use of org.jongo.FindOne in project profile by craftercms.
the class ProfileRepositoryImpl method findOneByQuery.
@Override
public Profile findOneByQuery(String query, String... attributesToReturn) throws MongoDataException {
try {
FindOne findOne = getCollection().findOne(query);
addProjection(findOne, attributesToReturn);
return findOne.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profile by query '" + query + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
use of org.jongo.FindOne 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.jongo.FindOne 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);
}
}
Aggregations