Search in sources :

Example 51 with PersonExternalIdentifier

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;
}
Also used : ApplicationException(org.orcid.core.exception.ApplicationException) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date)

Example 52 with PersonExternalIdentifier

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);
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)

Example 53 with PersonExternalIdentifier

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 54 with PersonExternalIdentifier

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 55 with PersonExternalIdentifier

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);
    }
}
Also used : Email(org.orcid.jaxb.model.record_rc2.Email) InputStreamReader(java.io.InputStreamReader) Keyword(org.orcid.jaxb.model.record_rc2.Keyword) Address(org.orcid.jaxb.model.record_rc2.Address) OtherNames(org.orcid.jaxb.model.record_rc2.OtherNames) CreditName(org.orcid.jaxb.model.record_rc2.CreditName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) PersonExternalIdentifier(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifier) History(org.orcid.jaxb.model.record_rc2.History) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc2.ActivitiesSummary) Deprecated(org.orcid.jaxb.model.record_rc2.Deprecated) Biography(org.orcid.jaxb.model.record_rc2.Biography) ResearcherUrl(org.orcid.jaxb.model.record_rc2.ResearcherUrl)

Aggregations

PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)99 Test (org.junit.Test)91 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)47 Address (org.orcid.jaxb.model.record_v2.Address)42 Keyword (org.orcid.jaxb.model.record_v2.Keyword)42 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)41 OtherName (org.orcid.jaxb.model.record_v2.OtherName)40 Email (org.orcid.jaxb.model.record_v2.Email)39 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 Biography (org.orcid.jaxb.model.record_v2.Biography)32 Person (org.orcid.jaxb.model.record_v2.Person)32 Addresses (org.orcid.jaxb.model.record_v2.Addresses)31 Emails (org.orcid.jaxb.model.record_v2.Emails)31 Keywords (org.orcid.jaxb.model.record_v2.Keywords)31 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)31 Name (org.orcid.jaxb.model.record_v2.Name)29 Response (javax.ws.rs.core.Response)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)19 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)19 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)19