Search in sources :

Example 71 with Works

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

the class PublicV3ApiServiceDelegatorImpl method viewWorks.

@Override
public Response viewWorks(String orcid) {
    List<WorkSummary> works = workManagerReadOnly.getWorksSummaryList(orcid);
    Works publicWorks = workManagerReadOnly.groupWorks(works, true);
    publicAPISecurityManagerV3.filter(publicWorks);
    ActivityUtils.cleanEmptyFields(publicWorks);
    ActivityUtils.setPathToWorks(publicWorks, orcid);
    Api3_0_Dev1LastModifiedDatesHelper.calculateLastModified(publicWorks);
    sourceUtilsReadOnly.setSourceName(publicWorks);
    return Response.ok(publicWorks).build();
}
Also used : WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works)

Example 72 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works 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 73 with Works

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

the class ActivitiesGroupGenerator_GroupingWorksTest method groupWorks_DontGroupWorksWithoutExtIds_Test.

/**
 * Test that two groups without ext ids dont get grouped
 */
@Test
public void groupWorks_DontGroupWorksWithoutExtIds_Test() {
    ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
    Map<String, WorkSummary> works = generateWorks();
    // Group the first group
    WorkSummary work8 = works.get("work-8");
    WorkSummary work9 = works.get("work-9");
    generator.group(work8);
    generator.group(work9);
    List<ActivitiesGroup> groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    // Check there are two activities in each group
    assertEquals(1, groups.get(0).getActivities().size());
    assertEquals(1, groups.get(1).getActivities().size());
    // Check there are five external ids in each group
    assertEquals(0, groups.get(0).getGroupKeys().size());
    assertEquals(0, groups.get(1).getGroupKeys().size());
    checkActivityIsOnGroups(work8, groups);
    checkActivityIsOnGroups(work9, groups);
    checkActivitiesDontBelongsToTheSameGroup(groups, work8, work9);
}
Also used : WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) Test(org.junit.Test)

Example 74 with Works

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

the class ActivitiesGroupGenerator_GroupingWorksTest method groupWorks_4GroupsOf1Work_Test.

@Test
public void groupWorks_4GroupsOf1Work_Test() {
    ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
    Map<String, WorkSummary> works = generateWorks();
    // Group the first group
    // work-1 -> ARG(A), ARG(B), ARG(C)
    WorkSummary work1 = works.get("work-1");
    generator.group(work1);
    // There should be one group, and the ext ids should be A, B and C
    List<ActivitiesGroup> groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(1, groups.size());
    ActivitiesGroup g1 = groups.get(0);
    assertNotNull(g1);
    assertNotNull(g1.getActivities());
    assertEquals(1, g1.getActivities().size());
    assertTrue(g1.getActivities().contains(work1));
    assertNotNull(g1.getGroupKeys());
    assertEquals(3, g1.getGroupKeys().size());
    checkExternalIdentifiers(work1, g1);
    // Add another work to the groups
    // work-5 -> ARG(M), ARG(N), ARG(O)
    WorkSummary work5 = works.get("work-5");
    generator.group(work5);
    // There should be two groups, one for each work
    groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    // There should be one activity in each group
    assertEquals(1, groups.get(0).getActivities().size());
    assertEquals(1, groups.get(1).getActivities().size());
    // There should be 3 ext ids in each group
    assertEquals(3, groups.get(0).getGroupKeys().size());
    assertEquals(3, groups.get(1).getGroupKeys().size());
    // Check work in groups
    checkActivityIsOnGroups(work5, groups);
    // Add another work to the groups
    // work-6 -> ARXIV(A), ARXIV(B), ARXIV(C)
    WorkSummary work6 = works.get("work-6");
    generator.group(work6);
    groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(3, groups.size());
    // There should be one activity in each group
    assertEquals(1, groups.get(0).getActivities().size());
    assertEquals(1, groups.get(1).getActivities().size());
    assertEquals(1, groups.get(2).getActivities().size());
    // There should be 3 ext ids in each group
    assertEquals(3, groups.get(0).getGroupKeys().size());
    assertEquals(3, groups.get(1).getGroupKeys().size());
    assertEquals(3, groups.get(2).getGroupKeys().size());
    // Check work in groups
    checkActivityIsOnGroups(work6, groups);
    // Add another work to the groups
    // work-8 -> No external identifiers
    WorkSummary work8 = works.get("work-8");
    generator.group(work8);
    groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(4, groups.size());
    // There should be one activity in each group
    assertEquals(1, groups.get(0).getActivities().size());
    assertEquals(1, groups.get(1).getActivities().size());
    assertEquals(1, groups.get(2).getActivities().size());
    assertEquals(1, groups.get(3).getActivities().size());
    // There should be 3 ext ids in each group, except for one group that doesnt have any ext id
    boolean work8found = false;
    for (int i = 0; i < 4; i++) {
        if (groups.get(i).getGroupKeys().size() == 0) {
            work8found = true;
        } else {
            assertEquals(3, groups.get(i).getGroupKeys().size());
        }
    }
    assertTrue("Work without ext ids was not found", work8found);
    // Check work in groups
    checkActivityIsOnGroups(work8, groups);
}
Also used : WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) Test(org.junit.Test)

Example 75 with Works

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

the class ActivitiesGroupGenerator_GroupingWorksTest method groupWorks_MergeTwoGroups_Test.

/**
 * work-1 and work-3 will be in different groups
 * then work-2 will go to the same group as work-1
 * then work-4 contains ARG(Y) and ARG(B) so, the two groups should be merged
 */
@Test
public void groupWorks_MergeTwoGroups_Test() {
    ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
    Map<String, WorkSummary> works = generateWorks();
    // Group the first group
    WorkSummary work1 = works.get("work-1");
    WorkSummary work2 = works.get("work-2");
    WorkSummary work3 = works.get("work-3");
    WorkSummary work4 = works.get("work-4");
    generator.group(work1);
    generator.group(work2);
    generator.group(work3);
    /**
     * At this point there are two groups
     * G1 with work1 and work2
     * G2 with work3
     */
    List<ActivitiesGroup> groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    checkActivitiesBelongsToTheSameGroup(groups, work1, work2);
    checkActivitiesDontBelongsToTheSameGroup(groups, work1, work3);
    checkActivitiesDontBelongsToTheSameGroup(groups, work2, work3);
    // group work4, which should merge the two groups
    generator.group(work4);
    groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(1, groups.size());
    assertEquals(4, groups.get(0).getActivities().size());
    assertEquals(9, groups.get(0).getGroupKeys().size());
    checkActivityIsOnGroups(work1, groups);
    checkActivityIsOnGroups(work2, groups);
    checkActivityIsOnGroups(work3, groups);
    checkActivityIsOnGroups(work4, groups);
    checkActivitiesBelongsToTheSameGroup(groups, work1, work2, work3, work4);
}
Also used : WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)83 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)65 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)46 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)38 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)37 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)37 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)37 Works (org.orcid.jaxb.model.v3.dev1.record.summary.Works)37 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)35 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)35 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)35 QualificationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary)35 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)35 DBUnitTest (org.orcid.test.DBUnitTest)21 Response (javax.ws.rs.core.Response)20 WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)20 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)17 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)17 Address (org.orcid.jaxb.model.v3.dev1.record.Address)16 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)16