use of javax.xml.datatype.XMLGregorianCalendar 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 {
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 profile 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 record is locked
if (!profile.isAccountNonLocked()) {
LockedException lockedException = new LockedException();
lockedException.setOrcid(profile.getId());
throw lockedException;
}
}
use of javax.xml.datatype.XMLGregorianCalendar in project ORCID-Source by ORCID.
the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.
public static Date calculateLatest(Keywords keywords) {
Date latestAct = null;
if (keywords != null && keywords.getKeywords() != null && !keywords.getKeywords().isEmpty()) {
XMLGregorianCalendar latest = keywords.getKeywords().get(0).getLastModifiedDate().getValue();
for (Keyword keyword : keywords.getKeywords()) {
if (latest.compare(keyword.getLastModifiedDate().getValue()) == -1) {
latest = keyword.getLastModifiedDate().getValue();
}
}
latestAct = latest.toGregorianCalendar().getTime();
keywords.setLastModifiedDate(new LastModifiedDate(latest));
}
return latestAct;
}
use of javax.xml.datatype.XMLGregorianCalendar in project ORCID-Source by ORCID.
the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.
public static Date calculateLatest(PersonExternalIdentifiers extIds) {
Date latestAct = null;
if (extIds != null && extIds.getExternalIdentifiers() != null && !extIds.getExternalIdentifiers().isEmpty()) {
XMLGregorianCalendar latest = extIds.getExternalIdentifiers().get(0).getLastModifiedDate().getValue();
for (PersonExternalIdentifier extId : extIds.getExternalIdentifiers()) {
if (latest.compare(extId.getLastModifiedDate().getValue()) == -1) {
latest = extId.getLastModifiedDate().getValue();
}
}
latestAct = latest.toGregorianCalendar().getTime();
extIds.setLastModifiedDate(new LastModifiedDate(latest));
}
return latestAct;
}
use of javax.xml.datatype.XMLGregorianCalendar in project ORCID-Source by ORCID.
the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.
public static Date calculateLatest(GroupIdRecords groupIdRecords) {
Date latestAct = null;
if (groupIdRecords != null && groupIdRecords.getGroupIdRecord() != null && !groupIdRecords.getGroupIdRecord().isEmpty()) {
XMLGregorianCalendar latest = groupIdRecords.getGroupIdRecord().get(0).getLastModifiedDate().getValue();
for (GroupIdRecord groupid : groupIdRecords.getGroupIdRecord()) {
if (latest.compare(groupid.getLastModifiedDate().getValue()) == -1) {
latest = groupid.getLastModifiedDate().getValue();
}
}
latestAct = latest.toGregorianCalendar().getTime();
groupIdRecords.setLastModifiedDate(new LastModifiedDate(latest));
}
return latestAct;
}
use of javax.xml.datatype.XMLGregorianCalendar in project ORCID-Source by ORCID.
the class Api2_0_rc2_LastModifiedDatesHelper method calculateLatest.
public static Date calculateLatest(ResearcherUrls researcherUrls) {
Date latestAct = null;
if (researcherUrls != null && researcherUrls.getResearcherUrls() != null && !researcherUrls.getResearcherUrls().isEmpty()) {
XMLGregorianCalendar latest = researcherUrls.getResearcherUrls().get(0).getLastModifiedDate().getValue();
for (ResearcherUrl researcherUrl : researcherUrls.getResearcherUrls()) {
if (latest.compare(researcherUrl.getLastModifiedDate().getValue()) == -1) {
latest = researcherUrl.getLastModifiedDate().getValue();
}
}
latestAct = latest.toGregorianCalendar().getTime();
researcherUrls.setLastModifiedDate(new LastModifiedDate(latest));
}
return latestAct;
}
Aggregations