Search in sources :

Example 41 with XMLGregorianCalendar

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;
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LockedException(org.orcid.core.security.aop.LockedException) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) OrcidNotClaimedException(org.orcid.core.exception.OrcidNotClaimedException) NoResultException(javax.persistence.NoResultException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 42 with XMLGregorianCalendar

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Keyword(org.orcid.jaxb.model.record_rc2.Keyword) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Example 43 with XMLGregorianCalendar

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) PersonExternalIdentifier(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifier) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Example 44 with XMLGregorianCalendar

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) GroupIdRecord(org.orcid.jaxb.model.groupid_rc2.GroupIdRecord) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Example 45 with XMLGregorianCalendar

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) ResearcherUrl(org.orcid.jaxb.model.record_rc2.ResearcherUrl) LastModifiedDate(org.orcid.jaxb.model.common_rc2.LastModifiedDate) Date(java.util.Date)

Aggregations

XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)336 Test (org.testng.annotations.Test)159 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)130 Task (com.evolveum.midpoint.task.api.Task)104 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)52 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)44 Date (java.util.Date)36 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)32 ArrayList (java.util.ArrayList)32 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 AbstractSynchronizationStoryTest (com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)23 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 GregorianCalendar (java.util.GregorianCalendar)18 QName (javax.xml.namespace.QName)18 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 Duration (javax.xml.datatype.Duration)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14