Search in sources :

Example 21 with MongoDataException

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

the class AuthenticationServiceImpl method createTicket.

@Override
public Ticket createTicket(String profileId) throws ProfileException {
    Profile profile = profileService.getProfile(profileId, ProfileConstants.NO_ATTRIBUTE);
    if (profile != null) {
        String tenantName = profile.getTenant();
        checkIfManageTicketsIsAllowed(tenantName);
        if (!profile.isEnabled()) {
            throw new DisabledProfileException(profile.getId().toString(), tenantName);
        }
        try {
            Ticket ticket = new Ticket();
            ticket.setId(UUID.randomUUID().toString());
            ticket.setTenant(tenantName);
            ticket.setProfileId(profile.getId().toString());
            ticket.setLastRequestTime(new Date());
            ticketRepository.insert(ticket);
            logger.debug(LOG_KEY_TICKET_CREATED, profile.getId(), ticket);
            return ticket;
        } catch (MongoDataException e) {
            throw new I10nProfileException(ERROR_KEY_CREATE_TICKET_ERROR, profile.getId());
        }
    } else {
        throw new NoSuchProfileException.ById(profileId);
    }
}
Also used : Ticket(org.craftercms.profile.api.Ticket) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) DisabledProfileException(org.craftercms.profile.exceptions.DisabledProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

Example 22 with MongoDataException

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

the class TenantServiceImpl method deleteTenant.

@Override
public void deleteTenant(String name) throws ProfileException {
    checkIfTenantActionIsAllowed(name, TenantAction.DELETE_TENANT);
    try {
        profileRepository.removeAll(name);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_ALL_PROFILES_ERROR, e, name);
    }
    try {
        tenantRepository.removeByName(name);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_TENANT_ERROR, e, name);
    }
    logger.debug(LOG_KEY_TENANT_DELETED, name);
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException)

Example 23 with MongoDataException

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

the class ProfileRepositoryImpl method updateAllWithDefaultValue.

@Override
public void updateAllWithDefaultValue(String tenantName, String attributeName, Object defaultValue) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY);
        Update update = getCollection().update(query, tenantName, attributeName).multi();
        update.with(MODIFIER_UPDATE_ATTRIBUTE, attributeName, defaultValue);
    } catch (MongoException ex) {
        String msg = "Unable to add attribute with name '" + attributeName + "' to profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

Example 24 with MongoDataException

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

the class ProfileRepositoryImpl method removeAttributeFromAll.

@Override
public void removeAttributeFromAll(String tenantName, String attributeName) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY);
        Update update = getCollection().update(query, tenantName, attributeName).multi();
        update.with(MODIFIER_REMOVE_ATTRIBUTE, attributeName);
    } catch (MongoException ex) {
        String msg = "Unable to remove attribute with name '" + attributeName + "' from profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

Example 25 with MongoDataException

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

the class ProfileRepositoryImpl method removeRoleFromAll.

@Override
public void removeRoleFromAll(String tenantName, String role) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ROLE_QUERY);
        Update update = getCollection().update(query, tenantName, role).multi();
        update.with(MODIFIER_REMOVE_ROLE, role);
    } catch (MongoException ex) {
        String msg = "Unable to remove role '" + role + "' from profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

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