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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations