Search in sources :

Example 26 with WorkGroup

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

the class WorkManagerReadOnlyImpl method groupWorks.

/**
 * Generate a grouped list of works with the given list of works
 *
 * @param works
 *            The list of works to group
 * @param justPublic
 *            Specify if we want to group only the public elements in the
 *            given list
 * @return Works element with the WorkSummary elements grouped
 */
@Override
public Works groupWorks(List<WorkSummary> works, boolean justPublic) {
    ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
    Works result = new Works();
    // Group all works
    for (WorkSummary work : works) {
        if (justPublic && !work.getVisibility().equals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC)) {
        // If it is just public and the work is not public, just ignore
        // it
        } else {
            groupGenerator.group(work);
        }
    }
    List<ActivitiesGroup> groups = groupGenerator.getGroups();
    for (ActivitiesGroup group : groups) {
        Set<GroupAble> externalIdentifiers = group.getGroupKeys();
        Set<GroupableActivity> activities = group.getActivities();
        WorkGroup workGroup = new WorkGroup();
        // Fill the work groups with the external identifiers
        if (externalIdentifiers == null || externalIdentifiers.isEmpty()) {
            // Initialize the ids as an empty list
            workGroup.getIdentifiers().getExternalIdentifier();
        } else {
            for (GroupAble extId : externalIdentifiers) {
                ExternalID workExtId = (ExternalID) extId;
                workGroup.getIdentifiers().getExternalIdentifier().add(workExtId.clone());
            }
        }
        // Fill the work group with the list of activities
        for (GroupableActivity activity : activities) {
            WorkSummary workSummary = (WorkSummary) activity;
            workGroup.getWorkSummary().add(workSummary);
        }
        // Sort the works
        workGroup.getWorkSummary().sort(WorkComparators.ALL);
        result.getWorkGroup().add(workGroup);
    }
    // Sort the groups!
    result.getWorkGroup().sort(WorkComparators.GROUP);
    return result;
}
Also used : WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity) ActivitiesGroupGenerator(org.orcid.core.utils.v3.activities.ActivitiesGroupGenerator) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) ActivitiesGroup(org.orcid.core.utils.v3.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble)

Example 27 with WorkGroup

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

the class WorksPaginator method getWorksPage.

public WorksPage getWorksPage(String orcid, int offset, boolean justPublic, String sort, boolean sortAsc) {
    Works works = worksCacheManager.getGroupedWorks(orcid);
    List<org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup> filteredGroups = filter(works, justPublic);
    filteredGroups = sort(filteredGroups, sort, sortAsc);
    WorksPage worksPage = new WorksPage();
    worksPage.setTotalGroups(filteredGroups.size());
    List<WorkGroup> workGroups = new ArrayList<>();
    for (int i = offset; i < Math.min(offset + PAGE_SIZE, filteredGroups.size()); i++) {
        org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup group = filteredGroups.get(i);
        workGroups.add(WorkGroup.valueOf(group, i, orcid));
    }
    worksPage.setWorkGroups(workGroups);
    worksPage.setNextOffset(offset + PAGE_SIZE);
    return worksPage;
}
Also used : ArrayList(java.util.ArrayList) WorkGroup(org.orcid.pojo.WorkGroup) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works)

Example 28 with WorkGroup

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

the class WorksPaginator method getAllWorks.

public WorksPage getAllWorks(String orcid, String sort, boolean sortAsc) {
    Works works = worksCacheManager.getGroupedWorks(orcid);
    List<org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup> sortedGroups = sort(works.getWorkGroup(), sort, sortAsc);
    WorksPage worksPage = new WorksPage();
    worksPage.setTotalGroups(sortedGroups.size());
    List<WorkGroup> workGroups = new ArrayList<>();
    for (int i = 0; i < sortedGroups.size(); i++) {
        org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup group = sortedGroups.get(i);
        workGroups.add(WorkGroup.valueOf(group, i, orcid));
    }
    worksPage.setWorkGroups(workGroups);
    worksPage.setNextOffset(sortedGroups.size());
    return worksPage;
}
Also used : ArrayList(java.util.ArrayList) WorkGroup(org.orcid.pojo.WorkGroup) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works)

Example 29 with WorkGroup

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

the class WorkManagerTest method nonGroupableIdsGenerateEmptyIdsListTest.

