View Javadoc
1   /*
2    * Copyright (C) 2003-2011 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  
18  package org.exoplatform.social.core.storage.api;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.util.List;
23  import java.util.Set;
24  
25  import org.exoplatform.social.core.identity.SpaceMemberFilterListAccess.Type;
26  import org.exoplatform.social.core.identity.model.ActiveIdentityFilter;
27  import org.exoplatform.social.core.identity.model.Identity;
28  import org.exoplatform.social.core.identity.model.IdentityWithRelationship;
29  import org.exoplatform.social.core.identity.model.Profile;
30  import org.exoplatform.social.core.identity.model.Profile.AttachedActivityType;
31  import org.exoplatform.social.core.profile.ProfileFilter;
32  import org.exoplatform.social.core.space.model.Space;
33  import org.exoplatform.social.core.storage.IdentityStorageException;
34  
35  /**
36   * @author <a href="mailto:alain.defrance@exoplatform.com">Alain Defrance</a>
37   * @version $Revision$
38   */
39  public interface IdentityStorage {
40  
41    /**
42     * Saves identity.
43     *
44     * @param identity the identity
45     * @throws IdentityStorageException
46     */
47    public void saveIdentity(final Identity identity) throws IdentityStorageException;
48  
49    /**
50     * Updates existing identity's properties.
51     *
52     * @param identity the identity to be updated.
53     * @return the updated identity.
54     * @throws IdentityStorageException
55     * @since  1.2.0-GA
56     */
57    public Identity updateIdentity(final Identity identity) throws IdentityStorageException;
58    
59    /**
60     * Updates existing identity's membership in OrganizationService.
61     *
62     * @param remoteId the remoteId to be updated membership.
63     * @throws IdentityStorageException
64     * @since  4.0.0
65     */
66    public void updateIdentityMembership(final String remoteId) throws IdentityStorageException;
67  
68    /**
69     * Gets the identity by his id.
70     *
71     * @param nodeId the id of identity
72     * @return the identity
73     * @throws IdentityStorageException
74     */
75    public Identity findIdentityById(final String nodeId) throws IdentityStorageException;
76  
77    /**
78     * Deletes an identity
79     *
80     * @param identity
81     * @throws IdentityStorageException
82     */
83    public void deleteIdentity(final Identity identity) throws IdentityStorageException;
84  
85    /**
86     * Hard delete an identity
87     *
88     * @param identity
89     * @throws IdentityStorageException
90     */
91    public void hardDeleteIdentity(final Identity identity) throws IdentityStorageException;
92  
93    /**
94     * Load profile.
95     *
96     * @param profile the profile
97     * @throws IdentityStorageException
98     */
99    public Profile loadProfile(Profile profile) throws IdentityStorageException;
100 
101   /**
102    * Gets the identity by remote id.
103    *
104    * @param providerId the identity provider
105    * @param remoteId   the id
106    * @return the identity by remote id
107    * @throws IdentityStorageException
108    */
109   public Identity findIdentity(final String providerId, final String remoteId) throws IdentityStorageException;
110 
111   /**
112    * Saves profile.
113    *
114    * @param profile the profile
115    * @throws IdentityStorageException
116    */
117   public void saveProfile(final Profile profile) throws IdentityStorageException;
118 
119   /**
120    * Updates profile.
121    *
122    * @param profile the profile
123    * @throws IdentityStorageException
124    * @since 1.2.0-GA
125    */
126   public void updateProfile(final Profile profile) throws IdentityStorageException;
127 
128   /**
129    * Gets total number of identities in storage depend on providerId.
130    * @throws IdentityStorageException
131    */
132   public int getIdentitiesCount (final String providerId) throws IdentityStorageException;
133 
134   /**
135    * Gets the identities by profile filter.
136    *
137    * @param providerId Id of provider.
138    * @param profileFilter    Information of profile that used in filtering.
139    * @param offset           Start index of list to be get.
140    * @param limit            End index of list to be get.
141    * @param forceLoadOrReloadProfile Load profile or not.
142    * @return the identities by profile filter.
143    * @throws IdentityStorageException
144    * @since 1.2.0-GA
145    */
146   public List<Identity> getIdentitiesByProfileFilter(
147       final String providerId, final ProfileFilter profileFilter, long offset, long limit,
148       boolean forceLoadOrReloadProfile)
149       throws IdentityStorageException;
150   
151   /**
152    * Gets the identities by profile filter.
153    *
154    * @param providerId Id of provider.
155    * @param profileFilter    Information of profile that used in filtering.
156    * @param offset           Start index of list to be get.
157    * @param limit            End index of list to be get.
158    * @param forceLoadOrReloadProfile Load profile or not.
159    * @return the identities by profile filter.
160    * @throws IdentityStorageException
161    * @since 4.0.0-Alpha1
162    */
163   public List<Identity> getIdentitiesForMentions(final String providerId,
164                                                  final ProfileFilter profileFilter,
165                                                  org.exoplatform.social.core.relationship.model.Relationship.Type type,
166                                                  long offset,
167                                                  long limit,
168                                                  boolean forceLoadOrReloadProfile) throws IdentityStorageException;
169   
170   /**
171    * Gets the count identities by profile filter.
172    *
173    * @param providerId Id of provider.
174    * @param profileFilter    Information of profile that used in filtering.
175    * @return the number of filtered identities
176    * @throws IdentityStorageException
177    * @since 4.4.0
178    */
179   public int getIdentitiesForMentionsCount(final String providerId,
180                                            final ProfileFilter profileFilter,
181                                            org.exoplatform.social.core.relationship.model.Relationship.Type type) throws IdentityStorageException;
182   
183   /**
184    * Gets the identities for Unified Search.
185    *
186    * @param providerId Id of provider.
187    * @param profileFilter    Information of profile that used in filtering.
188    * @param offset           Start index of list to be get.
189    * @param limit            End index of list to be get.
190    * @return the identities
191    * @throws IdentityStorageException
192    * @since 4.0.x
193    */
194   public List<Identity> getIdentitiesForUnifiedSearch(final String providerId,
195                                                       final ProfileFilter profileFilter,
196                                                       long offset, long limit) throws IdentityStorageException;
197 
198   /**
199    * Counts the number of identity by profile filter.
200    *
201    * @param providerId Id of Provider.
202    * @param profileFilter Information of profile are used in filtering.
203    * @return Number of identities that are filtered by profile.
204    * @throws IdentityStorageException
205    * @since 1.2.0-GA
206    */
207   public int getIdentitiesByProfileFilterCount(final String providerId, final ProfileFilter profileFilter)
208       throws IdentityStorageException;
209 
210   /**
211    * Counts the number of identities that match the first character of name.
212    *
213    * @param providerId
214    * @param profileFilter Profile filter object.
215    * @return Number of identities that start with the first character of name.
216    * @throws IdentityStorageException
217    * @since 1.2.0-GA
218    */
219   public int getIdentitiesByFirstCharacterOfNameCount(final String providerId, final ProfileFilter profileFilter)
220       throws IdentityStorageException;
221 
222   /**
223    * Gets the identities that match the first character of name.
224    *
225    * @param providerId Id of provider.
226    * @param profileFilter Profile filter object.
227    * @param offset   Start index of list to be get.
228    * @param limit    End index of list to be get.
229    * @param forceLoadOrReloadProfile Load profile or not.
230    * @return Identities that have name start with the first character.
231    * @throws IdentityStorageException
232    * @deprecated use method getIdentities or getIdentitiesForUnifiedSearch instead
233    * @since 1.2.0-GA
234    */
235   @Deprecated
236   public List<Identity> getIdentitiesByFirstCharacterOfName(final String providerId, final ProfileFilter profileFilter,
237       long offset, long limit, boolean forceLoadOrReloadProfile) throws IdentityStorageException;
238 
239   /**
240    * Gets the type.
241    *
242    * @param nodetype the nodetype
243    * @param property the property
244    * @return the type
245    * @throws IdentityStorageException
246    */
247   public String getType(final String nodetype, final String property);
248 
249   /**
250    * Add or modify properties of profile and persist to JCR. Profile parameter is a lightweight that
251    * contains only the property that you want to add or modify. NOTE: The method will
252    * not delete the properties on old profile when the param profile have not those keys.
253    *
254    * @param profile
255    * @throws IdentityStorageException
256    */
257   public void addOrModifyProfileProperties(final Profile profile) throws IdentityStorageException;
258   
259   /**
260    * get Space's member Identity and filter it by Profile Filter
261    * @param space
262    * @param profileFilter
263    * @param offset
264    * @param limit
265    * @return
266    * @throws IdentityStorageException
267    */
268   public List<Identity> getSpaceMemberIdentitiesByProfileFilter(final Space space, 
269                                                                 final ProfileFilter profileFilter,
270                                                                 Type type,
271                                                                 long offset, long limit)
272                                                                 throws IdentityStorageException;
273   
274   /**
275    * Updates profile activity id by type.
276    * 
277    * @param identity
278    * @param activityId
279    * @param type Type of activity id to get.
280    * @since 4.0.0.Alpha1
281    */
282   public void updateProfileActivityId(Identity identity, String activityId, AttachedActivityType type);
283   
284   /**
285    * Gets profile activity id by type.
286    * 
287    * @param profile
288    * @param type Type of activity id to get.
289    * @return Profile activity id.
290    * @since 4.0.0.Alpha1
291    */
292   public String getProfileActivityId(Profile profile, AttachedActivityType type);
293   
294   /**
295    * Gets the active user list base on the given ActiveIdentityFilter.
296    * 1. N days who last login less than N days.
297    * 2. UserGroup who belongs to this group.
298    * 
299    * @param filter
300    * @return 
301    * @since 4.1.0
302    */
303   public Set<String> getActiveUsers(ActiveIdentityFilter filter);
304   
305   /**
306    * Process enable/disable Identity
307    * 
308    * @param identity The Identity enable
309    * @param isEnable true if the user is enable, false if not
310    * @since 4.2.x
311    */
312   public void processEnabledIdentity(Identity identity, boolean isEnable);
313 
314   /**
315    * Gets all identities from the store with the relationship that they have with current user identity.
316    *
317    * @param identityId user viewer identity id.
318    * @param offset   Start index of list to be get.
319    * @param limit    End index of list to be get.
320    * @return Identities that have name start with the first character.
321    * @since 4.4.0
322    */
323   List<IdentityWithRelationship> getIdentitiesWithRelationships(String identityId, int offset, int limit);
324 
325   /**
326    * Gets all identities from the store with the relationship that they have with current user identity.
327    * The firstChar parameter will be used to filter on identities full names first character.
328    * 
329    * @param identityId
330    * @param firstChar
331    * @param offset
332    * @param limit
333    * @return
334    */
335   default List<IdentityWithRelationship> getIdentitiesWithRelationships(String identityId, char firstChar, int offset, int limit) {
336     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
337   }
338 
339   /**
340    * Counts the number of identities
341    *
342    * @param identityId Id of Identity.
343    * @return Number of identities.
344    * @throws Exception
345    * @since 4.4.0
346    */
347   int countIdentitiesWithRelationships(String identityId) throws Exception;
348   
349   /**
350    *  Gets a the avatar stream for a given identity
351    *
352    * @param identity
353    * @return
354    */
355   InputStream getAvatarInputStreamById(Identity identity) throws IOException;
356 
357   /**
358    *  Gets a the avatar stream for a given identity
359    *
360    * @param identity
361    * @return
362    */
363   InputStream getBannerInputStreamById(Identity identity) throws IOException;
364 
365   /**
366    * count Space's members by status and filter it by Profile Filter
367    * 
368    * @param space
369    * @param profileFilter
370    * @param type
371    * @return
372    */
373   public int countSpaceMemberIdentitiesByProfileFilter(Space space, ProfileFilter profileFilter, Type type);
374 
375   /**
376    * Get list of identities by providerId
377    * 
378    * @param providerId
379    * @param offset
380    * @param limit
381    * @return
382    */
383   default public List<Identity> getIdentities(String providerId, long offset, long limit) {
384     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
385   }
386 
387   /**
388    * Get list of identities by providerId
389    * The firstChar parameter will be used to filter on identities full names first character.
390    * 
391    * @param providerId
392    * @param firstCharacterOfName
393    * @param offset
394    * @param limit
395    * @return
396    */
397   default public List<Identity> getIdentities(String providerId, char firstCharacterOfName, long offset, long limit) {
398     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
399   }
400 
401   /**
402    * Sorts a list of user identities using a field
403    * 
404    * @param identityRemoteIds
405    * @param sortField
406    * @return
407    */
408   public List<String> sortIdentities(List<String> identityRemoteIds, String sortField);
409 
410 }