Search in sources :

Example 11 with OrcidDuplicatedElementException

use of org.orcid.core.exception.OrcidDuplicatedElementException 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 12 with OrcidDuplicatedElementException

use of org.orcid.core.exception.OrcidDuplicatedElementException in project ORCID-Source by ORCID.

the class ProfileKeywordManagerImpl method createKeyword.

@Override
public Keyword createKeyword(String orcid, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, true, isApiRequest, null);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywords(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    ProfileKeywordEntity newEntity = adapter.toProfileKeywordEntity(keyword);
    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);
    profileKeywordDao.persist(newEntity);
    return adapter.toKeyword(newEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 13 with OrcidDuplicatedElementException

use of org.orcid.core.exception.OrcidDuplicatedElementException in project ORCID-Source by ORCID.

the class ProfileKeywordManagerImpl method updateKeyword.

@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    // Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywords(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedEntity);
    adapter.toProfileKeywordEntity(keyword, updatedEntity);
    updatedEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    profileKeywordDao.merge(updatedEntity);
    return adapter.toKeyword(updatedEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 14 with OrcidDuplicatedElementException

use of org.orcid.core.exception.OrcidDuplicatedElementException in project ORCID-Source by ORCID.

the class AddressManagerImpl method createAddress.

@Override
public Address createAddress(String orcid, Address address, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the address
    PersonValidator.validateAddress(address, sourceEntity, true, isApiRequest, null);
    // Validate it is not duplicated
    List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
    for (AddressEntity existing : existingAddresses) {
        if (isDuplicated(existing, address, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "address");
            params.put("value", address.getCountry().getValue().value());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    AddressEntity newEntity = adapter.toAddressEntity(address);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setUser(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());
    }
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
    setIncomingPrivacy(newEntity, profile);
    addressDao.persist(newEntity);
    return adapter.toAddress(newEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 15 with OrcidDuplicatedElementException

use of org.orcid.core.exception.OrcidDuplicatedElementException in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method createExternalIdentifier.

@Override
public PersonExternalIdentifier createExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, true, isApiRequest, null, 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);
        }
    }
    ExternalIdentifierEntity newEntity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setOwner(profile);
    newEntity.setDateCreated(new Date());
    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);
    externalIdentifierDao.persist(newEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(newEntity);
}
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) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Aggregations

Date (java.util.Date)20 HashMap (java.util.HashMap)20 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)20 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)20 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Transactional (org.springframework.transaction.annotation.Transactional)6 Visibility (org.orcid.jaxb.model.common_v2.Visibility)5 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)5 Transactional (javax.transaction.Transactional)4 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)4 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)4 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)4 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)4 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)4