Search in sources :

Example 56 with ExternalID

use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.

the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOff.

@Test
public void testValidExtIdsWorksFine_flagOff() {
    ExternalIDs extIds = new ExternalIDs();
    ExternalID id1 = new ExternalID();
    id1.setRelationship(null);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    ExternalID id2 = new ExternalID();
    id2.setRelationship(null);
    id2.setType("doi");
    id2.setValue("value1");
    id2.setUrl(new Url("http://value1.com"));
    ExternalID id3 = new ExternalID();
    id3.setRelationship(null);
    id3.setType("doi");
    id3.setValue("value1");
    id3.setUrl(new Url("http://value1.com"));
    extIds.getExternalIdentifier().add(id1);
    extIds.getExternalIdentifier().add(id2);
    extIds.getExternalIdentifier().add(id3);
    validator.validateWorkOrPeerReview(extIds);
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test)

Example 57 with ExternalID

use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.

the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOn.

@Test
public void testValidExtIdsWorksFine_flagOn() {
    validator.setRequireRelationshipOnExternalIdentifier(true);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    ExternalID id2 = new ExternalID();
    id2.setRelationship(Relationship.SELF);
    id2.setType("doi");
    id2.setValue("value1");
    id2.setUrl(new Url("http://value1.com"));
    ExternalID id3 = new ExternalID();
    id3.setRelationship(Relationship.SELF);
    id3.setType("doi");
    id3.setValue("value1");
    id3.setUrl(new Url("http://value1.com"));
    extIds.getExternalIdentifier().add(id1);
    extIds.getExternalIdentifier().add(id2);
    extIds.getExternalIdentifier().add(id3);
    validator.validateWorkOrPeerReview(extIds);
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Test(org.junit.Test)

Example 58 with ExternalID

use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.

the class ExternalIDValidatorTest method testValidateWorkOrPeerReview.

@Test
public void testValidateWorkOrPeerReview() {
    // call for ExternalID and ExternalIDs
    // ID valid
    ExternalID id1 = new ExternalID();
    id1.setRelationship(Relationship.SELF);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    validator.validateWorkOrPeerReview(id1);
    // ID bad type
    try {
        id1.setType("invalid");
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    // id null
    try {
        id1.setType(null);
        validator.validateWorkOrPeerReview(id1);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    ExternalIDs ids = new ExternalIDs();
    ids.getExternalIdentifier().add(id1);
    // IDS one invalid
    id1.setType("invalid");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
    // IDS one valid (lowercase)
    id1.setType("doi");
    validator.validateWorkOrPeerReview(ids);
    // IDS two valid
    ExternalID id2 = new ExternalID();
    id2.setRelationship(Relationship.SELF);
    id2.setType("source-work-id");
    id2.setValue("value2");
    id2.setUrl(new Url("http://value1.com"));
    ids.getExternalIdentifier().add(id2);
    validator.validateWorkOrPeerReview(ids);
    // IDS one invalid, one valid
    id2.setType("not-a-type");
    try {
        validator.validateWorkOrPeerReview(ids);
        fail("no exception thrown for invalid type");
    } catch (Exception e) {
        if (!(e instanceof ActivityIdentifierValidationException))
            throw e;
    }
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Url(org.orcid.jaxb.model.v3.dev1.common.Url) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Test(org.junit.Test)

Example 59 with ExternalID

use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.

the class OrcidSecurityManagerImpl method filterExternalIdentifiers.

/**
 * Filter the group external identifiers to match the external identifiers
 * that belongs to the activities it have after filtering
 *
 * @param group
 *            The group we want to filter the external identifiers
 */
private void filterExternalIdentifiers(Group group) {
    // Iterate over every external identifier and check if it is still
    // present in the list of filtered elements
    ExternalIDs extIds = group.getIdentifiers();
    Iterator<ExternalID> extIdsIt = extIds.getExternalIdentifier().iterator();
    while (extIdsIt.hasNext()) {
        ExternalID extId = extIdsIt.next();
        boolean found = false;
        for (GroupableActivity summary : group.getActivities()) {
            if (summary.getExternalIdentifiers() != null) {
                if (summary.getExternalIdentifiers().getExternalIdentifier().contains(extId)) {
                    found = true;
                    break;
                }
            }
        }
        // If the ext id is not found, remove it from the list of ext ids
        if (!found) {
            extIdsIt.remove();
        }
    }
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)

Example 60 with ExternalID

use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerImpl method createNewWorkGroup.

@Override
public void createNewWorkGroup(List<Long> workIds, String orcid) {
    List<MinimizedWorkEntity> works = workEntityCacheManager.retrieveMinimizedWorks(orcid, workIds, getLastModified(orcid));
    JSONWorkExternalIdentifiersConverterV3 externalIdConverter = new JSONWorkExternalIdentifiersConverterV3(norm, localeManager);
    ExternalIDs allExternalIDs = new ExternalIDs();
    MinimizedWorkEntity userVersion = null;
    MinimizedWorkEntity userPreferred = null;
    for (MinimizedWorkEntity work : works) {
        if (orcid.equals(work.getSourceId())) {
            userVersion = work;
        }
        if (userPreferred == null || userPreferred.getDisplayIndex() < work.getDisplayIndex()) {
            userPreferred = work;
        }
        ExternalIDs externalIDs = externalIdConverter.convertFrom(work.getExternalIdentifiersJson(), null);
        for (ExternalID externalID : externalIDs.getExternalIdentifier()) {
            if (!allExternalIDs.getExternalIdentifier().contains(externalID)) {
                allExternalIDs.getExternalIdentifier().add(externalID);
            }
        }
    }
    String externalIDsJson = externalIdConverter.convertTo(allExternalIDs, null);
    if (userVersion != null) {
        userVersion.setExternalIdentifiersJson(externalIDsJson);
    } else {
        WorkEntity allPreferredMetadata = createCopyOfUserPreferredWork(userPreferred);
        allPreferredMetadata.setExternalIdentifiersJson(externalIDsJson);
        workDao.persist(allPreferredMetadata);
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) JSONWorkExternalIdentifiersConverterV3(org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV3) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)

Aggregations

ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)120 Test (org.junit.Test)73 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)66 Url (org.orcid.jaxb.model.v3.dev1.common.Url)64 Title (org.orcid.jaxb.model.v3.dev1.common.Title)25 Work (org.orcid.jaxb.model.v3.dev1.record.Work)23 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)22 Response (javax.ws.rs.core.Response)20 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)20 DBUnitTest (org.orcid.test.DBUnitTest)20 List (java.util.List)16 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)14 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)13 ClientResponse (com.sun.jersey.api.client.ClientResponse)12 BaseTest (org.orcid.core.BaseTest)9 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)9 ArrayList (java.util.ArrayList)8 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)8 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)8 JSONUrl (org.orcid.core.adapter.jsonidentifier.JSONUrl)7