1 /*
2 * Copyright (c) 2002-2024, City of Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.identitystore.business.identity;
35
36 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.UpdatedIdentityDto;
37 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.history.IdentityChange;
38 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.history.IdentityChangeType;
39 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.SearchUpdatedAttribute;
40 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import org.apache.commons.lang3.tuple.Pair;
43
44 import java.sql.Timestamp;
45 import java.util.Date;
46 import java.util.List;
47 import java.util.Map;
48
49 /**
50 * IIdentityDAO Interface
51 */
52 public interface IIdentityDAO
53 {
54 String BEAN_NAME = "identitystore.identityDAO";
55
56 /**
57 * Insert a new record in the table.
58 *
59 * @param identity
60 * instance of the Identity object to insert
61 * @param plugin
62 * the Plugin
63 */
64 void insert( Identity identity, int dataRetentionPeriodInMonth, Plugin plugin );
65
66 /**
67 * Update the record in the table
68 *
69 * @param identity
70 * the reference of the Identity
71 * @param plugin
72 * the Plugin
73 */
74 void store( Identity identity, Plugin plugin );
75
76 /**
77 * Merge identity
78 *
79 * @param identity
80 * @param plugin
81 */
82 void merge( Identity identity, Plugin plugin );
83
84 /**
85 * Cancel identity merge
86 *
87 * @param identity
88 * @param plugin
89 */
90 void cancelMerge( Identity identity, Plugin plugin );
91
92 /**
93 * Delete a record from the table
94 *
95 * @param nKey
96 * The identifier of the Identity to delete
97 * @param plugin
98 * the Plugin
99 */
100 void hardDelete( int nKey, Plugin plugin );
101
102 /**
103 * Modify the columuns is_deleted and date_delete and connection_id to null
104 *
105 * @param strCuid
106 * The id of the Identity to delete
107 * @param plugin
108 * the Plugin
109 */
110 void softDelete( String strCuid, Plugin plugin );
111
112 // /////////////////////////////////////////////////////////////////////////
113 // Finders
114
115 /**
116 * Load the data from the table
117 *
118 * @param nKey
119 * The identifier of the identity
120 * @param plugin
121 * the Plugin
122 * @return The instance of the identity
123 */
124 Identity load( int nKey, Plugin plugin );
125
126 List<Identity> selectAll( Plugin plugin );
127
128 /**
129 * Find by connection ID
130 *
131 * @param strConnectionId
132 * The connection ID
133 * @param plugin
134 * The plugin
135 * @return The identity
136 */
137 Identity selectByConnectionId( String strConnectionId, Plugin plugin );
138
139 /**
140 * Find by customer ID
141 *
142 * @param strCustomerId
143 * The customerID
144 * @param plugin
145 * The plugin
146 * @return The identity
147 */
148 Identity selectByCustomerId( String strCustomerId, Plugin plugin );
149
150 Identity selectNotMergedByCustomerId( String strCustomerId, Plugin plugin );
151
152 Identity selectNotMergedByConnectionId( String strCustomerId, Plugin plugin );
153
154 /**
155 * Find an identity ID from the specified customer ID
156 *
157 * @param strCustomerId
158 * the customer ID
159 * @param plugin
160 * the plugin
161 * @return The identity ID
162 */
163 int selectIdByCustomerId( String strCustomerId, Plugin plugin );
164
165 /**
166 * Find by a combination of Attribute values. Search for identities that match the conditions defined for each of the selected attributes, that is on each
167 * of these attributes the exact value is in a list of expected values (no wildcards).
168 *
169 * @param mapAttributes
170 * A map that associates the id of each attributes selected with the list of values
171 * @param maxNbIdentityReturned
172 * The maximum number of Identity returned in the list
173 * @param plugin
174 * The plugin
175 * @return The identity
176 */
177 List<Identity> selectByAttributesValueForApiSearch( Map<String, List<String>> mapAttributes, int maxNbIdentityReturned, Plugin plugin );
178
179 /**
180 * Find all identities that have all attributes specified in the list in parameters.<br/>
181 * Identities <b>MUST</b> have all those attributes in order to be returned.
182 *
183 * @param idAttributeList
184 * the attributes id
185 * @param notMerged
186 * if the returned identities have to be not merged
187 * @param notSuspicious
188 * if the returned identities have to not be suspicious
189 * @param rulePriority
190 * when suspicions are not filtered ( notSuspicious = false ), return only lower priority suspicions
191 * @param nbFilledAttributes
192 * minimum number of filled attributes over idAttributeList
193 * @param plugin
194 * the plugin
195 * @return A list of matching identities
196 */
197 List<String> selectByAttributeExisting( final List<Integer> idAttributeList, final int nbFilledAttributes, final boolean notMerged,
198 final boolean notSuspicious, final int rulePriority, final Plugin plugin );
199
200 /**
201 * log changes
202 *
203 * @param identityChange
204 * @param plugin
205 */
206 void addChangeHistory( IdentityChange identityChange, Plugin plugin ) throws IdentityStoreException;
207
208 void addOrUpdateChangeHistory( IdentityChange identityChange, Plugin plugin ) throws IdentityStoreException;
209
210 /**
211 * get identity history
212 *
213 * @param strCustomerId
214 * @param plugin
215 * @return the list of identity changes
216 */
217 List<IdentityChange> selectIdentityHistoryByCustomerId( String strCustomerId, Plugin plugin ) throws IdentityStoreException;
218
219 /**
220 * get identities that have been updated during the previous `days`.
221 *
222 * @param days
223 * max number of days since the last update
224 * @param identityChangeTypes
225 * filters on specific change types
226 * @param updatedAttributes
227 * filters on specific updated attributes
228 * @return the list of identities
229 */
230 List<UpdatedIdentityDto> selectUpdated( final Integer days, final List<IdentityChangeType> identityChangeTypes,
231 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max, final Plugin plugin );
232
233 /**
234 * get identity IDs that have been updated during the previous `days`.
235 *
236 * @param days
237 * max number of days since the last update
238 * @param identityChangeTypes
239 * filters on specific change types
240 * @param updatedAttributes
241 * filters on specific updated attributes
242 * @return the list of identities
243 */
244 List<Integer> selectUpdatedIds( final Integer days, final List<IdentityChangeType> identityChangeTypes,
245 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max, final Plugin plugin );
246
247 /**
248 * select updated identities from their IDs.
249 *
250 * @param identityIds
251 * list of desired identity IDs
252 * @param plugin
253 * the plugin
254 * @return the list of identities
255 */
256 List<UpdatedIdentityDto> selectUpdatedFromIds( final List<Integer> identityIds, final Plugin plugin );
257
258 /**
259 * Search for history entries that matches the following parameters
260 *
261 * @param strCustomerId
262 * customer id of the identity
263 * @param clientCode
264 * client code that modified the identity
265 * @param authorName
266 * name of the author that modified the identity
267 * @param changeType
268 * the type of identity change
269 * @param metadata
270 * metadata of the identity change
271 * @param nbDaysFrom
272 * number of day from the current date
273 * @param plugin
274 * @return
275 */
276 List<IdentityChange> selectIdentityHistoryBySearchParameters( String strCustomerId, String clientCode, String authorName, IdentityChangeType changeType,
277 String changeStatus, final String authorType, final Date modificationDate, Map<String, String> metadata, Integer nbDaysFrom, Pair<Date, Date> modificationDateInterval, Plugin plugin )
278 throws IdentityStoreException;
279
280 /**
281 * Search for identities that are not connected, and have a past expirationDate.
282 *
283 * @param limit
284 * the max number of results
285 * @param plugin
286 * the plugin
287 * @return a list of {@link Identity}
288 */
289 List<Identity> selectExpiredNotMergedAndNotConnectedIdentities( int limit, Plugin plugin );
290
291 /**
292 * Search for identities that are merged to the provided identity ID.
293 *
294 * @param identityId
295 * the 'master' identity ID
296 * @param plugin
297 * the plugin
298 * @return a list of {@link Identity}
299 */
300 List<Identity> selectMergedIdentities( int identityId, Plugin plugin );
301
302 /**
303 * Delete all attribute history of the identity's provided id.
304 *
305 * @param identityId
306 * the identity's id
307 * @param plugin
308 * the plugin
309 */
310 void deleteAttributeHistory( int identityId, Plugin plugin );
311
312 /**
313 * Get the identity last update date coresponding to the given customer ID
314 *
315 * @param customerId
316 * the customer ID
317 * @param plugin
318 * the plugin
319 * @return the last update date or null if the identity doesn't exist for the provided CUID
320 */
321 Timestamp getIdentityLastUpdateDate( final String customerId, final Plugin plugin );
322 }