use of org.orcid.jaxb.model.record.summary_rc2.Works in project ORCID-Source by ORCID.
the class ConvertV2ToV2_1Test method upgradeWorksToV21Test.
@Test
public void upgradeWorksToV21Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(Works.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(Works.class);
Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
InputStream v20Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-works-2.0.xml");
InputStream v21Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-works-2.1.xml");
Works v20Works = (Works) jaxbUnmarshaller.unmarshal(v20Stream);
jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
Works v21Works1 = (Works) jaxbUnmarshaller.unmarshal(v21Stream);
V2Convertible result = versionConverterV2_0ToV2_1.upgrade(new V2Convertible(v20Works, "v2.1"));
Works v21Works2 = (Works) result.getObjectToConvert();
assertEquals(v21Works1, v21Works2);
}
use of org.orcid.jaxb.model.record.summary_rc2.Works in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewWorks.
@Override
public Response viewWorks(String orcid) {
List<WorkSummary> worksList = workManagerReadOnly.getWorksSummaryList(orcid, getLastModifiedTime(orcid));
// Lets copy the list so we don't modify the cached collection
List<WorkSummary> filteredList = null;
if (worksList != null) {
filteredList = new ArrayList<WorkSummary>(worksList);
}
worksList = filteredList;
orcidSecurityManager.checkAndFilter(orcid, worksList, ScopePathType.ORCID_WORKS_READ_LIMITED);
Works works = workManager.groupWorks(worksList, false);
Api2_0_LastModifiedDatesHelper.calculateLastModified(works);
ActivityUtils.cleanEmptyFields(works);
ActivityUtils.setPathToWorks(works, orcid);
sourceUtils.setSourceName(works);
return Response.ok(works).build();
}
use of org.orcid.jaxb.model.record.summary_rc2.Works in project ORCID-Source by ORCID.
the class SourceUtils method setSourceName.
public void setSourceName(ActivitiesSummary as) {
if (as == null) {
return;
}
if (as.getEducations() != null) {
Educations educations = as.getEducations();
List<EducationSummary> list = educations.getSummaries();
if (list != null) {
for (EducationSummary summary : list) {
setSourceName(summary);
}
}
}
if (as.getEmployments() != null) {
Employments employments = as.getEmployments();
List<EmploymentSummary> list = employments.getSummaries();
if (list != null) {
for (EmploymentSummary summary : list) {
setSourceName(summary);
}
}
}
if (as.getFundings() != null) {
Fundings fundings = as.getFundings();
List<FundingGroup> groups = fundings.getFundingGroup();
if (groups != null) {
for (FundingGroup group : groups) {
List<FundingSummary> summaryList = group.getFundingSummary();
if (summaryList != null) {
for (FundingSummary summary : summaryList) {
setSourceName(summary);
}
}
}
}
}
if (as.getPeerReviews() != null) {
PeerReviews peerReviews = as.getPeerReviews();
List<PeerReviewGroup> groups = peerReviews.getPeerReviewGroup();
if (groups != null) {
for (PeerReviewGroup group : groups) {
List<PeerReviewSummary> summaryList = group.getPeerReviewSummary();
if (summaryList != null) {
for (PeerReviewSummary summary : summaryList) {
setSourceName(summary);
}
}
}
}
}
if (as.getWorks() != null) {
Works works = as.getWorks();
List<WorkGroup> groups = works.getWorkGroup();
if (groups != null) {
for (WorkGroup group : groups) {
List<WorkSummary> summaryList = group.getWorkSummary();
if (summaryList != null) {
for (WorkSummary summary : summaryList) {
setSourceName(summary);
}
}
}
}
}
}
use of org.orcid.jaxb.model.record.summary_rc2.Works in project ORCID-Source by ORCID.
the class WorkManagerTest method testGroupWorksWithDisplayIndex.
@Test
public void testGroupWorksWithDisplayIndex() {
/**
* @formatter:off
* They should be grouped as
*
* Group 1: Work 3
* Group 2: Work 4 + Work 1
* Group 3: Work 5 + Work 2
* Group 4: Work 6
* @formatter:on
*/
WorkSummary s1 = getWorkSummary("Work 1", "ext-id-1", Visibility.PUBLIC, "0");
WorkSummary s2 = getWorkSummary("Work 2", "ext-id-2", Visibility.LIMITED, "1");
WorkSummary s3 = getWorkSummary("Work 3", "ext-id-3", Visibility.PRIVATE, "0");
WorkSummary s4 = getWorkSummary("Work 4", "ext-id-1", Visibility.PRIVATE, "1");
WorkSummary s5 = getWorkSummary("Work 5", "ext-id-2", Visibility.PUBLIC, "2");
WorkSummary s6 = getWorkSummary("Work 6", "ext-id-4", Visibility.PRIVATE, "0");
List<WorkSummary> workList1 = Arrays.asList(s1, s2, s3, s4, s5, s6);
Works works1 = workManager.groupWorks(workList1, false);
assertNotNull(works1);
assertEquals(4, works1.getWorkGroup().size());
// Group 1 have all with ext-id-3
assertEquals(1, works1.getWorkGroup().get(0).getWorkSummary().size());
assertEquals(1, works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-3", works1.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
// Group 2 have all with ext-id-2
assertEquals(2, works1.getWorkGroup().get(1).getWorkSummary().size());
assertEquals(1, works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-1", works1.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
// Group 3 have ext-id-3
assertEquals(2, works1.getWorkGroup().get(2).getWorkSummary().size());
assertEquals(1, works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-2", works1.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
// Group 4 have ext-id-4
assertEquals(1, works1.getWorkGroup().get(3).getWorkSummary().size());
assertEquals(1, works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-4", works1.getWorkGroup().get(3).getIdentifiers().getExternalIdentifier().get(0).getValue());
WorkSummary s7 = getWorkSummary("Work 7", "ext-id-4", Visibility.PRIVATE, "0");
// Add ext-id-3 to work 7, so, it join group 3 and group 4 in a single
// group
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://orcid.org"));
extId.setValue("ext-id-3");
s7.getExternalIdentifiers().getExternalIdentifier().add(extId);
/**
* @formatter:off
* Now, they should be grouped as
*
*
* Group 1: Work 3 + Work 6 + Work 7
* Group 2: Work 4 + Work 1
* Group 3: Work 5 + Work 2
* @formatter:on
*/
List<WorkSummary> workList2 = Arrays.asList(s1, s2, s3, s4, s5, s6, s7);
Works works2 = workManager.groupWorks(workList2, false);
assertNotNull(works2);
assertEquals(3, works2.getWorkGroup().size());
// Group 1 have all with ext-id-3 and ext-id-4
assertEquals(3, works2.getWorkGroup().get(0).getWorkSummary().size());
assertEquals(2, works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertThat(works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
assertThat(works2.getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().get(1).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
// Group 2 have all with ext-id-1
assertEquals(2, works2.getWorkGroup().get(1).getWorkSummary().size());
assertEquals(1, works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-1", works2.getWorkGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
// Group 2 have all with ext-id-2
assertEquals(2, works2.getWorkGroup().get(2).getWorkSummary().size());
assertEquals(1, works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-2", works2.getWorkGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
}
use of org.orcid.jaxb.model.record.summary_rc2.Works 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);
}
Aggregations