use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findByTenantAndExistingAttribute.
@Override
public Iterable<Profile> findByTenantAndExistingAttribute(String tenantName, String attributeName, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY);
Find find = getCollection().find(query, tenantName, attributeName);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles with attribute " + attributeName + " and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findById.
@Override
public Profile findById(String id, String... attributesToReturn) throws MongoDataException {
try {
FindOne findOne = getCollection().findOne(new ObjectId(id));
addProjection(findOne, attributesToReturn);
return findOne.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profile by id '" + id + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
} catch (IllegalArgumentException ex) {
String msg = "Given id '" + id + "' can't be converted to an ObjectId";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findByTenantAndUsername.
@Override
public Profile findByTenantAndUsername(String tenantName, String username, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_USERNAME_QUERY);
FindOne findOne = getCollection().findOne(query, tenantName, username);
if (ArrayUtils.isNotEmpty(attributesToReturn)) {
findOne = findOne.projection(buildProjectionWithAttributes(attributesToReturn));
}
return findOne.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profile by tenant name '" + tenantName + "' and username '" + username + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findByTenantAndRole.
@Override
public Iterable<Profile> findByTenantAndRole(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ROLE_QUERY);
Find find = getCollection().find(query, tenantName, role);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles for role '" + role + " and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.
the class ProfileRepositoryImpl method findByTenantAndAttributeValue.
@Override
public Iterable<Profile> findByTenantAndAttributeValue(String tenantName, String attributeName, String attributeValue, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY);
Find find = getCollection().find(query, tenantName, attributeName, attributeValue);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles for attribute " + attributeName + " = " + attributeValue + " and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
Aggregations