Search in sources :

Example 11 with MongoDataException

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

Example 12 with MongoDataException

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);
    }
}
Also used : FindOne(org.jongo.FindOne) MongoException(com.mongodb.MongoException) ObjectId(org.bson.types.ObjectId) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 13 with MongoDataException

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

Example 14 with MongoDataException

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

Example 15 with MongoDataException

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

Aggregations

MongoDataException (org.craftercms.commons.mongo.MongoDataException)39 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)27 Profile (org.craftercms.profile.api.Profile)15 MongoException (com.mongodb.MongoException)12 Date (java.util.Date)7 Find (org.jongo.Find)6 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4 ObjectId (org.bson.types.ObjectId)3 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)3 PersistentLogin (org.craftercms.profile.api.PersistentLogin)3 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)3 FindOne (org.jongo.FindOne)3 Update (org.jongo.Update)3 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 FileExistsException (org.apache.commons.io.FileExistsException)1 FileInfo (org.craftercms.commons.mongo.FileInfo)1