IdentityStorage.java

  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. package org.exoplatform.social.core.storage.api;

  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.util.List;
  21. import java.util.Set;

  22. import org.exoplatform.social.core.identity.SpaceMemberFilterListAccess.Type;
  23. import org.exoplatform.social.core.identity.model.ActiveIdentityFilter;
  24. import org.exoplatform.social.core.identity.model.Identity;
  25. import org.exoplatform.social.core.identity.model.IdentityWithRelationship;
  26. import org.exoplatform.social.core.identity.model.Profile;
  27. import org.exoplatform.social.core.identity.model.Profile.AttachedActivityType;
  28. import org.exoplatform.social.core.profile.ProfileFilter;
  29. import org.exoplatform.social.core.space.model.Space;
  30. import org.exoplatform.social.core.storage.IdentityStorageException;

  31. /**
  32.  * @author <a href="mailto:alain.defrance@exoplatform.com">Alain Defrance</a>
  33.  * @version $Revision$
  34.  */
  35. public interface IdentityStorage {

  36.   /**
  37.    * Saves identity.
  38.    *
  39.    * @param identity the identity
  40.    * @throws IdentityStorageException
  41.    */
  42.   public void saveIdentity(final Identity identity) throws IdentityStorageException;

  43.   /**
  44.    * Updates existing identity's properties.
  45.    *
  46.    * @param identity the identity to be updated.
  47.    * @return the updated identity.
  48.    * @throws IdentityStorageException
  49.    * @since  1.2.0-GA
  50.    */
  51.   public Identity updateIdentity(final Identity identity) throws IdentityStorageException;
  52.  
  53.   /**
  54.    * Updates existing identity's membership in OrganizationService.
  55.    *
  56.    * @param remoteId the remoteId to be updated membership.
  57.    * @throws IdentityStorageException
  58.    * @since  4.0.0
  59.    */
  60.   public void updateIdentityMembership(final String remoteId) throws IdentityStorageException;

  61.   /**
  62.    * Gets the identity by his id.
  63.    *
  64.    * @param nodeId the id of identity
  65.    * @return the identity
  66.    * @throws IdentityStorageException
  67.    */
  68.   public Identity findIdentityById(final String nodeId) throws IdentityStorageException;

  69.   /**
  70.    * Deletes an identity
  71.    *
  72.    * @param identity
  73.    * @throws IdentityStorageException
  74.    */
  75.   public void deleteIdentity(final Identity identity) throws IdentityStorageException;

  76.   /**
  77.    * Hard delete an identity
  78.    *
  79.    * @param identity
  80.    * @throws IdentityStorageException
  81.    */
  82.   public void hardDeleteIdentity(final Identity identity) throws IdentityStorageException;

  83.   /**
  84.    * Load profile.
  85.    *
  86.    * @param profile the profile
  87.    * @throws IdentityStorageException
  88.    */
  89.   public Profile loadProfile(Profile profile) throws IdentityStorageException;

  90.   /**
  91.    * Gets the identity by remote id.
  92.    *
  93.    * @param providerId the identity provider
  94.    * @param remoteId   the id
  95.    * @return the identity by remote id
  96.    * @throws IdentityStorageException
  97.    */
  98.   public Identity findIdentity(final String providerId, final String remoteId) throws IdentityStorageException;

  99.   /**
  100.    * Saves profile.
  101.    *
  102.    * @param profile the profile
  103.    * @throws IdentityStorageException
  104.    */
  105.   public void saveProfile(final Profile profile) throws IdentityStorageException;

  106.   /**
  107.    * Updates profile.
  108.    *
  109.    * @param profile the profile
  110.    * @throws IdentityStorageException
  111.    * @since 1.2.0-GA
  112.    */
  113.   public void updateProfile(final Profile profile) throws IdentityStorageException;

  114.   /**
  115.    * Gets total number of identities in storage depend on providerId.
  116.    * @throws IdentityStorageException
  117.    */
  118.   public int getIdentitiesCount (final String providerId) throws IdentityStorageException;

  119.   /**
  120.    * Gets the identities by profile filter.
  121.    *
  122.    * @param providerId Id of provider.
  123.    * @param profileFilter    Information of profile that used in filtering.
  124.    * @param offset           Start index of list to be get.
  125.    * @param limit            End index of list to be get.
  126.    * @param forceLoadOrReloadProfile Load profile or not.
  127.    * @return the identities by profile filter.
  128.    * @throws IdentityStorageException
  129.    * @since 1.2.0-GA
  130.    */
  131.   public List<Identity> getIdentitiesByProfileFilter(
  132.       final String providerId, final ProfileFilter profileFilter, long offset, long limit,
  133.       boolean forceLoadOrReloadProfile)
  134.       throws IdentityStorageException;
  135.  
  136.   /**
  137.    * Gets the identities by profile filter.
  138.    *
  139.    * @param providerId Id of provider.
  140.    * @param profileFilter    Information of profile that used in filtering.
  141.    * @param offset           Start index of list to be get.
  142.    * @param limit            End index of list to be get.
  143.    * @param forceLoadOrReloadProfile Load profile or not.
  144.    * @return the identities by profile filter.
  145.    * @throws IdentityStorageException
  146.    * @since 4.0.0-Alpha1
  147.    */
  148.   public List<Identity> getIdentitiesForMentions(final String providerId,
  149.                                                  final ProfileFilter profileFilter,
  150.                                                  org.exoplatform.social.core.relationship.model.Relationship.Type type,
  151.                                                  long offset,
  152.                                                  long limit,
  153.                                                  boolean forceLoadOrReloadProfile) throws IdentityStorageException;
  154.  
  155.   /**
  156.    * Gets the count identities by profile filter.
  157.    *
  158.    * @param providerId Id of provider.
  159.    * @param profileFilter    Information of profile that used in filtering.
  160.    * @return the number of filtered identities
  161.    * @throws IdentityStorageException
  162.    * @since 4.4.0
  163.    */
  164.   public int getIdentitiesForMentionsCount(final String providerId,
  165.                                            final ProfileFilter profileFilter,
  166.                                            org.exoplatform.social.core.relationship.model.Relationship.Type type) throws IdentityStorageException;
  167.  
  168.   /**
  169.    * Gets the identities for Unified Search.
  170.    *
  171.    * @param providerId Id of provider.
  172.    * @param profileFilter    Information of profile that used in filtering.
  173.    * @param offset           Start index of list to be get.
  174.    * @param limit            End index of list to be get.
  175.    * @return the identities
  176.    * @throws IdentityStorageException
  177.    * @since 4.0.x
  178.    */
  179.   public List<Identity> getIdentitiesForUnifiedSearch(final String providerId,
  180.                                                       final ProfileFilter profileFilter,
  181.                                                       long offset, long limit) throws IdentityStorageException;

  182.   /**
  183.    * Counts the number of identity by profile filter.
  184.    *
  185.    * @param providerId Id of Provider.
  186.    * @param profileFilter Information of profile are used in filtering.
  187.    * @return Number of identities that are filtered by profile.
  188.    * @throws IdentityStorageException
  189.    * @since 1.2.0-GA
  190.    */
  191.   public int getIdentitiesByProfileFilterCount(final String providerId, final ProfileFilter profileFilter)
  192.       throws IdentityStorageException;

  193.   /**
  194.    * Counts the number of identities that match the first character of name.
  195.    *
  196.    * @param providerId
  197.    * @param profileFilter Profile filter object.
  198.    * @return Number of identities that start with the first character of name.
  199.    * @throws IdentityStorageException
  200.    * @since 1.2.0-GA
  201.    */
  202.   public int getIdentitiesByFirstCharacterOfNameCount(final String providerId, final ProfileFilter profileFilter)
  203.       throws IdentityStorageException;

  204.   /**
  205.    * Gets the identities that match the first character of name.
  206.    *
  207.    * @param providerId Id of provider.
  208.    * @param profileFilter Profile filter object.
  209.    * @param offset   Start index of list to be get.
  210.    * @param limit    End index of list to be get.
  211.    * @param forceLoadOrReloadProfile Load profile or not.
  212.    * @return Identities that have name start with the first character.
  213.    * @throws IdentityStorageException
  214.    * @deprecated use method getIdentities or getIdentitiesForUnifiedSearch instead
  215.    * @since 1.2.0-GA
  216.    */
  217.   @Deprecated
  218.   public List<Identity> getIdentitiesByFirstCharacterOfName(final String providerId, final ProfileFilter profileFilter,
  219.       long offset, long limit, boolean forceLoadOrReloadProfile) throws IdentityStorageException;

  220.   /**
  221.    * Gets the type.
  222.    *
  223.    * @param nodetype the nodetype
  224.    * @param property the property
  225.    * @return the type
  226.    * @throws IdentityStorageException
  227.    */
  228.   public String getType(final String nodetype, final String property);

  229.   /**
  230.    * Add or modify properties of profile and persist to JCR. Profile parameter is a lightweight that
  231.    * contains only the property that you want to add or modify. NOTE: The method will
  232.    * not delete the properties on old profile when the param profile have not those keys.
  233.    *
  234.    * @param profile
  235.    * @throws IdentityStorageException
  236.    */
  237.   public void addOrModifyProfileProperties(final Profile profile) throws IdentityStorageException;
  238.  
  239.   /**
  240.    * get Space's member Identity and filter it by Profile Filter
  241.    * @param space
  242.    * @param profileFilter
  243.    * @param offset
  244.    * @param limit
  245.    * @return
  246.    * @throws IdentityStorageException
  247.    */
  248.   public List<Identity> getSpaceMemberIdentitiesByProfileFilter(final Space space,
  249.                                                                 final ProfileFilter profileFilter,
  250.                                                                 Type type,
  251.                                                                 long offset, long limit)
  252.                                                                 throws IdentityStorageException;
  253.  
  254.   /**
  255.    * Updates profile activity id by type.
  256.    *
  257.    * @param identity
  258.    * @param activityId
  259.    * @param type Type of activity id to get.
  260.    * @since 4.0.0.Alpha1
  261.    */
  262.   public void updateProfileActivityId(Identity identity, String activityId, AttachedActivityType type);
  263.  
  264.   /**
  265.    * Gets profile activity id by type.
  266.    *
  267.    * @param profile
  268.    * @param type Type of activity id to get.
  269.    * @return Profile activity id.
  270.    * @since 4.0.0.Alpha1
  271.    */
  272.   public String getProfileActivityId(Profile profile, AttachedActivityType type);
  273.  
  274.   /**
  275.    * Gets the active user list base on the given ActiveIdentityFilter.
  276.    * 1. N days who last login less than N days.
  277.    * 2. UserGroup who belongs to this group.
  278.    *
  279.    * @param filter
  280.    * @return
  281.    * @since 4.1.0
  282.    */
  283.   public Set<String> getActiveUsers(ActiveIdentityFilter filter);
  284.  
  285.   /**
  286.    * Process enable/disable Identity
  287.    *
  288.    * @param identity The Identity enable
  289.    * @param isEnable true if the user is enable, false if not
  290.    * @since 4.2.x
  291.    */
  292.   public void processEnabledIdentity(Identity identity, boolean isEnable);

  293.   /**
  294.    * Gets all identities from the store with the relationship that they have with current user identity.
  295.    *
  296.    * @param identityId user viewer identity id.
  297.    * @param offset   Start index of list to be get.
  298.    * @param limit    End index of list to be get.
  299.    * @return Identities that have name start with the first character.
  300.    * @since 4.4.0
  301.    */
  302.   List<IdentityWithRelationship> getIdentitiesWithRelationships(String identityId, int offset, int limit);

  303.   /**
  304.    * Gets all identities from the store with the relationship that they have with current user identity.
  305.    * The firstChar parameter will be used to filter on identities full names first character.
  306.    *
  307.    * @param identityId
  308.    * @param firstChar
  309.    * @param offset
  310.    * @param limit
  311.    * @return
  312.    */
  313.   default List<IdentityWithRelationship> getIdentitiesWithRelationships(String identityId, char firstChar, int offset, int limit) {
  314.     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
  315.   }

  316.   /**
  317.    * Counts the number of identities
  318.    *
  319.    * @param identityId Id of Identity.
  320.    * @return Number of identities.
  321.    * @throws Exception
  322.    * @since 4.4.0
  323.    */
  324.   int countIdentitiesWithRelationships(String identityId) throws Exception;
  325.  
  326.   /**
  327.    *  Gets a the avatar stream for a given identity
  328.    *
  329.    * @param identity
  330.    * @return
  331.    */
  332.   InputStream getAvatarInputStreamById(Identity identity) throws IOException;

  333.   /**
  334.    *  Gets a the avatar stream for a given identity
  335.    *
  336.    * @param identity
  337.    * @return
  338.    */
  339.   InputStream getBannerInputStreamById(Identity identity) throws IOException;

  340.   /**
  341.    * count Space's members by status and filter it by Profile Filter
  342.    *
  343.    * @param space
  344.    * @param profileFilter
  345.    * @param type
  346.    * @return
  347.    */
  348.   public int countSpaceMemberIdentitiesByProfileFilter(Space space, ProfileFilter profileFilter, Type type);

  349.   /**
  350.    * Get list of identities by providerId
  351.    *
  352.    * @param providerId
  353.    * @param offset
  354.    * @param limit
  355.    * @return
  356.    */
  357.   default public List<Identity> getIdentities(String providerId, long offset, long limit) {
  358.     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
  359.   }

  360.   /**
  361.    * Get list of identities by providerId
  362.    * The firstChar parameter will be used to filter on identities full names first character.
  363.    *
  364.    * @param providerId
  365.    * @param firstCharacterOfName
  366.    * @param offset
  367.    * @param limit
  368.    * @return
  369.    */
  370.   default public List<Identity> getIdentities(String providerId, char firstCharacterOfName, long offset, long limit) {
  371.     throw new UnsupportedOperationException("This operation is not supported using current implementation of service IdentityStorage");
  372.   }

  373.   /**
  374.    * Sorts a list of user identities using a field
  375.    *
  376.    * @param identityRemoteIds
  377.    * @param sortField
  378.    * @return
  379.    */
  380.   public List<String> sortIdentities(List<String> identityRemoteIds, String sortField);

  381. }