@Test
public void nonGroupableIdsGenerateEmptyIdsListTest() {
    WorkSummary s1 = getWorkSummary("Element 1", "ext-id-1", Visibility.PUBLIC);
    WorkSummary s2 = getWorkSummary("Element 2", "ext-id-2", Visibility.LIMITED);
    WorkSummary s3 = getWorkSummary("Element 3", "ext-id-3", Visibility.PRIVATE);
    // s1 will be a part of identifier, so, it will go in its own group
    s1.getExternalIdentifiers().getExternalIdentifier().get(0).setRelationship(Relationship.PART_OF);
    List<WorkSummary> workList = Arrays.asList(s1, s2, s3);
    /**
     * They should be grouped as
     *
     * Group 1: Element 1
     * Group 2: Element 2
     * Group 3: Element 3
     */
    Works works = workManager.groupWorks(workList, false);
    assertNotNull(works);
    assertEquals(3, works.getWorkGroup().size());
    boolean foundEmptyGroup = false;
    boolean found2 = false;
    boolean found3 = false;
    for (WorkGroup group : works.getWorkGroup()) {
        assertEquals(1, group.getWorkSummary().size());
        assertNotNull(group.getIdentifiers().getExternalIdentifier());
        if (group.getIdentifiers().getExternalIdentifier().isEmpty()) {
            assertEquals("Element 1", group.getWorkSummary().get(0).getTitle().getTitle().getContent());
            assertEquals("ext-id-1", group.getWorkSummary().get(0).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
            foundEmptyGroup = true;
        } else {
            assertEquals(1, group.getIdentifiers().getExternalIdentifier().size());
            assertThat(group.getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-2"), is("ext-id-3")));
            if (group.getIdentifiers().getExternalIdentifier().get(0).getValue().equals("ext-id-2")) {
                assertEquals("Element 2", group.getWorkSummary().get(0).getTitle().getTitle().getContent());
                assertEquals("ext-id-2", group.getWorkSummary().get(0).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
                found2 = true;
            } else if (group.getIdentifiers().getExternalIdentifier().get(0).getValue().equals("ext-id-3")) {
                assertEquals("Element 3", group.getWorkSummary().get(0).getTitle().getTitle().getContent());
                assertEquals("ext-id-3", group.getWorkSummary().get(0).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
                found3 = true;
            } else {
                fail("Invalid ext id found " + group.getIdentifiers().getExternalIdentifier().get(0).getValue());
            }
        }
    }
    assertTrue(foundEmptyGroup);
    assertTrue(found2);
    assertTrue(found3);
}
Also used : WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 30 with WorkGroup

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

the class ActivityUtilsTest method cleanEmptyActivitiesSummaryTest.

@Test
public void cleanEmptyActivitiesSummaryTest() {
    // Test it cleans empty fields
    WorkSummary s = getEmptyWorkSummary();
    ActivitiesSummary x = new ActivitiesSummary();
    Works w = new Works();
    WorkGroup g = new WorkGroup();
    g.getWorkSummary().add(s);
    w.getWorkGroup().add(g);
    x.setWorks(w);
    assertNotNull(x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle());
    ActivityUtils.cleanEmptyFields(x);
    assertNull(x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle());
    // Test it doesn't remove non empty fields
    s = getEmptyWorkSummary();
    s.getTitle().getTranslatedTitle().setContent("test");
    s.getTitle().getTranslatedTitle().setLanguageCode("en_us");
    x = new ActivitiesSummary();
    w = new Works();
    g = new WorkGroup();
    g.getWorkSummary().add(s);
    w.getWorkGroup().add(g);
    x.setWorks(w);
    assertEquals("test", x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getLanguageCode());
    ActivityUtils.cleanEmptyFields(x);
    assertEquals("test", x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", x.getWorks().getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getLanguageCode());
}
Also used : WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) Test(org.junit.Test)

Aggregations

WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)28 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)28 Test (org.junit.Test)17 Works (org.orcid.jaxb.model.v3.dev1.record.summary.Works)17 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)10 FundingGroup (org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup)9 PeerReviewGroup (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup)9 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)8 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)8 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)8 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)8 ArrayList (java.util.ArrayList)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 DBUnitTest (org.orcid.test.DBUnitTest)6 ClientResponse (com.sun.jersey.api.client.ClientResponse)5 Response (javax.ws.rs.core.Response)5 Work (org.orcid.jaxb.model.v3.dev1.record.Work)5 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)4 Title (org.orcid.jaxb.model.v3.dev1.common.Title)4 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)4