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