use of org.orcid.jaxb.model.record_rc3.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method updateExternalIdentifiers.
@Override
public PersonExternalIdentifiers updateExternalIdentifiers(String orcid, PersonExternalIdentifiers externalIdentifiers) {
List<ExternalIdentifierEntity> existingExternalIdentifiersList = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
// Delete the deleted ones
for (ExternalIdentifierEntity existing : existingExternalIdentifiersList) {
boolean deleteMe = true;
if (externalIdentifiers.getExternalIdentifiers() != null) {
for (PersonExternalIdentifier updatedOrNew : externalIdentifiers.getExternalIdentifiers()) {
if (existing.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
externalIdentifierDao.removeExternalIdentifier(orcid, existing.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete external identifier " + existing.getId(), e);
}
}
}
if (externalIdentifiers != null && externalIdentifiers.getExternalIdentifiers() != null) {
for (PersonExternalIdentifier updatedOrNew : externalIdentifiers.getExternalIdentifiers()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (ExternalIdentifierEntity existingExtId : existingExternalIdentifiersList) {
if (existingExtId.getId().equals(updatedOrNew.getPutCode())) {
existingExtId.setLastModified(new Date());
existingExtId.setVisibility(updatedOrNew.getVisibility());
existingExtId.setDisplayIndex(updatedOrNew.getDisplayIndex());
externalIdentifierDao.merge(existingExtId);
}
}
}
}
}
return externalIdentifiers;
}
use of org.orcid.jaxb.model.record_rc3.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class JpaJaxbExternalIdentifierAdapterTest method getExternalIdentifier.
private PersonExternalIdentifier getExternalIdentifier() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(new Class[] { PersonExternalIdentifier.class });
Unmarshaller unmarshaller = context.createUnmarshaller();
String name = "/record_2.0/samples/read_samples/external-identifier-2.0.xml";
InputStream inputStream = getClass().getResourceAsStream(name);
return (PersonExternalIdentifier) unmarshaller.unmarshal(inputStream);
}
use of org.orcid.jaxb.model.record_rc3.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerTest method testAddEqualsExternalIdentifiersFromDifferentSource.
@Test
public void testAddEqualsExternalIdentifiersFromDifferentSource() {
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
// Create from client # 1
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, true);
assertNotNull(extId1);
assertNotNull(extId1.getPutCode());
// Create from client # 2
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
PersonExternalIdentifier extId2 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, true);
assertNotNull(extId2);
assertNotNull(extId2.getPutCode());
// Verify both ext ids are not the same one
assertNotEquals(extId1.getPutCode(), extId2.getPutCode());
}
use of org.orcid.jaxb.model.record_rc3.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerTest method displayIndexIsSetTo_0_FromAPI.
@Test
public void displayIndexIsSetTo_0_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
PersonExternalIdentifier extId = getExternalIdentifier();
extId.setType(extId.getType() + System.currentTimeMillis());
PersonExternalIdentifier extId1 = externalIdentifierManager.createExternalIdentifier(claimedOrcid, extId, true);
extId1 = externalIdentifierManager.getExternalIdentifier(claimedOrcid, extId1.getPutCode());
assertNotNull(extId1);
assertEquals(Long.valueOf(0), extId1.getDisplayIndex());
}
use of org.orcid.jaxb.model.record_rc3.PersonExternalIdentifier in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method unmarshallFromPath.
private Object unmarshallFromPath(String path, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type, schemaPath);
Object result = null;
if (ResearcherUrls.class.equals(type)) {
result = (ResearcherUrls) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (PersonExternalIdentifiers.class.equals(type)) {
result = (PersonExternalIdentifiers) obj;
} else if (Biography.class.equals(type)) {
result = (Biography) obj;
} else if (Name.class.equals(type)) {
result = (Name) obj;
} else if (CreditName.class.equals(type)) {
result = (CreditName) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (OtherNames.class.equals(type)) {
result = (OtherNames) obj;
} else if (Keywords.class.equals(type)) {
result = (Keywords) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Addresses.class.equals(type)) {
result = (Addresses) obj;
} else if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Emails.class.equals(type)) {
result = (Emails) obj;
} else if (Email.class.equals(type)) {
result = (Email) obj;
} else if (Person.class.equals(type)) {
result = (Person) obj;
} else if (Deprecated.class.equals(type)) {
result = (Deprecated) obj;
} else if (Preferences.class.equals(type)) {
result = (Preferences) obj;
} else if (History.class.equals(type)) {
result = (History) obj;
} else if (Record.class.equals(type)) {
result = (Record) obj;
} else if (ActivitiesSummary.class.equals(type)) {
result = (ActivitiesSummary) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
Aggregations