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