use of org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ActivitiesSummaryTest method testCleanEmptyFieldsOnActivities.
@Test
public void testCleanEmptyFieldsOnActivities() {
LastModifiedDate lmd = new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(System.currentTimeMillis()));
Works works = new Works();
works.setLastModifiedDate(lmd);
WorkGroup group = new WorkGroup();
group.setLastModifiedDate(lmd);
for (int i = 0; i < 5; i++) {
WorkSummary summary = new WorkSummary();
summary.setLastModifiedDate(lmd);
WorkTitle title = new WorkTitle();
title.setTitle(new Title("Work " + i));
title.setTranslatedTitle(new TranslatedTitle("", ""));
summary.setTitle(title);
group.getWorkSummary().add(summary);
}
works.getWorkGroup().add(group);
ActivitiesSummary as = new ActivitiesSummary();
as.setWorks(works);
ActivityUtils.cleanEmptyFields(as);
assertNotNull(as);
assertNotNull(as.getWorks());
Utils.verifyLastModified(as.getWorks().getLastModifiedDate());
assertNotNull(as.getWorks().getWorkGroup());
assertEquals(1, as.getWorks().getWorkGroup().size());
assertNotNull(as.getWorks().getWorkGroup().get(0).getWorkSummary());
Utils.verifyLastModified(as.getWorks().getWorkGroup().get(0).getLastModifiedDate());
assertEquals(5, as.getWorks().getWorkGroup().get(0).getWorkSummary().size());
for (WorkSummary summary : as.getWorks().getWorkGroup().get(0).getWorkSummary()) {
Utils.verifyLastModified(summary.getLastModifiedDate());
assertNotNull(summary.getTitle());
assertNotNull(summary.getTitle().getTitle());
assertTrue(summary.getTitle().getTitle().getContent().startsWith("Work "));
assertNull(summary.getTitle().getTranslatedTitle());
}
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ActivitiesSummaryTest method testActivities.
private void testActivities(ActivitiesSummary as, String orcid) {
boolean found1 = false, found2 = false, found3 = false;
// This is more an utility that will work only for 0000-0000-0000-0003
assertEquals("0000-0000-0000-0003", orcid);
assertNotNull(as);
assertNotNull(as.getPath());
assertEquals("/0000-0000-0000-0003/activities", as.getPath());
Utils.verifyLastModified(as.getLastModifiedDate());
assertNotNull(as.getEducations());
assertEquals(3, as.getEducations().getSummaries().size());
for (EducationSummary element : as.getEducations().getSummaries()) {
if (element.getPutCode().equals(Long.valueOf(20))) {
found1 = true;
} else if (element.getPutCode().equals(Long.valueOf(21))) {
found2 = true;
} else if (element.getPutCode().equals(Long.valueOf(22))) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
found1 = found2 = found3 = false;
assertNotNull(as.getEmployments());
assertEquals(3, as.getEmployments().getSummaries().size());
for (EmploymentSummary element : as.getEmployments().getSummaries()) {
if (element.getPutCode().equals(Long.valueOf(17))) {
found1 = true;
} else if (element.getPutCode().equals(Long.valueOf(18))) {
found2 = true;
} else if (element.getPutCode().equals(Long.valueOf(19))) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
found1 = found2 = found3 = false;
assertNotNull(as.getFundings());
assertEquals(3, as.getFundings().getFundingGroup().size());
for (FundingGroup group : as.getFundings().getFundingGroup()) {
assertEquals(1, group.getFundingSummary().size());
FundingSummary element = group.getFundingSummary().get(0);
if (element.getPutCode().equals(Long.valueOf(10))) {
found1 = true;
} else if (element.getPutCode().equals(Long.valueOf(11))) {
found2 = true;
} else if (element.getPutCode().equals(Long.valueOf(12))) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
found1 = found2 = found3 = false;
assertNotNull(as.getPeerReviews());
assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
for (PeerReviewGroup group : as.getPeerReviews().getPeerReviewGroup()) {
assertEquals(1, group.getPeerReviewSummary().size());
PeerReviewSummary element = group.getPeerReviewSummary().get(0);
if (element.getPutCode().equals(Long.valueOf(9))) {
found1 = true;
} else if (element.getPutCode().equals(Long.valueOf(10))) {
found2 = true;
} else if (element.getPutCode().equals(Long.valueOf(11))) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
found1 = found2 = found3 = false;
assertNotNull(as.getWorks());
assertEquals(3, as.getWorks().getWorkGroup().size());
for (WorkGroup group : as.getWorks().getWorkGroup()) {
assertEquals(1, group.getWorkSummary().size());
WorkSummary element = group.getWorkSummary().get(0);
if (element.getPutCode().equals(Long.valueOf(11))) {
found1 = true;
} else if (element.getPutCode().equals(Long.valueOf(12))) {
found2 = true;
} else if (element.getPutCode().equals(Long.valueOf(13))) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
found1 = found2 = found3 = false;
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary in project ORCID-Source by ORCID.
the class PublicV3ApiServiceDelegatorTest method testViewWorks.
@Test
public void testViewWorks() {
Response response = serviceDelegator.viewWorks(ORCID);
assertNotNull(response);
Works works = (Works) response.getEntity();
assertNotNull(works);
assertEquals("/0000-0000-0000-0003/works", works.getPath());
assertNotNull(works.getLastModifiedDate());
assertNotNull(works.getLastModifiedDate().getValue());
assertEquals(1, works.getWorkGroup().size());
assertEquals(1, works.getWorkGroup().get(0).getWorkSummary().size());
WorkSummary work = works.getWorkGroup().get(0).getWorkSummary().get(0);
assertEquals(Long.valueOf(11), work.getPutCode());
assertNotNull(work.getLastModifiedDate());
assertNotNull(work.getLastModifiedDate().getValue());
assertEquals("/0000-0000-0000-0003/work/11", work.getPath());
assertEquals(WorkType.JOURNAL_ARTICLE, work.getType());
assertEquals("APP-5555555555555555", work.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary 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();
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary 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;
}
Aggregations