Search in sources :

Example 21 with I10nProfileException

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

the class ProfileServiceRestClient method getProfilesByQuery.

@Override
public List<Profile> getProfilesByQuery(String tenantName, String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws ProfileException {
    MultiValueMap<String, String> params = createBaseParams();
    HttpUtils.addValue(PARAM_TENANT_NAME, tenantName, params);
    HttpUtils.addValue(PARAM_QUERY, query, params);
    HttpUtils.addValue(PARAM_SORT_BY, sortBy, params);
    HttpUtils.addValue(PARAM_SORT_ORDER, sortOrder, params);
    HttpUtils.addValue(PARAM_START, start, params);
    HttpUtils.addValue(PARAM_COUNT, count, params);
    HttpUtils.addValues(PARAM_ATTRIBUTE_TO_RETURN, attributesToReturn, params);
    String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_GET_BY_QUERY);
    url = addQueryParams(url, params, true);
    try {
        return doGetForObject(new URI(url), profileListTypeRef);
    } catch (URISyntaxException e) {
        throw new I10nProfileException(ERROR_KEY_INVALID_URI_ERROR, url);
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 22 with I10nProfileException

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

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

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

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

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