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 ofProfileRepository
.- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description static String
ATTRIBUTE_FIELD_PREFIX
static String
KEY_COUNT_BY_TENANT_QUERY
static String
KEY_DEFAULT_FIELDS
static String
KEY_FIND_BY_IDS_QUERY
static String
KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY
static String
KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY
static String
KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY
static String
KEY_FIND_BY_TENANT_AND_ROLE_QUERY
static String
KEY_FIND_BY_TENANT_AND_USERNAME_QUERY
static String
KEY_FIND_BY_TENANT_QUERY
static String
KEY_INDEX_KEYS
static String
KEY_INDEX_OPTIONS
static String
KEY_REMOVE_BY_TENANT_QUERY
static String
MODIFIER_REMOVE_ATTRIBUTE
static String
MODIFIER_REMOVE_ROLE
static String
MODIFIER_UPDATE_ATTRIBUTE
-
Constructor Summary
Constructors Constructor Description ProfileRepositoryImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.jongo.FindOne
addProjection(org.jongo.FindOne findOne, String... attributesToReturn)
protected org.jongo.Find
addProjection(org.jongo.Find find, String... attributesToReturn)
protected org.jongo.Find
addRange(org.jongo.Find find, Integer start, Integer count)
protected org.jongo.Find
addSort(org.jongo.Find find, String sortBy, SortOrder sortOrder)
protected String
buildProjectionWithAttributes(String... attributeNames)
long
countByTenant(String tenantName)
Returns the count of profiles for the given tenant.Profile
findById(String id, String... attributesToReturn)
Returns the profile with the given ID.Iterable<Profile>
findByIds(List<String> ids, String sortBy, SortOrder sortOrder, String... attributesToReturn)
Returns the profiles with the given IDs.Iterable<Profile>
findByQuery(String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn)
Returns the profiles that match the specified query.Iterable<Profile>
findByTenantAndAttributeValue(String tenantName, String attributeName, String attributeValue, String sortBy, SortOrder sortOrder, String... attributesToReturn)
Returns the profiles that have the given attribute with the given value for the given tenant.Iterable<Profile>
findByTenantAndExistingAttribute(String tenantName, String attributeName, String sortBy, SortOrder sortOrder, String... attributesToReturn)
Returns the profiles that have the given attribute, with any value, for the given tenant.Iterable<Profile>
findByTenantAndRole(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn)
Returns the profiles with the given roles for the given tenant.Profile
findByTenantAndUsername(String tenantName, String username, String... attributesToReturn)
Returns the profile for the given tenant name and username.Profile
findOneByQuery(String query, String... attributesToReturn)
Returns the single profile that matches the specified queryIterable<Profile>
findRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn)
Returns a range of profiles for the given tenant.void
init()
void
removeAll(String tenantName)
Removes all the profiles associated to the given tenant.void
removeAttributeFromAll(String tenantName, String attributeName)
Removes the attribute of all profiles of to the given tenant.void
removeRoleFromAll(String tenantName, String role)
Removes the role of all profiles of to the given tenant.void
updateAllWithDefaultValue(String tenantName, String attributeName, Object defaultValue)
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.-
Methods inherited from class org.craftercms.commons.mongo.AbstractJongoRepository
count, count, count, createSortQuery, deleteFile, deleteFile, find, find, findAll, findById, findByStringId, findOne, findOne, getCollection, getFileInfo, getFileInfo, getQueryFor, insert, insert, listFilesByName, readFile, readFile, remove, remove, removeById, removeByStringId, returnList, returnSimple, save, save, saveFile, saveFile, setJongo, setQueries, update, update, update, update, updateFile, updateFile, updateFile, validateObject, validateObject
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.craftercms.commons.mongo.CrudRepository
count, count, count, deleteFile, deleteFile, find, find, findAll, findById, findByStringId, findOne, findOne, getFileInfo, getFileInfo, insert, insert, listFilesByName, readFile, readFile, remove, remove, removeById, removeByStringId, save, save, saveFile, saveFile, update, update, update, update, updateFile, updateFile, updateFile
-
-
-
-
Field Detail
-
KEY_INDEX_KEYS
public static final String KEY_INDEX_KEYS
- See Also:
- Constant Field Values
-
KEY_INDEX_OPTIONS
public static final String KEY_INDEX_OPTIONS
- See Also:
- Constant Field Values
-
KEY_DEFAULT_FIELDS
public static final String KEY_DEFAULT_FIELDS
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_AND_USERNAME_QUERY
public static final String KEY_FIND_BY_TENANT_AND_USERNAME_QUERY
- See Also:
- Constant Field Values
-
KEY_COUNT_BY_TENANT_QUERY
public static final String KEY_COUNT_BY_TENANT_QUERY
- See Also:
- Constant Field Values
-
KEY_REMOVE_BY_TENANT_QUERY
public static final String KEY_REMOVE_BY_TENANT_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_IDS_QUERY
public static final String KEY_FIND_BY_IDS_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_QUERY
public static final String KEY_FIND_BY_TENANT_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_AND_ROLE_QUERY
public static final String KEY_FIND_BY_TENANT_AND_ROLE_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY
public static final String KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY
public static final String KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY
- See Also:
- Constant Field Values
-
KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY
public static final String KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY
- See Also:
- Constant Field Values
-
ATTRIBUTE_FIELD_PREFIX
public static final String ATTRIBUTE_FIELD_PREFIX
- See Also:
- Constant Field Values
-
MODIFIER_REMOVE_ROLE
public static final String MODIFIER_REMOVE_ROLE
- See Also:
- Constant Field Values
-
MODIFIER_REMOVE_ATTRIBUTE
public static final String MODIFIER_REMOVE_ATTRIBUTE
- See Also:
- Constant Field Values
-
MODIFIER_UPDATE_ATTRIBUTE
public static final String MODIFIER_UPDATE_ATTRIBUTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init() 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 interfaceProfileRepository
- Parameters:
query
- the Mongo query used to search for the profilesattributesToReturn
- 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 interfaceProfileRepository
- Parameters:
id
- the profile's IDattributesToReturn
- 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 interfaceProfileRepository
- 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 applicationattributesToReturn
- 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 interfaceProfileRepository
- Parameters:
ids
- the IDs of the profiles to returnsortBy
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's namesortBy
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's namerole
- the role the profile's must havesortBy
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's nameattributeName
- the name of the attribute profiles must havesortBy
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's nameattributeName
- the name of the attribute profiles must haveattributeValue
- the value of the attribute profiles must havesortBy
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's nameusername
- the profile's usernameattributesToReturn
- 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 interfaceProfileRepository
- 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 interfaceProfileRepository
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's namerole
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's nameattributeName
- 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 interfaceProfileRepository
- Parameters:
tenantName
- the tenant's nameattributeName
- the attribute's namedefaultValue
- the default attribute value- Throws:
org.craftercms.commons.mongo.MongoDataException
-
addProjection
protected org.jongo.FindOne addProjection(org.jongo.FindOne findOne, String... attributesToReturn)
-
addProjection
protected org.jongo.Find addProjection(org.jongo.Find find, String... attributesToReturn)
-
-