use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class WorkManagerTest method testFindWorkBulk.
@Test
public void testFindWorkBulk() {
String putCodes = "11,12,13";
WorkBulk workBulk = workManager.findWorkBulk("0000-0000-0000-0003", putCodes);
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(3, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
assertTrue(workBulk.getBulk().get(2) instanceof Work);
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorkWithBulk_TwoSelf_DupError.
@Test
public void testCreateWorkWithBulk_TwoSelf_DupError() {
String orcid = "0000-0000-0000-0003";
Long time = System.currentTimeMillis();
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
WorkBulk bulk = new WorkBulk();
// Work # 1
Work work1 = new Work();
WorkTitle title1 = new WorkTitle();
title1.setTitle(new Title("Work # 1"));
work1.setWorkTitle(title1);
ExternalIDs extIds1 = new ExternalIDs();
ExternalID extId1 = new ExternalID();
extId1.setRelationship(Relationship.SELF);
extId1.setType("isbn");
extId1.setUrl(new Url("http://isbn/1/" + time));
extId1.setValue("isbn-1");
extIds1.getExternalIdentifier().add(extId1);
work1.setWorkExternalIdentifiers(extIds1);
work1.setWorkType(WorkType.BOOK);
bulk.getBulk().add(work1);
// Work # 2
Work work2 = new Work();
WorkTitle title2 = new WorkTitle();
title2.setTitle(new Title("Work # 2"));
work2.setWorkTitle(title2);
ExternalIDs extIds2 = new ExternalIDs();
ExternalID extId2 = new ExternalID();
extId2.setRelationship(Relationship.SELF);
extId2.setType("isbn");
extId2.setUrl(new Url("http://isbn/1/" + time));
extId2.setValue("isbn-1");
extIds2.getExternalIdentifier().add(extId2);
work2.setWorkExternalIdentifiers(extIds2);
work2.setWorkType(WorkType.BOOK);
bulk.getBulk().add(work2);
WorkBulk updatedBulk = workManager.createWorks(orcid, bulk);
assertNotNull(updatedBulk);
assertEquals(2, updatedBulk.getBulk().size());
assertTrue(updatedBulk.getBulk().get(0) instanceof Work);
assertNotNull(((Work) updatedBulk.getBulk().get(0)).getPutCode());
assertEquals(Relationship.SELF, ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
assertEquals("isbn-1", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
assertTrue(updatedBulk.getBulk().get(1) instanceof OrcidError);
assertEquals(Integer.valueOf(9021), ((OrcidError) updatedBulk.getBulk().get(1)).getErrorCode());
assertEquals("409 Conflict: You have already added this activity (matched by external identifiers.) If you are trying to edit the item, please use PUT instead of POST.", ((OrcidError) updatedBulk.getBulk().get(1)).getDeveloperMessage());
workManager.removeWorks(orcid, Arrays.asList(((Work) updatedBulk.getBulk().get(0)).getPutCode()));
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorksWithBulkAllOK.
@Test
public void testCreateWorksWithBulkAllOK() {
String orcid = "0000-0000-0000-0003";
Long time = System.currentTimeMillis();
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
WorkBulk bulk = new WorkBulk();
for (int i = 0; i < 5; i++) {
Work work = new Work();
WorkTitle title = new WorkTitle();
title.setTitle(new Title("Bulk work " + i + " " + time));
work.setWorkTitle(title);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://doi/" + i + "/" + time));
extId.setValue("doi-" + i + "-" + time);
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
work.setWorkType(WorkType.BOOK);
bulk.getBulk().add(work);
}
bulk = workManager.createWorks(orcid, bulk);
assertNotNull(bulk);
assertEquals(5, bulk.getBulk().size());
for (int i = 0; i < 5; i++) {
assertTrue(Work.class.isAssignableFrom(bulk.getBulk().get(i).getClass()));
Work w = (Work) bulk.getBulk().get(i);
assertNotNull(w.getPutCode());
assertTrue(0L < w.getPutCode());
assertEquals("Bulk work " + i + " " + time, w.getWorkTitle().getTitle().getContent());
assertNotNull(w.getExternalIdentifiers().getExternalIdentifier());
assertEquals("doi-" + i + "-" + time, w.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
Work w1 = workManager.getWork(orcid, w.getPutCode());
assertNotNull(w1);
assertEquals("Bulk work " + i + " " + time, w1.getWorkTitle().getTitle().getContent());
// Delete the work
assertTrue(workManager.checkSourceAndRemoveWork(orcid, w1.getPutCode()));
}
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorksWithBulkSomeOKSomeErrors.
@Test
public void testCreateWorksWithBulkSomeOKSomeErrors() {
String orcid = "0000-0000-0000-0003";
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
// Lets send a bulk of 6 works
WorkBulk bulk = new WorkBulk();
// Work # 1 - Fine
Work work1 = getWork(null);
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://doi/1"));
extId.setValue("doi-1");
work1.getExternalIdentifiers().getExternalIdentifier().clear();
work1.getExternalIdentifiers().getExternalIdentifier().add(extId);
work1.getWorkTitle().getTitle().setContent("Work # 1");
bulk.getBulk().add(work1);
// Work # 2 - Fine
Work work2 = getWork(null);
work2.getWorkTitle().getTitle().setContent("Work # 2");
bulk.getBulk().add(work2);
// Work # 3 - Duplicated of Work # 1
Work work3 = getWork(null);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
work3.getExternalIdentifiers().getExternalIdentifier().add(extId);
work3.getWorkTitle().getTitle().setContent("Work # 3");
bulk.getBulk().add(work3);
// Work # 4 - Fine
Work work4 = getWork("new-ext-id-" + System.currentTimeMillis());
work4.getWorkTitle().getTitle().setContent("Work # 4");
bulk.getBulk().add(work4);
// Work # 5 - Duplicated of existing work
Work work5 = getWork(null);
ExternalID dupExtId = new ExternalID();
dupExtId.setRelationship(Relationship.SELF);
dupExtId.setType("doi");
dupExtId.setValue("1");
work5.getExternalIdentifiers().getExternalIdentifier().clear();
work5.getExternalIdentifiers().getExternalIdentifier().add(dupExtId);
work5.getWorkTitle().getTitle().setContent("Work # 5");
bulk.getBulk().add(work5);
// Work # 6 - No title specified
Work work6 = getWork(null);
work6.getWorkTitle().getTitle().setContent(null);
bulk.getBulk().add(work6);
bulk = workManager.createWorks(orcid, bulk);
assertNotNull(bulk);
assertEquals(6, bulk.getBulk().size());
List<Long> worksToDelete = new ArrayList<Long>();
for (int i = 0; i < bulk.getBulk().size(); i++) {
BulkElement element = bulk.getBulk().get(i);
switch(i) {
case 0:
case 1:
case 3:
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
assertNotNull(work);
assertNotNull(work.getPutCode());
if (i == 0) {
assertEquals("Work # 1", work.getWorkTitle().getTitle().getContent());
} else if (i == 1) {
assertEquals("Work # 2", work.getWorkTitle().getTitle().getContent());
} else {
assertEquals("Work # 4", work.getWorkTitle().getTitle().getContent());
}
worksToDelete.add(work.getPutCode());
break;
case 2:
case 4:
case 5:
assertTrue("Error on id: " + i, OrcidError.class.isAssignableFrom(element.getClass()));
OrcidError error = (OrcidError) element;
if (i == 2) {
assertEquals(Integer.valueOf(9021), error.getErrorCode());
} else if (i == 4) {
assertEquals(Integer.valueOf(9021), error.getErrorCode());
} else {
assertEquals(Integer.valueOf(9022), error.getErrorCode());
}
break;
}
}
// Delete new works
for (Long putCode : worksToDelete) {
assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
}
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest method testWork.
/**
* <common:external-ids>
* <common:external-id>
* <common:external-id-type>agr</common:external-id-type>
* <common:external-id-value>work:external-identifier-id</common:external-id-value>
* <common:external-id-url>http://orcid.org</common:external-id-url>
* <common:external-id-relationship>self</common:external-id-relationship>
* </common:external-id>
* </common:external-ids>
*
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testWork() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Work work = unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
ExternalID id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("agr", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
Validator validator = getValidator("work");
validator.validate(marshall(Work.class, work));
validator.validate(marshallToDOM(Work.class, work));
work = unmarshallFromPath("/record_2.0/samples/read_samples/work-full-2.0.xml", Work.class);
id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("agr", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
validator.validate(marshall(Work.class, work));
validator.validate(marshallToDOM(Work.class, work));
}
Aggregations