Search in sources :

Example 21 with OtherNameEntity

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

the class JpaJaxbOtherNameAdapterTest method fromOtherNameEntityToOtherNameTest.

@Test
public void fromOtherNameEntityToOtherNameTest() {
    OtherNameEntity entity = getOtherNameEntity();
    OtherName otherName = adapter.toOtherName(entity);
    assertNotNull(otherName);
    assertEquals("display-name", otherName.getContent());
    assertNotNull(otherName.getCreatedDate());
    assertNotNull(otherName.getLastModifiedDate());
    assertEquals(Long.valueOf(1), otherName.getPutCode());
    assertNotNull(otherName.getSource());
    assertEquals("APP-000000001", otherName.getSource().retrieveSourcePath());
    assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Also used : OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Test(org.junit.Test)

Example 22 with OtherNameEntity

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

the class JpaJaxbOtherNameAdapterTest method getOtherNameEntity.

private OtherNameEntity getOtherNameEntity() {
    OtherNameEntity result = new OtherNameEntity();
    result.setId(Long.valueOf(1));
    result.setDateCreated(new Date());
    result.setLastModified(new Date());
    result.setDisplayName("display-name");
    result.setProfile(new ProfileEntity("0000-0000-0000-0000"));
    result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 23 with OtherNameEntity

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

the class OtherNameManagerImpl method createOtherName.

@Override
@Transactional
public OtherName createOtherName(String orcid, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the otherName
    PersonValidator.validateOtherName(otherName, sourceEntity, true, isApiRequest, null);
    // Validate it is not duplicated
    List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    for (OtherNameEntity existing : existingOtherNames) {
        if (isDuplicated(existing, otherName, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "other-name");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    OtherNameEntity newEntity = jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setProfile(profile);
    newEntity.setDateCreated(new Date());
    // Set the source
    if (sourceEntity.getSourceProfile() != null) {
        newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingPrivacy(newEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
    otherNameDao.persist(newEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(newEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with OtherNameEntity

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

the class OtherNameManagerImpl method updateOtherNames.

@Override
@Transactional
public OtherNames updateOtherNames(String orcid, OtherNames otherNames) {
    List<OtherNameEntity> existingOtherNamesEntityList = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    // Delete the deleted ones
    for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
        boolean deleteMe = true;
        if (otherNames.getOtherNames() != null) {
            for (OtherName updatedOrNew : otherNames.getOtherNames()) {
                if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                    deleteMe = false;
                    break;
                }
            }
        }
        if (deleteMe) {
            try {
                otherNameDao.deleteOtherName(existingOtherName);
            } catch (Exception e) {
                throw new ApplicationException("Unable to delete other name " + existingOtherName.getId(), e);
            }
        }
    }
    if (otherNames != null && otherNames.getOtherNames() != null) {
        for (OtherName updatedOrNew : otherNames.getOtherNames()) {
            if (updatedOrNew.getPutCode() != null) {
                // Update the existing ones
                for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
                    if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                        existingOtherName.setLastModified(new Date());
                        existingOtherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
                        existingOtherName.setDisplayName(updatedOrNew.getContent());
                        existingOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                        otherNameDao.merge(existingOtherName);
                    }
                }
            } else {
                // Add the new ones
                OtherNameEntity newOtherName = jpaJaxbOtherNameAdapter.toOtherNameEntity(updatedOrNew);
                SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
                ProfileEntity profile = new ProfileEntity(orcid);
                newOtherName.setProfile(profile);
                newOtherName.setDateCreated(new Date());
                // Set the source
                if (sourceEntity.getSourceProfile() != null) {
                    newOtherName.setSourceId(sourceEntity.getSourceProfile().getId());
                }
                if (sourceEntity.getSourceClient() != null) {
                    newOtherName.setClientSourceId(sourceEntity.getSourceClient().getId());
                }
                newOtherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
                newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                otherNameDao.persist(newOtherName);
            }
        }
    }
    return otherNames;
}
Also used : ApplicationException(org.orcid.core.exception.ApplicationException) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with OtherNameEntity

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

the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.

@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
    // Verify the email
    boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
    if (!emailVerified) {
        throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
    }
    // Update the profile entity fields
    ProfileEntity profile = profileDao.find(orcid);
    profile.setLastModified(new Date());
    profile.setIndexingStatus(IndexingStatus.REINDEX);
    profile.setClaimed(true);
    profile.setCompletedDate(new Date());
    profile.setEncryptedPassword(encryptionManager.hashForInternalUse(claim.getPassword().getValue()));
    if (locale != null) {
        profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
    }
    if (claim != null) {
        profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
        profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
        profile.setActivitiesVisibilityDefault(org.orcid.jaxb.model.common_v2.Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
    }
    // Update the visibility for every bio element to the visibility
    // selected by the user
    // Update the bio
    org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
    if (profile.getBiographyEntity() != null) {
        profile.getBiographyEntity().setVisibility(defaultVisibility);
    }
    // Update address
    if (profile.getAddresses() != null) {
        for (AddressEntity a : profile.getAddresses()) {
            a.setVisibility(defaultVisibility);
        }
    }
    // Update the keywords
    if (profile.getKeywords() != null) {
        for (ProfileKeywordEntity k : profile.getKeywords()) {
            k.setVisibility(defaultVisibility);
        }
    }
    // Update the other names
    if (profile.getOtherNames() != null) {
        for (OtherNameEntity o : profile.getOtherNames()) {
            o.setVisibility(defaultVisibility);
        }
    }
    // Update the researcher urls
    if (profile.getResearcherUrls() != null) {
        for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
            r.setVisibility(defaultVisibility);
        }
    }
    // Update the external identifiers
    if (profile.getExternalIdentifiers() != null) {
        for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
            e.setVisibility(defaultVisibility);
        }
    }
    profileDao.merge(profile);
    profileDao.flush();
    return true;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)27 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)13 Date (java.util.Date)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.Test)10 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)7 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)7 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)6 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 HashMap (java.util.HashMap)4 OtherName (org.orcid.jaxb.model.record_v2.OtherName)4 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)4 ApplicationException (org.orcid.core.exception.ApplicationException)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 InvalidParameterException (java.security.InvalidParameterException)2 MapperFactory (ma.glasnost.orika.MapperFactory)2