Search in sources :

Example 11 with Group

use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.

the class ValidateV2_1SamplesTest method testUnmarshallWorks.

@Test
public void testUnmarshallWorks() throws JAXBException, SAXException, URISyntaxException {
    Works works = (Works) unmarshallFromPath("/record_2.1/samples/read_samples/works-2.1.xml", Works.class, "/record_2.1/activities-2.1.xsd");
    assertNotNull(works);
    assertNotNull(works.getLastModifiedDate());
    assertNotNull(works.getLastModifiedDate().getValue());
    assertEquals(3, works.getWorkGroup().size());
    boolean foundWorkWithNoExtIds = false;
    for (WorkGroup group : works.getWorkGroup()) {
        assertNotNull(group.getLastModifiedDate().getValue());
        assertNotNull(group.getIdentifiers().getExternalIdentifier());
        if (group.getIdentifiers().getExternalIdentifier().isEmpty()) {
            WorkSummary summary = group.getWorkSummary().get(0);
            validateSourceInHttps(summary.getSource());
            assertEquals("1", summary.getDisplayIndex());
            assertEquals(1, summary.getExternalIdentifiers().getExternalIdentifier().size());
            assertEquals("doi", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
            assertEquals("https://doi.org/123456", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl().getValue());
            assertEquals("123456", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
            assertEquals("/8888-8888-8888-8880/work/3356", summary.getPath());
            assertEquals("03", summary.getPublicationDate().getDay().getValue());
            assertEquals("03", summary.getPublicationDate().getMonth().getValue());
            assertEquals("2017", summary.getPublicationDate().getYear().getValue());
            assertEquals("Work # 0", summary.getTitle().getTitle().getContent());
            assertEquals(WorkType.CONFERENCE_PAPER, summary.getType());
            assertEquals(Visibility.PUBLIC, summary.getVisibility());
            foundWorkWithNoExtIds = true;
        } else {
            assertEquals(1, group.getIdentifiers().getExternalIdentifier().size());
            ExternalID extId = group.getIdentifiers().getExternalIdentifier().get(0);
            if (extId.getType().equals("arxiv")) {
                assertEquals(Relationship.SELF, extId.getRelationship());
                assertEquals("http://arxiv.org/abs/123456", extId.getUrl().getValue());
                assertEquals("123456", extId.getValue());
            } else if (extId.getType().equals("bibcode")) {
                assertEquals(Relationship.SELF, extId.getRelationship());
                assertEquals("http://adsabs.harvard.edu/abs/4567", extId.getUrl().getValue());
                assertEquals("4567", extId.getValue());
            } else {
                fail("Invalid ext id type " + extId.getType());
            }
            assertEquals(1, group.getWorkSummary().size());
            WorkSummary summary = group.getWorkSummary().get(0);
            validateSourceInHttps(summary.getSource());
            if (summary.getPutCode().equals(Long.valueOf(3357))) {
                assertEquals("1", summary.getDisplayIndex());
                assertEquals(1, summary.getExternalIdentifiers().getExternalIdentifier().size());
                assertEquals("arxiv", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
                assertEquals("http://arxiv.org/abs/123456", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl().getValue());
                assertEquals("123456", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
                assertEquals("/8888-8888-8888-8880/work/3357", summary.getPath());
                assertEquals("02", summary.getPublicationDate().getDay().getValue());
                assertEquals("02", summary.getPublicationDate().getMonth().getValue());
                assertEquals("2017", summary.getPublicationDate().getYear().getValue());
                assertEquals("Work # 1", summary.getTitle().getTitle().getContent());
                assertEquals(WorkType.CONFERENCE_PAPER, summary.getType());
                assertEquals(Visibility.PUBLIC, summary.getVisibility());
            } else if (summary.getPutCode().equals(Long.valueOf(3358))) {
                assertEquals("1", summary.getDisplayIndex());
                assertEquals(1, summary.getExternalIdentifiers().getExternalIdentifier().size());
                assertEquals("bibcode", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
                assertEquals("http://adsabs.harvard.edu/abs/4567", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl().getValue());
                assertEquals("4567", summary.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
                assertEquals("/8888-8888-8888-8880/work/3358", summary.getPath());
                assertEquals("03", summary.getPublicationDate().getDay().getValue());
                assertEquals("03", summary.getPublicationDate().getMonth().getValue());
                assertEquals("2017", summary.getPublicationDate().getYear().getValue());
                assertEquals("Work # 2", summary.getTitle().getTitle().getContent());
                assertEquals(WorkType.JOURNAL_ARTICLE, summary.getType());
                assertEquals(Visibility.PUBLIC, summary.getVisibility());
            } else {
                fail("Invalid put code " + summary.getPutCode());
            }
        }
    }
    assertTrue(foundWorkWithNoExtIds);
}
Also used : WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Works(org.orcid.jaxb.model.record.summary_v2.Works) Test(org.junit.Test)

Example 12 with Group

use of org.orcid.jaxb.model.record_v2.Group 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.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity)

Example 13 with Group

use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.

the class ActivitiesGroup method merge.

public void merge(ActivitiesGroup group) {
    Set<GroupableActivity> otherActivities = group.getActivities();
    Set<GroupAble> otherKeys = group.getGroupKeys();
    //The incoming groups should always contain at least one key, we should not merge activities without keys
    if (otherKeys.isEmpty())
        throw new IllegalArgumentException("Unable to merge a group without external identifiers");
    //Merge group keys
    for (GroupAble otherKey : otherKeys) {
        if (!groupKeys.contains(otherKey))
            groupKeys.add(otherKey);
    }
    //Merge activities
    for (GroupableActivity activity : otherActivities) {
        //We assume the activity is not already there, anyway it is a set
        activities.add(activity);
    }
}
Also used : GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 14 with Group

use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.

the class Api2_0_LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(Group group) {
    Collection<? extends GroupableActivity> activities = group.getActivities();
    if (activities != null && !activities.isEmpty()) {
        Iterator<? extends GroupableActivity> activitiesIterator = activities.iterator();
        LastModifiedDate latest = null;
        while (activitiesIterator.hasNext()) {
            GroupableActivity activity = activitiesIterator.next();
            if (activity.getLastModifiedDate() != null && activity.getLastModifiedDate().after(latest)) {
                latest = activity.getLastModifiedDate();
            }
        }
        group.setLastModifiedDate(latest);
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity)

Example 15 with Group

use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.

the class Api2_0_LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(GroupsContainer groupsContainerV2) {
    if (groupsContainerV2.retrieveGroups() != null && !groupsContainerV2.retrieveGroups().isEmpty()) {
        List<? extends Group> groupsRc1 = new ArrayList<>(groupsContainerV2.retrieveGroups());
        List<org.orcid.jaxb.model.record_v2.Group> groupsV2 = new ArrayList<>(groupsContainerV2.retrieveGroups());
        if (groupsRc1.get(0).getActivities() != null && !groupsRc1.get(0).getActivities().isEmpty()) {
            LastModifiedDate latest = null;
            for (Group group : groupsV2) {
                calculateLastModified(group);
                if (group.getLastModifiedDate() != null && group.getLastModifiedDate().after(latest)) {
                    latest = group.getLastModifiedDate();
                }
            }
            groupsContainerV2.setLastModifiedDate(latest);
        }
    }
}
Also used : Group(org.orcid.jaxb.model.record_v2.Group) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)24 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)19 ArrayList (java.util.ArrayList)14 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)14 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)13 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)10 Url (org.orcid.jaxb.model.common_v2.Url)9 Group (org.gluu.oxtrust.model.scim2.Group)8 Group (org.openstack4j.model.identity.v3.Group)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)7 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)7 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)7 GroupAble (org.orcid.jaxb.model.record_v2.GroupAble)7 GroupableActivity (org.orcid.jaxb.model.record_v2.GroupableActivity)7 Response (javax.ws.rs.core.Response)6 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)6 Group (com.google.monitoring.v3.Group)5 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)5