use of org.orcid.core.exception.OrcidNotClaimedException in project ORCID-Source by ORCID.
the class OrcidInfo method publicPreview.
@RequestMapping(value = { "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}", "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/print" })
public ModelAndView publicPreview(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") int pageNo, @RequestParam(value = "v", defaultValue = "0") int v, @RequestParam(value = "maxResults", defaultValue = "15") int maxResults, @PathVariable("orcid") String orcid) {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (Exception e) {
return new ModelAndView("error-404");
}
try {
// Check if the profile is deprecated, non claimed or locked
orcidSecurityManager.checkProfile(orcid);
} catch (OrcidDeprecatedException | OrcidNotClaimedException | LockedException e) {
ModelAndView mav = new ModelAndView("public_profile_unavailable");
mav.addObject("effectiveUserOrcid", orcid);
String displayName = "";
if (e instanceof OrcidDeprecatedException) {
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
mav.addObject("deprecated", true);
mav.addObject("primaryRecord", profile.getPrimaryRecord().getId());
} else if (e instanceof OrcidNotClaimedException) {
displayName = localeManager.resolveMessage("orcid.reserved_for_claim");
} else {
mav.addObject("locked", true);
mav.addObject("isPublicProfile", true);
displayName = localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name");
}
if (!PojoUtil.isEmpty(displayName)) {
mav.addObject("title", getMessage("layout.public-layout.title", displayName, orcid));
mav.addObject("displayName", displayName);
}
return mav;
}
long lastModifiedTime = getLastModifiedTime(orcid);
ModelAndView mav = null;
if (request.getRequestURI().contains("/print")) {
mav = new ModelAndView("print_public_record");
mav.addObject("hideUserVoiceScript", true);
} else {
mav = new ModelAndView("public_profile_v3");
}
mav.addObject("isPublicProfile", true);
mav.addObject("effectiveUserOrcid", orcid);
mav.addObject("lastModifiedTime", lastModifiedTime);
boolean isProfileEmtpy = true;
HttpSession session = request.getSession(false);
if (session != null) {
session.removeAttribute(PUBLIC_WORKS_RESULTS_ATTRIBUTE);
}
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
// Fill personal details
if (publicPersonalDetails != null) {
// Get display name
String displayName = "";
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
if (!PojoUtil.isEmpty(displayName)) {
// <Published Name> (<ORCID iD>) - ORCID | Connecting Research
// and Researchers
mav.addObject("title", getMessage("layout.public-layout.title", displayName.trim(), orcid));
mav.addObject("displayName", displayName);
}
// Get biography
if (publicPersonalDetails.getBiography() != null) {
Biography bio = publicPersonalDetails.getBiography();
if (org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.equals(bio.getVisibility()) && !PojoUtil.isEmpty(bio.getContent())) {
isProfileEmtpy = false;
mav.addObject("biography", bio);
}
}
// Fill other names
OtherNames publicOtherNames = publicPersonalDetails.getOtherNames();
if (publicOtherNames != null && publicOtherNames.getOtherNames() != null) {
Iterator<OtherName> it = publicOtherNames.getOtherNames().iterator();
while (it.hasNext()) {
OtherName otherName = it.next();
if (!org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.equals(otherName.getVisibility())) {
it.remove();
}
}
}
Map<String, List<OtherName>> groupedOtherNames = groupOtherNames(publicOtherNames);
mav.addObject("publicGroupedOtherNames", groupedOtherNames);
}
// Fill biography elements
// Fill country
Addresses publicAddresses = addressManager.getPublicAddresses(orcid, lastModifiedTime);
Map<String, String> countryNames = new HashMap<String, String>();
if (publicAddresses != null && publicAddresses.getAddress() != null) {
Address publicAddress = null;
// The primary address will be the one with the lowest display index
for (Address address : publicAddresses.getAddress()) {
countryNames.put(address.getCountry().getValue().value(), getcountryName(address.getCountry().getValue().value()));
if (publicAddress == null) {
publicAddress = address;
}
}
if (publicAddress != null) {
mav.addObject("publicAddress", publicAddress);
mav.addObject("countryNames", countryNames);
Map<String, List<Address>> groupedAddresses = groupAddresses(publicAddresses);
mav.addObject("publicGroupedAddresses", groupedAddresses);
}
}
// Fill keywords
Keywords publicKeywords = keywordManager.getPublicKeywords(orcid, lastModifiedTime);
Map<String, List<Keyword>> groupedKeywords = groupKeywords(publicKeywords);
mav.addObject("publicGroupedKeywords", groupedKeywords);
// Fill researcher urls
ResearcherUrls publicResearcherUrls = researcherUrlManager.getPublicResearcherUrls(orcid, lastModifiedTime);
Map<String, List<ResearcherUrl>> groupedResearcherUrls = groupResearcherUrls(publicResearcherUrls);
mav.addObject("publicGroupedResearcherUrls", groupedResearcherUrls);
// Fill emails
Emails publicEmails = emailManager.getPublicEmails(orcid, lastModifiedTime);
Map<String, List<Email>> groupedEmails = groupEmails(publicEmails);
mav.addObject("publicGroupedEmails", groupedEmails);
// Fill external identifiers
PersonExternalIdentifiers publicPersonExternalIdentifiers = externalIdentifierManager.getPublicExternalIdentifiers(orcid, lastModifiedTime);
Map<String, List<PersonExternalIdentifier>> groupedExternalIdentifiers = groupExternalIdentifiers(publicPersonExternalIdentifiers);
mav.addObject("publicGroupedPersonExternalIdentifiers", groupedExternalIdentifiers);
LinkedHashMap<Long, WorkForm> minimizedWorksMap = new LinkedHashMap<>();
LinkedHashMap<Long, Affiliation> affiliationMap = new LinkedHashMap<>();
LinkedHashMap<Long, Funding> fundingMap = new LinkedHashMap<>();
LinkedHashMap<Long, PeerReview> peerReviewMap = new LinkedHashMap<>();
minimizedWorksMap = activityCacheManager.pubMinWorksMap(orcid, lastModifiedTime);
if (minimizedWorksMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("worksEmpty", true);
}
affiliationMap = affiliationMap(orcid, lastModifiedTime);
if (affiliationMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("affiliationsEmpty", true);
}
fundingMap = fundingMap(orcid, lastModifiedTime);
if (fundingMap.size() > 0)
isProfileEmtpy = false;
else {
mav.addObject("fundingEmpty", true);
}
peerReviewMap = peerReviewMap(orcid, lastModifiedTime);
if (peerReviewMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("peerReviewsEmpty", true);
}
ObjectMapper mapper = new ObjectMapper();
try {
String worksIdsJson = mapper.writeValueAsString(minimizedWorksMap.keySet());
String affiliationIdsJson = mapper.writeValueAsString(affiliationMap.keySet());
String fundingIdsJson = mapper.writeValueAsString(fundingMap.keySet());
String peerReviewIdsJson = mapper.writeValueAsString(peerReviewMap.keySet());
mav.addObject("workIdsJson", StringEscapeUtils.escapeEcmaScript(worksIdsJson));
mav.addObject("affiliationIdsJson", StringEscapeUtils.escapeEcmaScript(affiliationIdsJson));
mav.addObject("fundingIdsJson", StringEscapeUtils.escapeEcmaScript(fundingIdsJson));
mav.addObject("peerReviewIdsJson", StringEscapeUtils.escapeEcmaScript(peerReviewIdsJson));
mav.addObject("isProfileEmpty", isProfileEmtpy);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (!profile.isReviewed()) {
if (isProfileValidForIndex(profile)) {
int countTokens = orcidOauth2TokenService.findCountByUserName(orcid, lastModifiedTime);
if (!profile.isAccountNonLocked() || countTokens == 0 || (!CreationMethod.WEBSITE.value().equals(profile.getCreationMethod()) && !CreationMethod.DIRECT.value().equals(profile.getCreationMethod()))) {
mav.addObject("noIndex", true);
}
} else {
mav.addObject("noIndex", true);
}
}
return mav;
}
use of org.orcid.core.exception.OrcidNotClaimedException in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorImpl method checkRecordStatus.
/**
* Checks if an account is deprecated
*
* @param orcidMessage
* OrcidMessage, for it we can get the orcid to check for
* deprecation
* @throws DeprecatedException
* if the account is deprecated
*/
public void checkRecordStatus(String orcid) {
ProfileEntity entity = profileEntityCacheManager.retrieve(orcid);
if (entity != null) {
if (entity.getPrimaryRecord() != null) {
Map<String, String> params = new HashMap<String, String>();
StringBuffer primary = new StringBuffer(orcidUrlManager.getBaseUrl()).append("/").append(entity.getPrimaryRecord().getId());
params.put(OrcidDeprecatedException.ORCID, primary.toString());
if (entity.getDeprecatedDate() != null) {
XMLGregorianCalendar calendar = DateUtils.convertToXMLGregorianCalendar(entity.getDeprecatedDate());
params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
}
throw new OrcidDeprecatedException(params);
} else if (entity.getDeactivationDate() != null) {
DeactivatedException exception = new DeactivatedException(localeManager.resolveMessage("apiError.9044.developerMessage"));
exception.setOrcid(orcid);
throw exception;
} else if (!entity.isAccountNonLocked()) {
LockedException lockedException = new LockedException(localeManager.resolveMessage("apiError.9018.developerMessage"));
lockedException.setOrcid(orcid);
throw lockedException;
} else {
// Check if the user record is not claimed and not old enough
if ((entity.getClaimed() == null || Boolean.FALSE.equals(entity.getClaimed())) && !isOldEnough(entity)) {
// Let the creator access the profile even if it is not claimed and
// not old enough
SourceEntity currentSourceEntity = sourceManager.retrieveSourceEntity();
String profileSource = entity.getSource() == null ? null : entity.getSource().getSourceId();
String currentSource = currentSourceEntity == null ? null : currentSourceEntity.getSourceId();
// the profile source, throw an exception
if (profileSource == null || !Objects.equals(profileSource, currentSource)) {
throw new OrcidNotClaimedException(localeManager.resolveMessage("apiError.9036.developerMessage"));
}
}
}
}
}
use of org.orcid.core.exception.OrcidNotClaimedException in project ORCID-Source by ORCID.
the class OrcidInfo method publicPreview.
@RequestMapping(value = { "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}", "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/print" })
public ModelAndView publicPreview(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "page", defaultValue = "1") int pageNo, @RequestParam(value = "v", defaultValue = "0") int v, @RequestParam(value = "maxResults", defaultValue = "15") int maxResults, @PathVariable("orcid") String orcid) {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (Exception e) {
response.setStatus(HttpStatus.NOT_FOUND.value());
return new ModelAndView("error-404");
}
try {
// Check if the profile is deprecated, non claimed or locked
orcidSecurityManager.checkProfile(orcid);
} catch (OrcidDeprecatedException | OrcidNotClaimedException | LockedException | DeactivatedException e) {
ModelAndView mav = new ModelAndView("public_profile_unavailable");
mav.addObject("effectiveUserOrcid", orcid);
String displayName = "";
if (e instanceof OrcidDeprecatedException) {
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
mav.addObject("deprecated", true);
mav.addObject("primaryRecord", profile.getPrimaryRecord().getId());
} else if (e instanceof OrcidNotClaimedException) {
displayName = localeManager.resolveMessage("orcid.reserved_for_claim");
} else if (e instanceof LockedException) {
mav.addObject("locked", true);
mav.addObject("isPublicProfile", true);
displayName = localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name");
} else {
mav.addObject("deactivated", true);
displayName = localeManager.resolveMessage("public_profile.deactivated.given_names") + " " + localeManager.resolveMessage("public_profile.deactivated.family_name");
}
if (!PojoUtil.isEmpty(displayName)) {
mav.addObject("title", getMessage("layout.public-layout.title", displayName, orcid));
mav.addObject("displayName", displayName);
}
return mav;
}
long lastModifiedTime = getLastModifiedTime(orcid);
ModelAndView mav = null;
if (request.getRequestURI().contains("/print")) {
mav = new ModelAndView("print_public_record");
mav.addObject("hideUserVoiceScript", true);
} else {
mav = new ModelAndView("public_profile_v3");
}
mav.addObject("isPublicProfile", true);
mav.addObject("effectiveUserOrcid", orcid);
mav.addObject("lastModifiedTime", lastModifiedTime);
boolean isProfileEmtpy = true;
PersonalDetails publicPersonalDetails = personalDetailsManager.getPublicPersonalDetails(orcid);
// Fill personal details
if (publicPersonalDetails != null) {
// Get display name
String displayName = "";
if (publicPersonalDetails.getName() != null) {
Name name = publicPersonalDetails.getName();
if (name.getVisibility().equals(Visibility.PUBLIC)) {
if (name.getCreditName() != null && !PojoUtil.isEmpty(name.getCreditName().getContent())) {
displayName = name.getCreditName().getContent();
} else {
if (name.getGivenNames() != null && !PojoUtil.isEmpty(name.getGivenNames().getContent())) {
displayName = name.getGivenNames().getContent() + " ";
}
if (name.getFamilyName() != null && !PojoUtil.isEmpty(name.getFamilyName().getContent())) {
displayName += name.getFamilyName().getContent();
}
}
}
}
if (!PojoUtil.isEmpty(displayName)) {
// <Published Name> (<ORCID iD>) - ORCID | Connecting Research
// and Researchers
mav.addObject("title", getMessage("layout.public-layout.title", displayName.trim(), orcid));
mav.addObject("displayName", displayName);
}
// Get biography
if (publicPersonalDetails.getBiography() != null) {
Biography bio = publicPersonalDetails.getBiography();
if (Visibility.PUBLIC.equals(bio.getVisibility()) && !PojoUtil.isEmpty(bio.getContent())) {
isProfileEmtpy = false;
mav.addObject("biography", bio);
}
}
// Fill other names
OtherNames publicOtherNames = publicPersonalDetails.getOtherNames();
if (publicOtherNames != null && publicOtherNames.getOtherNames() != null) {
Iterator<OtherName> it = publicOtherNames.getOtherNames().iterator();
while (it.hasNext()) {
OtherName otherName = it.next();
if (!Visibility.PUBLIC.equals(otherName.getVisibility())) {
it.remove();
}
}
}
Map<String, List<OtherName>> groupedOtherNames = groupOtherNames(publicOtherNames);
mav.addObject("publicGroupedOtherNames", groupedOtherNames);
}
// Fill biography elements
// Fill country
Addresses publicAddresses = addressManager.getPublicAddresses(orcid);
Map<String, String> countryNames = new HashMap<String, String>();
if (publicAddresses != null && publicAddresses.getAddress() != null) {
Address publicAddress = null;
// The primary address will be the one with the lowest display index
for (Address address : publicAddresses.getAddress()) {
countryNames.put(address.getCountry().getValue().value(), getcountryName(address.getCountry().getValue().value()));
if (publicAddress == null) {
publicAddress = address;
}
}
if (publicAddress != null) {
mav.addObject("publicAddress", publicAddress);
mav.addObject("countryNames", countryNames);
Map<String, List<Address>> groupedAddresses = groupAddresses(publicAddresses);
mav.addObject("publicGroupedAddresses", groupedAddresses);
}
}
// Fill keywords
Keywords publicKeywords = keywordManager.getPublicKeywords(orcid);
Map<String, List<Keyword>> groupedKeywords = groupKeywords(publicKeywords);
mav.addObject("publicGroupedKeywords", groupedKeywords);
// Fill researcher urls
ResearcherUrls publicResearcherUrls = researcherUrlManager.getPublicResearcherUrls(orcid);
Map<String, List<ResearcherUrl>> groupedResearcherUrls = groupResearcherUrls(publicResearcherUrls);
mav.addObject("publicGroupedResearcherUrls", groupedResearcherUrls);
// Fill emails
Emails publicEmails = emailManager.getPublicEmails(orcid);
Map<String, List<Email>> groupedEmails = groupEmails(publicEmails);
mav.addObject("publicGroupedEmails", groupedEmails);
// Fill external identifiers
PersonExternalIdentifiers publicPersonExternalIdentifiers = externalIdentifierManager.getPublicExternalIdentifiers(orcid);
Map<String, List<PersonExternalIdentifier>> groupedExternalIdentifiers = groupExternalIdentifiers(publicPersonExternalIdentifiers);
mav.addObject("publicGroupedPersonExternalIdentifiers", groupedExternalIdentifiers);
LinkedHashMap<Long, Affiliation> affiliationMap = new LinkedHashMap<>();
LinkedHashMap<Long, Funding> fundingMap = new LinkedHashMap<>();
LinkedHashMap<Long, PeerReview> peerReviewMap = new LinkedHashMap<>();
if (worksPaginator.getPublicWorksCount(orcid) > 0) {
isProfileEmtpy = false;
}
affiliationMap = activityManager.affiliationMap(orcid);
if (affiliationMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("affiliationsEmpty", true);
}
fundingMap = activityManager.fundingMap(orcid);
if (fundingMap.size() > 0)
isProfileEmtpy = false;
else {
mav.addObject("fundingEmpty", true);
}
peerReviewMap = activityManager.pubPeerReviewsMap(orcid);
if (peerReviewMap.size() > 0) {
isProfileEmtpy = false;
} else {
mav.addObject("peerReviewsEmpty", true);
}
ObjectMapper mapper = new ObjectMapper();
try {
String affiliationIdsJson = mapper.writeValueAsString(affiliationMap.keySet());
String fundingIdsJson = mapper.writeValueAsString(fundingMap.keySet());
String peerReviewIdsJson = mapper.writeValueAsString(peerReviewMap.keySet());
mav.addObject("affiliationIdsJson", StringEscapeUtils.escapeEcmaScript(affiliationIdsJson));
mav.addObject("fundingIdsJson", StringEscapeUtils.escapeEcmaScript(fundingIdsJson));
mav.addObject("peerReviewIdsJson", StringEscapeUtils.escapeEcmaScript(peerReviewIdsJson));
mav.addObject("isProfileEmpty", isProfileEmtpy);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (!profile.isReviewed()) {
if (isProfileValidForIndex(profile)) {
int countTokens = orcidOauth2TokenService.findCountByUserName(orcid, lastModifiedTime);
if (!profile.isAccountNonLocked() || countTokens == 0 || (!CreationMethod.WEBSITE.value().equals(profile.getCreationMethod()) && !CreationMethod.DIRECT.value().equals(profile.getCreationMethod()))) {
mav.addObject("noIndex", true);
}
} else {
mav.addObject("noIndex", true);
}
}
return mav;
}
use of org.orcid.core.exception.OrcidNotClaimedException in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkProfile.
/**
* Checks a record status and throw an exception indicating if the profile
* have any of the following conditions: - The record is not claimed and is
* not old enough nor being accessed by its creator - It is locked - It is
* deprecated - It is deactivated
*
* @throws OrcidDeprecatedException
* in case the account is deprecated
* @throws OrcidNotClaimedException
* in case the account is not claimed
* @throws LockedException
* in the case the account is locked
*/
@Override
public void checkProfile(String orcid) throws NoResultException, OrcidDeprecatedException, OrcidNotClaimedException, LockedException, DeactivatedException {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (IllegalArgumentException e) {
throw new NoResultException();
}
// Check if the user record is deprecated
if (profile.getPrimaryRecord() != null) {
StringBuffer primary = new StringBuffer(baseUrl).append("/").append(profile.getPrimaryRecord().getId());
Map<String, String> params = new HashMap<String, String>();
params.put(OrcidDeprecatedException.ORCID, primary.toString());
if (profile.getDeprecatedDate() != null) {
XMLGregorianCalendar calendar = DateUtils.convertToXMLGregorianCalendar(profile.getDeprecatedDate());
params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
}
throw new OrcidDeprecatedException(params);
}
// Check if the user record is not claimed and not old enough
if ((profile.getClaimed() == null || Boolean.FALSE.equals(profile.getClaimed())) && !isOldEnough(profile)) {
// Let the creator access the profile even if it is not claimed and
// not old enough
SourceEntity currentSourceEntity = sourceManager.retrieveSourceEntity();
String profileSource = profile.getSource() == null ? null : profile.getSource().getSourceId();
String currentSource = currentSourceEntity == null ? null : currentSourceEntity.getSourceId();
// the profile source, throw an exception
if (profileSource == null || !Objects.equals(profileSource, currentSource)) {
throw new OrcidNotClaimedException();
}
}
// Check if the user record is locked
if (!profile.isAccountNonLocked()) {
LockedException lockedException = new LockedException();
lockedException.setOrcid(profile.getId());
throw lockedException;
}
// Check if the user record is deactivated
if (profile.getDeactivationDate() != null) {
DeactivatedException exception = new DeactivatedException();
exception.setOrcid(orcid);
throw exception;
}
}
use of org.orcid.core.exception.OrcidNotClaimedException in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkProfile.
/**
* Checks a record status and throw an exception indicating if the profile
* have any of the following conditions: - The record is not claimed and is
* not old enough nor being accessed by its creator - It is locked - It is
* deprecated - It is deactivated
*
* @throws OrcidDeprecatedException
* in case the account is deprecated
* @throws OrcidNotClaimedException
* in case the account is not claimed
* @throws LockedException
* in the case the account is locked
*/
@Override
public void checkProfile(String orcid) throws NoResultException, OrcidDeprecatedException, OrcidNotClaimedException, LockedException, DeactivatedException {
ProfileEntity profile = null;
try {
profile = profileEntityCacheManager.retrieve(orcid);
} catch (IllegalArgumentException e) {
throw new NoResultException();
}
// Check if the user record is deprecated
if (profile.getPrimaryRecord() != null) {
StringBuffer primary = new StringBuffer(baseUrl).append("/").append(profile.getPrimaryRecord().getId());
Map<String, String> params = new HashMap<String, String>();
params.put(OrcidDeprecatedException.ORCID, primary.toString());
if (profile.getDeprecatedDate() != null) {
XMLGregorianCalendar calendar = DateUtils.convertToXMLGregorianCalendar(profile.getDeprecatedDate());
params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
}
StringBuffer deprecated = new StringBuffer(baseUrl).append("/").append(profile.getId());
params.put(OrcidDeprecatedException.DEPRECATED_ORCID, deprecated.toString());
throw new OrcidDeprecatedException(params);
}
// Check if the user record is not claimed and not old enough
if ((profile.getClaimed() == null || Boolean.FALSE.equals(profile.getClaimed())) && !isOldEnough(profile)) {
// Let the creator access the profile even if it is not claimed and
// not old enough
SourceEntity currentSourceEntity = sourceManager.retrieveSourceEntity();
String profileSource = profile.getSource() == null ? null : profile.getSource().getSourceId();
String currentSource = currentSourceEntity == null ? null : currentSourceEntity.getSourceId();
// the profile source, throw an exception
if (profileSource == null || !Objects.equals(profileSource, currentSource)) {
throw new OrcidNotClaimedException();
}
}
// Check if the user record is locked
if (!profile.isAccountNonLocked()) {
LockedException lockedException = new LockedException();
StringBuffer orcidId = new StringBuffer(baseUrl).append("/").append(profile.getId());
lockedException.setOrcid(orcidId.toString());
throw lockedException;
}
// Check if the user record is deactivated
if (profile.getDeactivationDate() != null) {
DeactivatedException exception = new DeactivatedException();
exception.setOrcid(orcid);
throw exception;
}
}
Aggregations