use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.
the class WorkManagerImpl method createWorks.
/**
* Add a list of works to the given profile
*
* @param works
* The list of works that want to be added
* @param orcid
* The id of the user we want to add the works to
*
* @return the work bulk with the put codes of the new works or the error
* that indicates why a work can't be added
*/
@Override
@Transactional
public WorkBulk createWorks(String orcid, WorkBulk workBulk) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
List<Work> existingWorks = this.findWorks(orcid);
if (workBulk.getBulk() != null && !workBulk.getBulk().isEmpty()) {
List<BulkElement> bulk = workBulk.getBulk();
Set<ExternalID> existingExternalIdentifiers = buildExistingExternalIdsSet(existingWorks, sourceEntity.getSourceId());
if ((existingWorks.size() + bulk.size()) > this.maxNumOfActivities) {
throw new ExceedMaxNumberOfElementsException();
}
// Check bulk size
if (bulk.size() > maxBulkSize) {
Locale locale = localeManager.getLocale();
throw new IllegalArgumentException(messageSource.getMessage("apiError.validation_too_many_elements_in_bulk.exception", new Object[] { maxBulkSize }, locale));
}
for (int i = 0; i < bulk.size(); i++) {
if (Work.class.isAssignableFrom(bulk.get(i).getClass())) {
Work work = (Work) bulk.get(i);
try {
activityValidator.validateWork(work, sourceEntity, true, true, null);
// Validate it is not duplicated
if (work.getExternalIdentifiers() != null) {
for (ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) {
// normalise the provided ID
extId.setNormalized(new TransientNonEmptyString(norm.normalise(extId.getType(), extId.getValue())));
// If the external id exists and is a SELF identifier, then mark it as duplicated
if (existingExternalIdentifiers.contains(extId) && Relationship.SELF.equals(extId.getRelationship())) {
Map<String, String> params = new HashMap<String, String>();
params.put("clientName", sourceEntity.getSourceName());
throw new OrcidDuplicatedActivityException(params);
}
}
}
// Save the work
WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
workEntity.setOrcid(orcid);
workEntity.setAddedToProfileDate(new Date());
// Set source id
if (sourceEntity.getSourceProfile() != null) {
workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, true);
workDao.persist(workEntity);
// Update the element in the bulk
Work updatedWork = jpaJaxbWorkAdapter.toWork(workEntity);
bulk.set(i, updatedWork);
// Add the work extIds to the list of existing external identifiers
addExternalIdsToExistingSet(updatedWork, existingExternalIdentifiers);
} catch (Exception e) {
// Get the exception
OrcidError orcidError = orcidCoreExceptionMapper.getV3OrcidError(e);
bulk.set(i, orcidError);
}
}
}
workDao.flush();
}
return workBulk;
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.
the class ExternalIDNormalizedValueTest method testEqualsAndHashcode.
@Test
public void testEqualsAndHashcode() {
ExternalID id1 = new ExternalID();
id1.setType("doi");
id1.setValue("VALUE");
id1.setNormalized(new TransientNonEmptyString("value"));
ExternalID id2 = new ExternalID();
id2.setType("doi");
id2.setValue("value");
id2.setNormalized(new TransientNonEmptyString("value"));
assertEquals(id1, id2);
assertEquals(id1.hashCode(), id2.hashCode());
Set<ExternalID> set1 = new HashSet<ExternalID>();
id1.getNormalized().setValue("value");
set1.add(id1);
set1.add(id2);
assertEquals(1, set1.size());
id1.getNormalized().setValue("VALUE");
assertNotEquals(id1, id2);
assertNotEquals(id1.hashCode(), id2.hashCode());
Set<ExternalID> set2 = new HashSet<ExternalID>();
set2.add(id1);
set2.add(id2);
assertEquals(2, set2.size());
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.
the class TransientNonEmptyStringTest method testMarshal.
/**
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
* <common:external-ids xmlns:internal="http://www.orcid.org/ns/internal" xmlns:address="http://www.orcid.org/ns/address" xmlns:email="http://www.orcid.org/ns/email" xmlns:history="http://www.orcid.org/ns/history" xmlns:employment="http://www.orcid.org/ns/employment" xmlns:person="http://www.orcid.org/ns/person" xmlns:education="http://www.orcid.org/ns/education" xmlns:other-name="http://www.orcid.org/ns/other-name" xmlns:personal-details="http://www.orcid.org/ns/personal-details" xmlns:bulk="http://www.orcid.org/ns/bulk" xmlns:common="http://www.orcid.org/ns/common" xmlns:record="http://www.orcid.org/ns/record" xmlns:keyword="http://www.orcid.org/ns/keyword" xmlns:activities="http://www.orcid.org/ns/activities" xmlns:deprecated="http://www.orcid.org/ns/deprecated" xmlns:external-identifier="http://www.orcid.org/ns/external-identifier" xmlns:funding="http://www.orcid.org/ns/funding" xmlns:error="http://www.orcid.org/ns/error" xmlns:preferences="http://www.orcid.org/ns/preferences" xmlns:work="http://www.orcid.org/ns/work" xmlns:researcher-url="http://www.orcid.org/ns/researcher-url" xmlns:peer-review="http://www.orcid.org/ns/peer-review">
* <common:external-id>
* <common:external-id-type>doi</common:external-id-type>
* <common:external-id-value>value</common:external-id-value>
* <common:external-id-normalized transient="true">normalized-value</common:external-id-normalized>
* </common:external-id>
* </common:external-ids>
* @throws JAXBException
* @throws SAXException
* @throws IOException
*/
@Test
public void testMarshal() throws JAXBException, SAXException, IOException {
ExternalIDs ids = new ExternalIDs();
ExternalID id = new ExternalID();
id.setType("doi");
id.setValue("value");
id.setNormalized(new TransientNonEmptyString("normalized-value"));
ids.getExternalIdentifier().add(id);
JAXBContext context = JAXBContext.newInstance(ExternalIDs.class);
Marshaller marshaller = context.createMarshaller();
StringWriter sw = new StringWriter();
marshaller.marshal(ids, sw);
assertTrue(sw.toString().contains("<common:external-id-normalized transient=\"true\">normalized-value</common:external-id-normalized>"));
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(getClass().getResource("/common_3.0_dev1/common-3.0_dev1.xsd"));
Validator validator = schema.newValidator();
validator.validate(new JAXBSource(context, ids));
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.
the class ActivitiesGroupGenerator_GroupingWorksTest method testNormalizedGrouping.
@Test
public void testNormalizedGrouping() {
ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
List<WorkSummary> sums = new ArrayList<WorkSummary>();
for (int i = 0; i < 2; i++) {
String title = "work-" + i;
WorkSummary work = new WorkSummary();
// Set title
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title(title));
work.setTitle(workTitle);
ExternalIDs wei = new ExternalIDs();
ExternalID e1 = new ExternalID();
e1.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.DOI.value());
e1.setValue("a");
e1.setNormalized(new TransientNonEmptyString("a"));
wei.getExternalIdentifier().add(e1);
work.setExternalIdentifiers(wei);
sums.add(work);
}
sums.get(0).getExternalIdentifiers().getExternalIdentifier().get(0).setValue("A");
generator.group(sums.get(0));
generator.group(sums.get(1));
assertEquals(1, generator.getGroups().size());
checkActivitiesBelongsToTheSameGroup(generator.getGroups(), sums.get(0), sums.get(1));
for (int i = 2; i < 4; i++) {
String title = "work-" + i;
WorkSummary work = new WorkSummary();
// Set title
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title(title));
work.setTitle(workTitle);
ExternalIDs wei = new ExternalIDs();
ExternalID e1 = new ExternalID();
e1.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e1.setValue("https://dx.doi.org/10/UPPER");
e1.setNormalized(new TransientNonEmptyString("10/upper"));
wei.getExternalIdentifier().add(e1);
work.setExternalIdentifiers(wei);
sums.add(work);
}
sums.get(0).getExternalIdentifiers().getExternalIdentifier().get(0).setValue("http://doi.org/10/upper");
generator.group(sums.get(2));
generator.group(sums.get(3));
assertEquals(2, generator.getGroups().size());
checkActivitiesBelongsToTheSameGroup(generator.getGroups(), sums.get(0), sums.get(1));
checkActivitiesBelongsToTheSameGroup(generator.getGroups(), sums.get(2), sums.get(3));
}
use of org.orcid.jaxb.model.v3.dev1.record.ExternalID in project ORCID-Source by ORCID.
the class ActivitiesGroupGenerator_GroupingWorksTest method generateWorks.
/**
* work-1 -> ARG(A), ARG(B), ARG(C)
* work-2 -> ARG(C), ARG(D), ARG(E)
* work-3 -> ARG(X), ARG(Y), ARG(Z)
* work-4 -> ARG(Y), ARG(B), ARG(1)
* work-5 -> ARG(M), ARG(N), ARG(O)
* work-6 -> ARXIV(A), ARXIV(B), ARXIV(C)
* work-7 -> DOI(1), DOI(2), ARIXV(B)
* work-8 -> No external identifiers
* work-9 -> No external identifiers
* work-10 -> ISSN(1), ISSN(2), ISSN(3)
* work-11 -> ISSN(3), ISSN(4), ISSN(5)
* work-12 -> DOI(1), ISSN(1)
* work-13 -> DOI(1), ISSN(4)
*/
private Map<String, WorkSummary> generateWorks() {
Map<String, WorkSummary> result = new HashMap<String, WorkSummary>();
for (int i = 1; i < 14; i++) {
String title = "work-" + i;
WorkSummary work = new WorkSummary();
// Set title
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title(title));
work.setTitle(workTitle);
ExternalIDs wei = new ExternalIDs();
switch(i) {
case 1:
ExternalID e1 = new ExternalID();
e1.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e1.setValue("A");
ExternalID e2 = new ExternalID();
e2.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e2.setValue("B");
ExternalID e3 = new ExternalID();
e3.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e3.setValue("C");
wei.getExternalIdentifier().add(e1);
wei.getExternalIdentifier().add(e2);
wei.getExternalIdentifier().add(e3);
break;
case 2:
ExternalID e4 = new ExternalID();
e4.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e4.setValue("C");
ExternalID e5 = new ExternalID();
e5.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e5.setValue("D");
ExternalID e6 = new ExternalID();
e6.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e6.setValue("E");
wei.getExternalIdentifier().add(e4);
wei.getExternalIdentifier().add(e5);
wei.getExternalIdentifier().add(e6);
break;
case 3:
ExternalID e7 = new ExternalID();
e7.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e7.setValue("X");
ExternalID e8 = new ExternalID();
e8.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e8.setValue("Y");
ExternalID e9 = new ExternalID();
e9.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e9.setValue("Z");
wei.getExternalIdentifier().add(e7);
wei.getExternalIdentifier().add(e8);
wei.getExternalIdentifier().add(e9);
break;
case 4:
ExternalID e10 = new ExternalID();
e10.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e10.setValue("Y");
ExternalID e11 = new ExternalID();
e11.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e11.setValue("B");
ExternalID e12 = new ExternalID();
e12.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e12.setValue("1");
wei.getExternalIdentifier().add(e10);
wei.getExternalIdentifier().add(e11);
wei.getExternalIdentifier().add(e12);
break;
case 5:
ExternalID e13 = new ExternalID();
e13.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e13.setValue("M");
ExternalID e14 = new ExternalID();
e14.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e14.setValue("N");
ExternalID e15 = new ExternalID();
e15.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value());
e15.setValue("O");
wei.getExternalIdentifier().add(e13);
wei.getExternalIdentifier().add(e14);
wei.getExternalIdentifier().add(e15);
break;
case 6:
ExternalID e16 = new ExternalID();
e16.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ARXIV.value());
e16.setValue("A");
ExternalID e17 = new ExternalID();
e17.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ARXIV.value());
e17.setValue("B");
ExternalID e18 = new ExternalID();
e18.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ARXIV.value());
e18.setValue("C");
wei.getExternalIdentifier().add(e16);
wei.getExternalIdentifier().add(e17);
wei.getExternalIdentifier().add(e18);
break;
case 7:
ExternalID e19 = new ExternalID();
e19.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.DOI.value());
e19.setValue("1");
ExternalID e20 = new ExternalID();
e20.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.DOI.value());
e20.setValue("2");
ExternalID e21 = new ExternalID();
e21.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ARXIV.value());
e21.setValue("B");
wei.getExternalIdentifier().add(e19);
wei.getExternalIdentifier().add(e20);
wei.getExternalIdentifier().add(e21);
break;
case 10:
ExternalID e22 = new ExternalID();
e22.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e22.setValue("1");
ExternalID e23 = new ExternalID();
e23.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e23.setValue("2");
ExternalID e24 = new ExternalID();
e24.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e24.setValue("3");
wei.getExternalIdentifier().add(e22);
wei.getExternalIdentifier().add(e23);
wei.getExternalIdentifier().add(e24);
break;
case 11:
ExternalID e25 = new ExternalID();
e25.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e25.setValue("3");
ExternalID e26 = new ExternalID();
e26.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e26.setValue("3");
ExternalID e27 = new ExternalID();
e27.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e27.setValue("3");
wei.getExternalIdentifier().add(e25);
wei.getExternalIdentifier().add(e26);
wei.getExternalIdentifier().add(e27);
break;
case 12:
ExternalID e28 = new ExternalID();
e28.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.DOI.value());
e28.setValue("1");
ExternalID e29 = new ExternalID();
e29.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e29.setValue("1");
wei.getExternalIdentifier().add(e28);
wei.getExternalIdentifier().add(e29);
break;
case 13:
ExternalID e30 = new ExternalID();
e30.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.DOI.value());
e30.setValue("1");
ExternalID e31 = new ExternalID();
e31.setType(org.orcid.jaxb.model.message.WorkExternalIdentifierType.ISSN.value());
e31.setValue("4");
wei.getExternalIdentifier().add(e30);
wei.getExternalIdentifier().add(e31);
break;
}
work.setExternalIdentifiers(wei);
result.put(title, work);
}
return result;
}
Aggregations