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 Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.craftercms.commons.mongo.AbstractJongoRepository
clazz, collectionName, gridfs, jongo, queries
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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
protected org.jongo.Find
protected String
buildProjectionWithAttributes
(String... attributeNames) long
countByTenant
(String tenantName) Returns the count of profiles for the given tenant.Returns the profile with the given ID.Returns the profiles with the given IDs.findByQuery
(String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) Returns the profiles that match the specified query.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.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.findByTenantAndRole
(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn) Returns the profiles with the given roles for the given tenant.findByTenantAndUsername
(String tenantName, String username, String... attributesToReturn) Returns the profile for the given tenant name and username.findOneByQuery
(String query, String... attributesToReturn) Returns the single profile that matches the specified queryfindRange
(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) Returns a range of profiles for the given tenant.void
init()
void
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 Details
-
KEY_INDEX_KEYS
- See Also:
-
KEY_INDEX_OPTIONS
- See Also:
-
KEY_DEFAULT_FIELDS
- See Also:
-
KEY_FIND_BY_TENANT_AND_USERNAME_QUERY
- See Also:
-
KEY_COUNT_BY_TENANT_QUERY
- See Also:
-
KEY_REMOVE_BY_TENANT_QUERY
- See Also:
-
KEY_FIND_BY_IDS_QUERY
- See Also:
-
KEY_FIND_BY_TENANT_QUERY
- See Also:
-
KEY_FIND_BY_TENANT_AND_ROLE_QUERY
- See Also:
-
KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY
- See Also:
-
KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY
- See Also:
-
KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY
- See Also:
-
ATTRIBUTE_FIELD_PREFIX
- See Also:
-
MODIFIER_REMOVE_ROLE
- See Also:
-
MODIFIER_REMOVE_ATTRIBUTE
- See Also:
-
MODIFIER_UPDATE_ATTRIBUTE
- See Also:
-
-
Constructor Details
-
ProfileRepositoryImpl
public ProfileRepositoryImpl()
-
-
Method Details
-
init
-
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
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
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
-
addSort
-
addRange
-
addProjection
-
addProjection
-
buildProjectionWithAttributes
-