Search in sources :

Example 6 with MongoDataException

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

the class ProfileServiceImpl method getProfile.

@Override
public Profile getProfile(String profileId, String... attributesToReturn) throws ProfileException {
    try {
        Profile profile = profileRepository.findById(profileId, attributesToReturn);
        if (profile != null) {
            checkIfManageProfilesIsAllowed(profile.getTenant());
            filterNonReadableAttributes(profile);
        }
        return profile;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_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 7 with MongoDataException

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

the class ProfileServiceImpl method addProfileAttachment.

@Override
public ProfileAttachment addProfileAttachment(final String profileId, final String attachmentName, final InputStream file) throws ProfileException {
    String storeName = "/" + profileId + "/" + FilenameUtils.removeExtension(attachmentName);
    try {
        ObjectId currentId = checkIfAttachmentExist(storeName);
        String mimeType = getAttachmentContentType(attachmentName);
        FileInfo fileInfo;
        if (currentId != null) {
            // Update !!!
            fileInfo = profileRepository.updateFile(currentId, file, storeName, mimeType, true);
        } else {
            fileInfo = profileRepository.saveFile(file, storeName, mimeType);
        }
        return fileInfoToProfileAttachment(fileInfo);
    } catch (MongoDataException | FileExistsException | FileNotFoundException e) {
        throw new ProfileException("Unable to attach file to profile '" + profileId + "'", e);
    }
}
Also used : FileInfo(org.craftercms.commons.mongo.FileInfo) ObjectId(org.bson.types.ObjectId) FileNotFoundException(java.io.FileNotFoundException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) NoSuchProfileException(org.craftercms.profile.exceptions.NoSuchProfileException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) ProfileException(org.craftercms.profile.api.exceptions.ProfileException) FileExistsException(org.apache.commons.io.FileExistsException)

Example 8 with MongoDataException

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

the class VerificationServiceImpl method createToken.

@Override
public VerificationToken createToken(Profile profile) throws ProfileException {
    String tenant = profile.getTenant();
    String profileId = profile.getId().toString();
    VerificationToken token = new VerificationToken();
    token.setId(UUID.randomUUID().toString());
    token.setTenant(tenant);
    token.setProfileId(profileId);
    token.setTimestamp(new Date());
    try {
        tokenRepository.insert(token);
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_CREATE_TOKEN_ERROR, profileId);
    }
    logger.debug(LOG_KEY_TOKEN_CREATED, profileId, token);
    return token;
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Date(java.util.Date)

Example 9 with MongoDataException

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

the class ProfileRepositoryImpl method findOneByQuery.

@Override
public Profile findOneByQuery(String query, String... attributesToReturn) throws MongoDataException {
    try {
        FindOne findOne = getCollection().findOne(query);
        addProjection(findOne, attributesToReturn);
        return findOne.as(Profile.class);
    } catch (MongoException ex) {
        String msg = "Unable to find profile by query '" + query + "'";
        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 10 with MongoDataException

use of org.craftercms.commons.mongo.MongoDataException 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)

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