Class ProfileRepositoryImpl

java.lang.Object
org.craftercms.commons.mongo.AbstractJongoRepository<Profile>
org.craftercms.profile.repositories.impl.ProfileRepositoryImpl
All Implemented Interfaces:
org.craftercms.commons.mongo.CrudRepository<Profile>, ProfileRepository

public class ProfileRepositoryImpl extends org.craftercms.commons.mongo.AbstractJongoRepository<Profile> implements ProfileRepository
Default implementation of ProfileRepository.
Author:
avasquez
  • Field Details

  • Constructor Details

    • ProfileRepositoryImpl

      public ProfileRepositoryImpl()
  • Method Details

    • init

      public void init() throws Exception
      Overrides:
      init in class org.craftercms.commons.mongo.AbstractJongoRepository<Profile>
      Throws:
      Exception
    • findOneByQuery

      public Profile findOneByQuery(String query, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the single profile that matches the specified query
      Specified by:
      findOneByQuery in interface ProfileRepository
      Parameters:
      query - the Mongo query used to search for the profiles
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the profile, or null if not found
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findById

      public Profile findById(String id, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profile with the given ID.
      Specified by:
      findById in interface ProfileRepository
      Parameters:
      id - the profile's ID
      attributesToReturn - the name of the attributes to return (null to return all)
      Returns:
      the profile found, or null if not found
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByQuery

      public Iterable<Profile> findByQuery(String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profiles that match the specified query.
      Specified by:
      findByQuery in interface ProfileRepository
      Parameters:
      query - the Mongo query used to search for the profiles. Must not contain the $where operator, the tenant's name (already specified) or any non-readable attribute by the application
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the list of profiles found, or null if none match the query
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByIds

      public Iterable<Profile> findByIds(List<String> ids, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profiles with the given IDs.
      Specified by:
      findByIds in interface ProfileRepository
      Parameters:
      ids - the IDs of the profiles to return
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the name of the attributes to return (null to return all)
      Returns:
      the profiles for the given IDs
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findRange

      public Iterable<Profile> findRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns a range of profiles for the given tenant.
      Specified by:
      findRange in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      start - from the entire list of results, the position where the actual results should start (useful for pagination) (optional)
      count - the number of profiles to return (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all)
      Returns:
      the range of profiles
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByTenantAndRole

      public Iterable<Profile> findByTenantAndRole(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profiles with the given roles for the given tenant.
      Specified by:
      findByTenantAndRole in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      role - the role the profile's must have
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all)
      Returns:
      the matching profiles
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByTenantAndExistingAttribute

      public Iterable<Profile> findByTenantAndExistingAttribute(String tenantName, String attributeName, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profiles that have the given attribute, with any value, for the given tenant.
      Specified by:
      findByTenantAndExistingAttribute in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      attributeName - the name of the attribute profiles must have
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all)
      Returns:
      the matching profiles
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByTenantAndAttributeValue

      public Iterable<Profile> findByTenantAndAttributeValue(String tenantName, String attributeName, String attributeValue, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profiles that have the given attribute with the given value for the given tenant.
      Specified by:
      findByTenantAndAttributeValue in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      attributeName - the name of the attribute profiles must have
      attributeValue - the value of the attribute profiles must have
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all)
      Returns:
      the matching profiles
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • findByTenantAndUsername

      public Profile findByTenantAndUsername(String tenantName, String username, String... attributesToReturn) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the profile for the given tenant name and username.
      Specified by:
      findByTenantAndUsername in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      username - the profile's username
      attributesToReturn - the name of the attributes to return (null to return all)
      Returns:
      the profile found, or null if not found
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • countByTenant

      public long countByTenant(String tenantName) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Returns the count of profiles for the given tenant.
      Specified by:
      countByTenant in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      Returns:
      the count of profiles for the tenant
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • removeAll

      public void removeAll(String tenantName) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Removes all the profiles associated to the given tenant.
      Specified by:
      removeAll in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • removeRoleFromAll

      public void removeRoleFromAll(String tenantName, String role) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Removes the role of all profiles of to the given tenant.
      Specified by:
      removeRoleFromAll in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      role - the name of the role to remove
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • removeAttributeFromAll

      public void removeAttributeFromAll(String tenantName, String attributeName) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Removes the attribute of all profiles of to the given tenant.
      Specified by:
      removeAttributeFromAll in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      attributeName - the name of the attribute to remove
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • updateAllWithDefaultValue

      public void updateAllWithDefaultValue(String tenantName, String attributeName, Object defaultValue) throws org.craftercms.commons.mongo.MongoDataException
      Description copied from interface: ProfileRepository
      Updates all the profiles of a given tenant with the default value of an attribute, only if they don't have the attribute value set yet.
      Specified by:
      updateAllWithDefaultValue in interface ProfileRepository
      Parameters:
      tenantName - the tenant's name
      attributeName - the attribute's name
      defaultValue - the default attribute value
      Throws:
      org.craftercms.commons.mongo.MongoDataException
    • addSort

      protected org.jongo.Find addSort(org.jongo.Find find, String sortBy, SortOrder sortOrder)
    • addRange

      protected org.jongo.Find addRange(org.jongo.Find find, Integer start, Integer count)
    • addProjection

      protected org.jongo.FindOne addProjection(org.jongo.FindOne findOne, String... attributesToReturn)
    • addProjection

      protected org.jongo.Find addProjection(org.jongo.Find find, String... attributesToReturn)
    • buildProjectionWithAttributes

      protected String buildProjectionWithAttributes(String... attributeNames)