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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations