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.SearchAttribute;
40 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.SearchUpdatedAttribute;
41 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import org.apache.commons.lang3.tuple.Pair;
44
45 import java.sql.Timestamp;
46 import java.util.Date;
47 import java.util.List;
48 import java.util.Map;
49
50 /**
51 * IIdentityDAO Interface
52 */
53 public interface IIdentityDAO
54 {
55 String BEAN_NAME = "identitystore.identityDAO";
56
57 /**
58 * Insert a new record in the table.
59 *
60 * @param identity
61 * instance of the Identity object to insert
62 * @param plugin
63 * the Plugin
64 */
65 void insert( Identity identity, int dataRetentionPeriodInMonth, Plugin plugin );
66
67 /**
68 * Update the record in the table
69 *
70 * @param identity
71 * the reference of the Identity
72 * @param plugin
73 * the Plugin
74 */
75 void store( Identity identity, Plugin plugin );
76
77 /**
78 * Merge identity
79 *
80 * @param identity
81 * @param plugin
82 */
83 void merge( Identity identity, Plugin plugin );
84
85 /**
86 * Cancel identity merge
87 *
88 * @param identity
89 * @param plugin
90 */
91 void cancelMerge( Identity identity, Plugin plugin );
92
93 /**
94 * Delete a record from the table
95 *
96 * @param nKey
97 * The identifier of the Identity to delete
98 * @param plugin
99 * the Plugin
100 */
101 void hardDelete( int nKey, Plugin plugin );
102
103 /**
104 * Modify the columuns is_deleted and date_delete and connection_id to null
105 *
106 * @param strCuid
107 * The id of the Identity to delete
108 * @param plugin
109 * the Plugin
110 */
111 void softDelete( String strCuid, Plugin plugin );
112
113 // /////////////////////////////////////////////////////////////////////////
114 // Finders
115
116 /**
117 * Load the data from the table
118 *
119 * @param nKey
120 * The identifier of the identity
121 * @param plugin
122 * the Plugin
123 * @return The instance of the identity
124 */
125 Identity load( int nKey, Plugin plugin );
126
127 List<Identity> selectAll( Plugin plugin );
128
129 /**
130 * Find by connection ID
131 *
132 * @param strConnectionId
133 * The connection ID
134 * @param plugin
135 * The plugin
136 * @return The identity
137 */
138 Identity selectByConnectionId( String strConnectionId, Plugin plugin );
139
140 /**
141 * Find by customer ID
142 *
143 * @param strCustomerId
144 * The customerID
145 * @param plugin
146 * The plugin
147 * @return The identity
148 */
149 Identity selectByCustomerId( String strCustomerId, Plugin plugin );
150
151 Identity selectNotMergedByCustomerId( String strCustomerId, Plugin plugin );
152
153 Identity selectNotMergedByConnectionId( String strCustomerId, Plugin plugin );
154
155 /**
156 * Find an identity ID from the specified customer ID
157 *
158 * @param strCustomerId
159 * the customer ID
160 * @param plugin
161 * the plugin
162 * @return The identity ID
163 */
164 int selectIdByCustomerId( String strCustomerId, Plugin plugin );
165
166 /**
167 * 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
168 * of these attributes the exact value is in a list of expected values (no wildcards).
169 *
170 * @param searchAttributes
171 * The list of searched attributes selected with the list of values
172 * @param maxNbIdentityReturned
173 * The maximum number of Identity returned in the list
174 * @param plugin
175 * The plugin
176 * @return The identity
177 */
178 List<Identity> selectByAttributesValueForApiSearch(final List<SearchAttribute> searchAttributes, int maxNbIdentityReturned, Plugin plugin );
179
180 /**
181 * Find all identities that have all attributes specified in the list in parameters.<br/>
182 * Identities <b>MUST</b> have all those attributes in order to be returned.
183 *
184 * @param idAttributeList
185 * the attributes id
186 * @param notMerged
187 * if the returned identities have to be not merged
188 * @param notSuspicious
189 * if the returned identities have to not be suspicious
190 * @param rulePriority
191 * when suspicions are not filtered ( notSuspicious = false ), return only lower priority suspicions
192 * @param nbFilledAttributes
193 * minimum number of filled attributes over idAttributeList
194 * @param plugin
195 * the plugin
196 * @return A list of matching identities
197 */
198 List<String> selectByAttributeExisting( final List<Integer> idAttributeList, final int nbFilledAttributes, final boolean notMerged,
199 final boolean notSuspicious, final int rulePriority, final Plugin plugin );
200
201 /**
202 * log changes
203 *
204 * @param identityChange
205 * @param plugin
206 */
207 void addChangeHistory( IdentityChange identityChange, Plugin plugin ) throws IdentityStoreException;
208
209 void addOrUpdateChangeHistory( IdentityChange identityChange, Plugin plugin ) throws IdentityStoreException;
210
211 /**
212 * get identity history
213 *
214 * @param strCustomerId
215 * @param plugin
216 * @return the list of identity changes
217 */
218 List<IdentityChange> selectIdentityHistoryByCustomerId( String strCustomerId, Plugin plugin ) throws IdentityStoreException;
219
220 /**
221 * get identities that have been updated during the previous `days`.
222 *
223 * @param days
224 * max number of days since the last update
225 * @param identityChangeTypes
226 * filters on specific change types
227 * @param updatedAttributes
228 * filters on specific updated attributes
229 * @return the list of identities
230 */
231 List<UpdatedIdentityDto> selectUpdated( final Integer days, final List<IdentityChangeType> identityChangeTypes,
232 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max, final Plugin plugin );
233
234 /**
235 * get identity IDs that have been updated during the previous `days`.
236 *
237 * @param days
238 * max number of days since the last update
239 * @param identityChangeTypes
240 * filters on specific change types
241 * @param updatedAttributes
242 * filters on specific updated attributes
243 * @return the list of identities
244 */
245 List<Integer> selectUpdatedIds( final Integer days, final List<IdentityChangeType> identityChangeTypes,
246 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max, final Plugin plugin );
247
248 /**
249 * select updated identities from their IDs.
250 *
251 * @param identityIds
252 * list of desired identity IDs
253 * @param plugin
254 * the plugin
255 * @return the list of identities
256 */
257 List<UpdatedIdentityDto> selectUpdatedFromIds( final List<Integer> identityIds, final Plugin plugin );
258
259 /**
260 * Search for history entries that matches the following parameters
261 *
262 * @param strCustomerId
263 * customer id of the identity
264 * @param clientCode
265 * client code that modified the identity
266 * @param authorName
267 * name of the author that modified the identity
268 * @param changeType
269 * the type of identity change
270 * @param metadata
271 * metadata of the identity change
272 * @param nbDaysFrom
273 * number of day from the current date
274 * @param plugin
275 * @return
276 */
277 List<IdentityChange> selectIdentityHistoryBySearchParameters( String strCustomerId, String clientCode, String authorName, IdentityChangeType changeType,
278 String changeStatus, final String authorType, final Date modificationDate, Map<String, String> metadata, Integer nbDaysFrom, Pair<Date, Date> modificationDateInterval, Plugin plugin, int nMaxNbIdentityReturned )
279 throws IdentityStoreException;
280
281 /**
282 * Search for identities that are not connected, and have a past expirationDate.
283 *
284 * @param limit
285 * the max number of results
286 * @param plugin
287 * the plugin
288 * @return a list of {@link Identity}
289 */
290 List<Identity> selectExpiredNotMergedAndNotConnectedIdentities( int limit, Plugin plugin );
291
292 /**
293 * Search for identity customer IDs that are not connected, not merged, and have the specified attribute non-certified.
294 *
295 * @param attributeKey
296 * the attribute key to be present and non-certified
297 * @param limit
298 * the max number of returned identities
299 * @return a list of customer IDs
300 */
301 List<String> selectNotMergedNotConnectedWithNonCertifiedAttributeCustomerIds(String attributeKey, String certProcess, int limit, Plugin plugin);
302
303 /**
304 * Search for identities that are merged to the provided identity ID.
305 *
306 * @param identityId
307 * the 'master' identity ID
308 * @param plugin
309 * the plugin
310 * @return a list of {@link Identity}
311 */
312 List<Identity> selectMergedIdentities( int identityId, Plugin plugin );
313
314 /**
315 * Delete all attribute history of the identity's provided id.
316 *
317 * @param identityId
318 * the identity's id
319 * @param plugin
320 * the plugin
321 */
322 void deleteAttributeHistory( int identityId, Plugin plugin );
323
324 /**
325 * Get the identity last update date coresponding to the given customer ID
326 *
327 * @param customerId
328 * the customer ID
329 * @param plugin
330 * the plugin
331 * @return the last update date or null if the identity doesn't exist for the provided CUID
332 */
333 Timestamp getIdentityLastUpdateDate( final String customerId, final Plugin plugin );
334
335 /**
336 * Count All Identities.
337 */
338 Integer getCountIdentities( final Plugin plugin );
339
340 /**
341 * Count All identities that has been deleted or not.
342 *
343 * @param deleted
344 * define if the dao count deleted or not deleted identities
345 */
346 Integer getCountDeletedIdentities(final boolean deleted, final Plugin plugin );
347
348 /**
349 * Count All identities that has been merged or not.
350 *
351 * @param merged
352 * define if the dao count merged or not merged identities
353 */
354 Integer getCountMergedIdentities(final boolean merged, final Plugin plugin );
355
356 /**
357 * Count All identities that has been connected or not.
358 *
359 * @param monParisActive
360 * define if the dao count connected or not connected identities
361 */
362 Integer getCountActiveMonParisdentities(final boolean monParisActive, final Plugin plugin );
363
364 /**
365 * Count how many attributes each entity has.
366 */
367 Map<Integer, Integer> getCountAttributesByIdentities(final Plugin plugin );
368
369 /**
370 * Count how many attributes has no attribute and isn't merged.
371 */
372 Integer getCountUnmergedIdentitiesWithoutAttributes(final Plugin plugin );
373
374 Integer getCountIndexEligibleIdentities(final Plugin plugin);
375
376 Integer getCountIndexNotEligibleIdentities(final Plugin plugin);
377
378 /**
379 * Count how many actions and their type were done during an delimited time.
380 */
381 List<IndicatorsActionsType> getActionsTypesDuringInterval(int interval, final Plugin plugin );
382
383 List<String> getHistoryStatusList( final Plugin plugin );
384 }