use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class GroupIdRecordManagerImpl method updateGroupIdRecord.
@Override
public GroupIdRecord updateGroupIdRecord(Long putCode, GroupIdRecord groupIdRecord) {
GroupIdRecordEntity existingEntity = groupIdRecordDao.find(putCode);
if (existingEntity == null) {
throw new GroupIdRecordNotFoundException();
}
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = existingEntity.getSourceId();
String existingClientSourceId = existingEntity.getClientSourceId();
activityValidator.validateGroupIdRecord(groupIdRecord, false, sourceEntity);
validateDuplicate(groupIdRecord);
orcidSecurityManager.checkSource(existingEntity);
GroupIdRecordEntity updatedEntity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
updatedEntity.setDateCreated(existingEntity.getDateCreated());
// Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
updatedEntity = groupIdRecordDao.merge(updatedEntity);
return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(updatedEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class IdentifierTypeManagerImpl method createIdentifierType.
@Override
@CacheEvict(value = { "identifier-types", "identifier-types-map" }, allEntries = true)
public IdentifierType createIdentifierType(IdentifierType id) {
IdentifierTypeEntity entity = adapter.fromPojo(id);
SourceEntity source = sourceManager.retrieveSourceEntity();
entity.setSourceClient(source.getSourceClient());
Date now = new Date();
entity.setDateCreated(now);
entity.setLastModified(now);
entity = idTypeDao.addIdentifierType(entity);
return adapter.fromEntity(entity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity 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.persistence.jpa.entities.SourceEntity 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(updatedOrNew.getVisibility());
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(updatedOrNew.getVisibility());
newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.persist(newOtherName);
}
}
}
return otherNames;
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeywords.
@Override
@Transactional
public Keywords updateKeywords(String orcid, Keywords keywords) {
List<ProfileKeywordEntity> existingKeywordsList = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
// Delete the deleted ones
for (ProfileKeywordEntity existing : existingKeywordsList) {
boolean deleteMe = true;
if (keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (existing.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
profileKeywordDao.deleteProfileKeyword(existing);
} catch (Exception e) {
throw new ApplicationException("Unable to delete keyword " + existing.getId(), e);
}
}
}
if (keywords != null && keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (ProfileKeywordEntity existingKeyword : existingKeywordsList) {
if (existingKeyword.getId().equals(updatedOrNew.getPutCode())) {
existingKeyword.setLastModified(new Date());
existingKeyword.setVisibility(updatedOrNew.getVisibility());
existingKeyword.setKeywordName(updatedOrNew.getContent());
existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.merge(existingKeyword);
}
}
} else {
// Add the new ones
ProfileKeywordEntity newKeyword = adapter.toProfileKeywordEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newKeyword.setProfile(profile);
newKeyword.setDateCreated(new Date());
//Set the source
if (sourceEntity.getSourceProfile() != null) {
newKeyword.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newKeyword.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newKeyword.setVisibility(updatedOrNew.getVisibility());
newKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.persist(newKeyword);
}
}
}
return keywords;
}
Aggregations