Search in sources :

Example 31 with MongoDataException

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

the class AccessTokenServiceImpl method createToken.

@Override
public AccessToken createToken(AccessToken token) throws ProfileException {
    checkIfTokenActionIsAllowed(null, Action.CREATE_TOKEN);
    if (token.getId() == null) {
        token.setId(UUID.randomUUID().toString());
    }
    try {
        accessTokenRepository.insert(token);
    } catch (DuplicateKeyException e) {
        throw new AccessTokenExistsException(token.getId());
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_ACCESS_TOKEN_ERROR, e, token);
    }
    logger.debug(LOG_KEY_ACCESS_TOKEN_CREATED, token);
    return token;
}
Also used : AccessTokenExistsException(org.craftercms.profile.exceptions.AccessTokenExistsException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) DuplicateKeyException(org.craftercms.commons.mongo.DuplicateKeyException)

Example 32 with MongoDataException

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

the class ProfileServiceImpl method getProfileByQuery.

@Override
public Profile getProfileByQuery(String tenantName, String query, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    Tenant tenant = getTenant(tenantName);
    try {
        Profile profile = profileRepository.findOneByQuery(getFinalQuery(tenant, query), attributesToReturn);
        filterNonReadableAttributes(tenant, profile);
        return profile;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILE_BY_QUERY_ERROR, e, query);
    }
}
Also used : Tenant(org.craftercms.profile.api.Tenant) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 33 with MongoDataException

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

the class ProfileServiceImpl method getProfilesByIds.

@Override
public List<Profile> getProfilesByIds(List<String> profileIds, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException {
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByIds(profileIds, sortBy, sortOrder, attributesToReturn));
        if (profiles != null) {
            for (Profile profile : profiles) {
                checkIfManageProfilesIsAllowed(profile.getTenant());
                filterNonReadableAttributes(profile);
            }
        }
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_ERROR, e, profileIds);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 34 with MongoDataException

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

the class ProfileServiceImpl method deleteProfile.

@Override
public void deleteProfile(String profileId) throws ProfileException {
    try {
        Profile profile = getProfile(profileId);
        if (profile != null) {
            profileRepository.removeById(profileId);
        }
        logger.debug(LOG_KEY_PROFILE_DELETED, profileId);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_DELETE_PROFILE_ERROR, e, profileId);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 35 with MongoDataException

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

the class ProfileServiceImpl method updateProfile.

protected Profile updateProfile(String profileId, UpdateCallback callback, String... attributesToReturn) throws ProfileException {
    // We need to filter the attributes after save, if not, the attributes to return will replace all the
    // attributes
    Profile profile = getNonNullProfile(profileId);
    UpdateHelper updateHelper = new UpdateHelper();
    ProfileUpdater profileUpdater = new ProfileUpdater(profile, updateHelper, profileRepository);
    callback.doWithProfile(profileUpdater);
    profileUpdater.setLastModified(new Date());
    try {
        profileUpdater.update();
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_UPDATE_PROFILE_ERROR, e, profileId);
    }
    return filterAttributes(profile, attributesToReturn);
}
Also used : UpdateHelper(org.craftercms.commons.mongo.UpdateHelper) ProfileUpdater(org.craftercms.profile.utils.db.ProfileUpdater) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile) Date(java.util.Date)

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