Search in sources :

Example 1 with ExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getExternalIdentifierMapperFacade.

public MapperFacade getExternalIdentifierMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<PersonExternalIdentifier, ExternalIdentifierEntity> externalIdentifierClassMap = mapperFactory.classMap(PersonExternalIdentifier.class, ExternalIdentifierEntity.class);
    addV2DateFields(externalIdentifierClassMap);
    externalIdentifierClassMap.field("putCode", "id");
    externalIdentifierClassMap.field("type", "externalIdCommonName");
    externalIdentifierClassMap.field("value", "externalIdReference");
    externalIdentifierClassMap.field("url.value", "externalIdUrl");
    externalIdentifierClassMap.fieldBToA("displayIndex", "displayIndex");
    externalIdentifierClassMap.byDefault();
    registerSourceConverters(mapperFactory, externalIdentifierClassMap);
    //TODO: add relationship to database schema for people.
    externalIdentifierClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)

Example 2 with ExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method updateExternalIdentifier.

@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
    //Save the original source
    String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
    String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
    Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, requireRelationshipOnExternalIdentifier);
    // Validate it is not duplicated
    List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
    for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
        if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "external-identifier");
            params.put("value", externalIdentifier.getUrl().getValue());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
    jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
    updatedExternalIdentifierEntity.setLastModified(new Date());
    //Set source
    updatedExternalIdentifierEntity.setSourceId(existingSourceId);
    updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
    externalIdentifierDao.merge(updatedExternalIdentifierEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date)

Example 3 with ExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity 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 4 with ExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.

the class JpaJaxbExternalIdentifierAdapterTest method testToExternalIdentifierEntity.

@Test
public void testToExternalIdentifierEntity() throws JAXBException {
    ExternalIdentifierEntity entity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(getExternalIdentifier());
    assertNotNull(entity);
    assertEquals("A-0003", entity.getExternalIdCommonName());
    assertEquals("A-0003", entity.getExternalIdReference());
    assertEquals("http://ext-id/A-0003", entity.getExternalIdUrl());
    assertEquals(Long.valueOf(1), entity.getId());
    assertNotNull(entity.getDateCreated());
    assertNotNull(entity.getLastModified());
    // Source
    assertNull(entity.getSourceId());
    assertNull(entity.getClientSourceId());
    assertNull(entity.getElementSourceId());
}
Also used : ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) Test(org.junit.Test)

Example 5 with ExternalIdentifierEntity

use of org.orcid.persistence.jpa.entities.ExternalIdentifierEntity in project ORCID-Source by ORCID.

the class ProfileEntityManagerImplTest method testClaimChangingVisibility.

@Test
@Transactional
public void testClaimChangingVisibility() {
    Claim claim = new Claim();
    claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
    claim.setPassword(Text.valueOf("passwordTest1"));
    claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
    Checkbox checked = new Checkbox();
    checked.setValue(true);
    claim.setSendChangeNotifications(checked);
    claim.setSendOrcidNews(checked);
    claim.setTermsOfUse(checked);
    assertTrue(profileEntityManager.claimProfileAndUpdatePreferences("0000-0000-0000-0001", "public_0000-0000-0000-0001@test.orcid.org", Locale.EN, claim));
    ProfileEntity profile = profileEntityManager.findByOrcid("0000-0000-0000-0001");
    assertNotNull(profile);
    assertNotNull(profile.getBiographyEntity());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, profile.getBiographyEntity().getVisibility());
    assertNotNull(profile.getAddresses());
    assertEquals(3, profile.getAddresses().size());
    for (AddressEntity a : profile.getAddresses()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, a.getVisibility());
    }
    assertNotNull(profile.getExternalIdentifiers());
    assertEquals(3, profile.getExternalIdentifiers().size());
    for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, e.getVisibility());
    }
    assertNotNull(profile.getKeywords());
    assertEquals(3, profile.getKeywords().size());
    for (ProfileKeywordEntity k : profile.getKeywords()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, k.getVisibility());
    }
    assertNotNull(profile.getOtherNames());
    assertEquals(3, profile.getOtherNames().size());
    for (OtherNameEntity o : profile.getOtherNames()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, o.getVisibility());
    }
    assertNotNull(profile.getResearcherUrls());
    assertEquals(3, profile.getResearcherUrls().size());
    for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, r.getVisibility());
    }
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Claim(org.orcid.pojo.ajaxForm.Claim) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)17 Test (org.junit.Test)6 Date (java.util.Date)5 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)5 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)5 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)3 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashMap (java.util.HashMap)2 ApplicationException (org.orcid.core.exception.ApplicationException)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 GivenNames (org.orcid.jaxb.model.record_v2.GivenNames)2