Search in sources :

Example 26 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.

the class ProfileRepositoryImpl method findRange.

@Override
public Iterable<Profile> findRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_QUERY);
        Find find = getCollection().find(query, tenantName);
        addSort(find, sortBy, sortOrder);
        addRange(find, start, count);
        addProjection(find, attributesToReturn);
        return find.as(Profile.class);
    } catch (MongoException ex) {
        String msg = "Unable to find range of profiles for 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 27 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.

the class AuthenticationServiceImpl method refreshPersistentLoginToken.

@Override
public PersistentLogin refreshPersistentLoginToken(String loginId) throws ProfileException {
    PersistentLogin login = getPersistentLogin(loginId);
    if (login != null) {
        try {
            login.setToken(UUID.randomUUID().toString());
            persistentLoginRepository.save(login);
            logger.debug(LOG_KEY_PERSISTENT_LOGIN_TOKEN_REFRESHED, loginId, login.getToken());
            return login;
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_PERSISTENT_LOGIN_ERROR, loginId);
        }
    } else {
        throw new NoSuchPersistentLoginException(loginId);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) NoSuchPersistentLoginException(org.craftercms.profile.exceptions.NoSuchPersistentLoginException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) PersistentLogin(org.craftercms.profile.api.PersistentLogin)

Example 28 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.

the class AuthenticationServiceImpl method getTicket.

@Override
public Ticket getTicket(String ticketId) throws ProfileException {
    Ticket ticket;
    try {
        ticket = ticketRepository.findByStringId(ticketId);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_TICKET_ERROR, e, ticketId);
    }
    if (ticket != null) {
        checkIfManageTicketsIsAllowed(ticket.getTenant());
        ticket.setLastRequestTime(new Date());
        try {
            ticketRepository.save(ticket);
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TICKET_ERROR, ticketId);
        }
        logger.debug(LOG_KEY_TICKET_REQUESTED, ticketId);
        return ticket;
    }
    return null;
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Date(java.util.Date)

Example 29 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.

the class TenantServiceImpl method updateTenant.

protected Tenant updateTenant(String tenantName, UpdateCallback callback) throws ProfileException {
    Tenant tenant = getTenant(tenantName);
    if (tenant != null) {
        checkIfTenantActionIsAllowed(tenantName, TenantAction.UPDATE_TENANT);
        UpdateHelper updateHelper = new UpdateHelper();
        TenantUpdater tenantUpdater = new TenantUpdater(tenant, updateHelper, tenantRepository);
        callback.doWithTenant(tenantUpdater);
        try {
            tenantUpdater.update();
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_UPDATE_TENANT_ERROR, e, tenant.getName());
        }
    } else {
        throw new NoSuchTenantException(tenantName);
    }
    return tenant;
}
Also used : NoSuchTenantException(org.craftercms.profile.exceptions.NoSuchTenantException) UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) Tenant(org.craftercms.profile.api.Tenant) TenantUpdater(org.craftercms.profile.utils.db.TenantUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 30 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException in project profile by craftercms.

the class TenantServiceImpl method createTenant.

@Override
public Tenant createTenant(Tenant tenant) throws ProfileException {
    checkIfTenantActionIsAllowed(null, TenantAction.CREATE_TENANT);
    // Make sure ID is null, we want it auto-generated
    tenant.setId(null);
    try {
        tenantRepository.insert(tenant);
    } catch (DuplicateKeyException e) {
        throw new TenantExistsException(tenant.getName());
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_TENANT_ERROR, e, tenant.getName());
    }
    logger.debug(LOG_KEY_TENANT_CREATED, tenant);
    return tenant;
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) TenantExistsException(org.craftercms.profile.exceptions.TenantExistsException) DuplicateKeyException(org.craftercms.commons.mongo.DuplicateKeyException)

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