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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations