use of org.orcid.jaxb.model.v3.dev1.record.WorkTitle 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.v3.dev1.record.WorkTitle in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorkWithBulk_TwoSelf_DupError_CaseSensitive.
@Test
public void testCreateWorkWithBulk_TwoSelf_DupError_CaseSensitive() {
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("doi");
extId1.setUrl(new Url("http://doi.org/10.1/CASE" + time));
extId1.setValue("10.1/CASE");
extIds1.getExternalIdentifier().add(extId1);
work1.setWorkExternalIdentifiers(extIds1);
work1.setWorkType(WorkType.JOURNAL_ARTICLE);
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("doi");
extId2.setUrl(new Url("http://doi.org/10.1/case" + time));
// this should fail as dois are not case sensitive
extId2.setValue("10.1/case");
extIds2.getExternalIdentifier().add(extId2);
work2.setWorkExternalIdentifiers(extIds2);
work2.setWorkType(WorkType.JOURNAL_ARTICLE);
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("10.1/CASE", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
assertEquals("10.1/case", ((Work) updatedBulk.getBulk().get(0)).getExternalIdentifiers().getExternalIdentifier().get(0).getNormalized().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.v3.dev1.record.WorkTitle in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorksWithBulkAllErrors.
@Test
public void testCreateWorksWithBulkAllErrors() {
String orcid = "0000-0000-0000-0003";
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
// Set up data:
// Create one work with a DOI doi-1 so we can create a duplicate
Work work = new Work();
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title("work #1"));
work.setWorkTitle(workTitle);
ExternalIDs extIds = new ExternalIDs();
extIds.getExternalIdentifier().add(getDuplicateExternalId());
work.setWorkExternalIdentifiers(extIds);
work.setWorkType(WorkType.BOOK);
Work newWork = workManager.createWork(orcid, work, true);
Long putCode = newWork.getPutCode();
WorkBulk bulk = new WorkBulk();
// Work # 1: No ext ids
Work work1 = getWork("work # 1 " + System.currentTimeMillis());
work1.getExternalIdentifiers().getExternalIdentifier().clear();
// Work # 2: No title
Work work2 = getWork("work # 2 " + System.currentTimeMillis());
work2.getWorkTitle().getTitle().setContent(null);
// Work # 3: No work type
Work work3 = getWork("work # 3 " + System.currentTimeMillis());
work3.setWorkType(null);
// Work # 4: Ext id already exists
Work work4 = getWork("work # 4 " + System.currentTimeMillis());
work4.getExternalIdentifiers().getExternalIdentifier().add(getDuplicateExternalId());
bulk.getBulk().add(work1);
bulk.getBulk().add(work2);
bulk.getBulk().add(work3);
bulk.getBulk().add(work4);
bulk = workManager.createWorks(orcid, bulk);
assertNotNull(bulk);
assertEquals(4, bulk.getBulk().size());
for (int i = 0; i < bulk.getBulk().size(); i++) {
BulkElement element = bulk.getBulk().get(i);
assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
OrcidError error = (OrcidError) element;
switch(i) {
case 0:
assertEquals(Integer.valueOf(9023), error.getErrorCode());
break;
case 1:
assertEquals(Integer.valueOf(9022), error.getErrorCode());
break;
case 2:
assertEquals(Integer.valueOf(9037), error.getErrorCode());
break;
case 3:
assertEquals(Integer.valueOf(9021), error.getErrorCode());
break;
}
}
// Delete the work
assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
}
use of org.orcid.jaxb.model.v3.dev1.record.WorkTitle in project ORCID-Source by ORCID.
the class BibtexManagerTest method testGenerateBibtexForSingleWorkEsaped.
@Test
public void testGenerateBibtexForSingleWorkEsaped() {
Work w = new Work();
WorkTitle title = new WorkTitle();
title.setTitle(new Title("Escapes θ à À È © ë Ö ì"));
w.setWorkTitle(title);
w.setWorkType(WorkType.JOURNAL_ARTICLE);
w.setPutCode(100l);
String bib = bibtexManager.generateBibtex(ORCID, w);
Assert.assertEquals("@article{Credit_Name100,\ntitle={Escapes \\texttheta {\\`a} \\`{A} \\`{E} \\textcopyright {\\\"e} {\\\"O} {\\`i}},\nauthor={Credit Name}\n}", bib);
}
use of org.orcid.jaxb.model.v3.dev1.record.WorkTitle in project ORCID-Source by ORCID.
the class ContributorUtilsTest method getWorkWithContributorWithoutOrcid.
private Work getWorkWithContributorWithoutOrcid() {
Work work = new Work();
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title("work with contributor without ORCID record"));
work.setWorkTitle(workTitle);
work.setWorkContributors(getWorkContributorWithoutOrcid());
return work;
}
Aggregations