Search in sources :

Example 26 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException 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)

Example 27 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfilesByAttributeValue.

@Override
public List<Profile> getProfilesByAttributeValue(String tenantName, String attributeName, String attributeValue, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByTenantAndAttributeValue(tenantName, attributeName, attributeValue, sortBy, sortOrder, attributesToReturn));
        filterNonReadableAttributes(profiles);
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_BY_ATTRIB_VALUE_ERROR, e, attributeName, attributeValue, tenantName);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 28 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfileRange.

@Override
public List<Profile> getProfileRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findRange(tenantName, sortBy, sortOrder, start, count, attributesToReturn));
        filterNonReadableAttributes(profiles);
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILE_RANGE_ERROR, e, start, count, tenantName);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 29 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfileByUsername.

@Override
public Profile getProfileByUsername(String tenantName, String username, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    try {
        Profile profile = profileRepository.findByTenantAndUsername(tenantName, username, attributesToReturn);
        filterNonReadableAttributes(profile);
        return profile;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILE_BY_USERNAME_ERROR, e, username, tenantName);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Example 30 with I10nProfileException

use of org.craftercms.profile.api.exceptions.I10nProfileException in project profile by craftercms.

the class ProfileServiceImpl method getProfilesByRole.

@Override
public List<Profile> getProfilesByRole(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException {
    checkIfManageProfilesIsAllowed(tenantName);
    try {
        List<Profile> profiles = IterableUtils.toList(profileRepository.findByTenantAndRole(tenantName, role, sortBy, sortOrder, attributesToReturn));
        filterNonReadableAttributes(profiles);
        return profiles;
    } catch (MongoDataException e) {
        throw new I10nProfileException(ERROR_KEY_GET_PROFILES_BY_ROLE_ERROR, e, role, tenantName);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Profile(org.craftercms.profile.api.Profile)

Aggregations

I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)31 MongoDataException (org.craftercms.commons.mongo.MongoDataException)26 Profile (org.craftercms.profile.api.Profile)15 Date (java.util.Date)7 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 DuplicateKeyException (org.craftercms.commons.mongo.DuplicateKeyException)3 PersistentLogin (org.craftercms.profile.api.PersistentLogin)3 DisabledProfileException (org.craftercms.profile.exceptions.DisabledProfileException)3 UpdateHelper (org.craftercms.commons.mongo.UpdateHelper)2 VerificationToken (org.craftercms.profile.api.VerificationToken)2 File (java.io.File)1 IOException (java.io.IOException)1 EmailException (org.craftercms.commons.mail.EmailException)1 AttributeDefinition (org.craftercms.profile.api.AttributeDefinition)1 AccessTokenExistsException (org.craftercms.profile.exceptions.AccessTokenExistsException)1 BadCredentialsException (org.craftercms.profile.exceptions.BadCredentialsException)1 InvalidEmailAddressException (org.craftercms.profile.exceptions.InvalidEmailAddressException)1