Search in sources :

Example 1 with Find

use of org.jongo.Find in project profile by craftercms.

the class ProfileRepositoryImpl method findByQuery.

@Override
public Iterable<Profile> findByQuery(String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws MongoDataException {
    try {
        Find find = getCollection().find(query);
        addSort(find, sortBy, sortOrder);
        addRange(find, start, count);
        addProjection(find, attributesToReturn);
        return find.as(Profile.class);
    } catch (MongoException ex) {
        String msg = "Unable to find profiles by query " + query;
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) Find(org.jongo.Find) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 2 with Find

use of org.jongo.Find 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);
    }
}
Also used : MongoException(com.mongodb.MongoException) Find(org.jongo.Find) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 3 with Find

use of org.jongo.Find 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);
    }
}
Also used : MongoException(com.mongodb.MongoException) Find(org.jongo.Find) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 4 with Find

use of org.jongo.Find 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);
    }
}
Also used : MongoException(com.mongodb.MongoException) Find(org.jongo.Find) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 5 with Find

use of org.jongo.Find in project profile by craftercms.

the class ProfileRepositoryImpl method findByIds.

@Override
public Iterable<Profile> findByIds(List<String> ids, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws MongoDataException {
    List<ObjectId> objectIds = new ArrayList<>(ids.size());
    for (String id : ids) {
        try {
            objectIds.add(new ObjectId(id));
        } catch (IllegalArgumentException ex) {
            String msg = "Given id '" + id + "' can't be converted to an ObjectId";
            logger.error(msg, ex);
            throw new MongoDataException(msg, ex);
        }
    }
    try {
        String query = getQueryFor(KEY_FIND_BY_IDS_QUERY);
        Find find = getCollection().find(query, objectIds);
        addSort(find, sortBy, sortOrder);
        addProjection(find, attributesToReturn);
        return find.as(Profile.class);
    } catch (MongoException ex) {
        String msg = "Unable to find profiles for ids " + ids;
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) Find(org.jongo.Find) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Aggregations

MongoException (com.mongodb.MongoException)6 MongoDataException (org.craftercms.commons.mongo.MongoDataException)6 Find (org.jongo.Find)6 ArrayList (java.util.ArrayList)1 ObjectId (org.bson.types.ObjectId)1