Search in sources :

Example 6 with I10nProfileException

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

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

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

the class ProfileServiceRestClient method getProfileByQuery.

@Override
public Profile getProfileByQuery(String tenantName, String query, String... attributesToReturn) throws ProfileException {
    MultiValueMap<String, String> params = createBaseParams();
    HttpUtils.addValue(PARAM_TENANT_NAME, tenantName, params);
    HttpUtils.addValue(PARAM_QUERY, query, params);
    HttpUtils.addValues(PARAM_ATTRIBUTE_TO_RETURN, attributesToReturn, params);
    String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_GET_ONE_BY_QUERY);
    url = addQueryParams(url, params, true);
    try {
        return doGetForObject(new URI(url), Profile.class);
    } catch (URISyntaxException e) {
        throw new I10nProfileException(ERROR_KEY_INVALID_URI_ERROR, url);
    } catch (ProfileRestServiceException e) {
        if (e.getStatus() == HttpStatus.NOT_FOUND) {
            return null;
        } else {
            throw e;
        }
    }
}
Also used : ProfileRestServiceException(org.craftercms.profile.exceptions.ProfileRestServiceException) I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 9 with I10nProfileException

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

the class ProfileServiceRestClient method addProfileAttachment.

@Override
public ProfileAttachment addProfileAttachment(String profileId, String attachmentName, InputStream file) throws ProfileException {
    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    params.add(PARAM_ACCESS_TOKEN_ID, accessTokenIdResolver.getAccessTokenId());
    params.add(PARAM_FILENAME, attachmentName);
    String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_UPLOAD_ATTACHMENT);
    File tmpFile = null;
    try {
        tmpFile = File.createTempFile(profileId + "-" + attachmentName, "attachment");
        FileUtils.copyInputStreamToFile(file, tmpFile);
        params.add("attachment", new FileSystemResource(tmpFile));
        return doPostForUpload(url, params, ProfileAttachment.class, profileId);
    } catch (IOException e) {
        throw new I10nProfileException(ERROR_KEY_TMP_COPY_FAILED, e, attachmentName, profileId);
    } finally {
        try {
            file.close();
            FileUtils.forceDelete(tmpFile);
        } catch (Throwable e) {
        }
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) File(java.io.File)

Example 10 with I10nProfileException

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

the class ProfileServiceRestClient method getProfileCountByQuery.

@Override
public long getProfileCountByQuery(String tenantName, String query) throws ProfileException {
    MultiValueMap<String, String> params = createBaseParams();
    HttpUtils.addValue(PARAM_TENANT_NAME, tenantName, params);
    HttpUtils.addValue(PARAM_QUERY, query, params);
    String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_TENANT_COUNT_BY_QUERY);
    url = addQueryParams(url, params, true);
    try {
        return doGetForObject(new URI(url), Long.class);
    } 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)

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