use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class WorkManagerImpl method updateWork.
@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
Visibility originalVisibility = workEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = workEntity.getSourceId();
String existingClientSourceId = workEntity.getClientSourceId();
if (isApiRequest) {
activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
long lastModifiedTime = getLastModified(orcid);
List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
for (Work existing : existingWorks) {
// Dont compare the updated peer review with the DB version
if (!existing.getPutCode().equals(work.getPutCode())) {
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
//validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
orcidSecurityManager.checkSource(workEntity);
jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
workEntity.setVisibility(originalVisibility);
//Be sure it doesn't overwrite the source
workEntity.setSourceId(existingSourceId);
workEntity.setClientSourceId(existingClientSourceId);
workDao.merge(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class WorkManagerImpl method createWork.
@Override
@Transactional
public Work createWork(String orcid, Work work, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
if (isApiRequest) {
activityValidator.validateWork(work, sourceEntity, true, isApiRequest, null);
// duplicates
if (!sourceEntity.getSourceId().equals(orcid)) {
long lastModifiedTime = getLastModified(orcid);
List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
if (existingWorks != null) {
for (Work existing : existingWorks) {
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
}
} else {
// validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
workEntity.setProfile(profile);
workEntity.setAddedToProfileDate(new Date());
// Set source id
if (sourceEntity.getSourceProfile() != null) {
workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
workDao.persist(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method updateResearcherUrl.
@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
//Save the original source
String existingSourceId = updatedResearcherUrlEntity.getSourceId();
String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
// Validate the researcher url
PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
for (ResearcherUrlEntity existing : existingResearcherUrls) {
if (isDuplicated(existing, researcherUrl, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "researcher-url");
params.put("value", researcherUrl.getUrlName());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
updatedResearcherUrlEntity.setLastModified(new Date());
//Be sure it doesn't overwrite the source
updatedResearcherUrlEntity.setSourceId(existingSourceId);
updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
researcherUrlDao.merge(updatedResearcherUrlEntity);
return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method updateResearcherUrls.
/**
* Update the researcher urls associated with a specific account
*
* @param orcid
* @param researcherUrls
* */
@Override
@Transactional
public ResearcherUrls updateResearcherUrls(String orcid, ResearcherUrls researcherUrls) {
List<ResearcherUrlEntity> existingEntities = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
//Delete the deleted ones
for (ResearcherUrlEntity existingEntity : existingEntities) {
boolean deleteMe = true;
if (researcherUrls.getResearcherUrls() != null) {
for (ResearcherUrl updatedOrNew : researcherUrls.getResearcherUrls()) {
if (existingEntity.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
researcherUrlDao.deleteResearcherUrl(existingEntity.getProfile().getId(), existingEntity.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete researcher url " + existingEntity.getId(), e);
}
}
}
// Update or create new
if (researcherUrls != null && researcherUrls.getResearcherUrls() != null) {
for (ResearcherUrl updatedOrNew : researcherUrls.getResearcherUrls()) {
if (updatedOrNew.getPutCode() != null) {
//Update the existing ones
for (ResearcherUrlEntity existingEntity : existingEntities) {
if (existingEntity.getId().equals(updatedOrNew.getPutCode())) {
existingEntity.setLastModified(new Date());
existingEntity.setVisibility(updatedOrNew.getVisibility());
existingEntity.setUrl(updatedOrNew.getUrl().getValue());
existingEntity.setUrlName(updatedOrNew.getUrlName());
existingEntity.setDisplayIndex(updatedOrNew.getDisplayIndex());
researcherUrlDao.merge(existingEntity);
}
}
} else {
//Add the new ones
ResearcherUrlEntity newResearcherUrl = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newResearcherUrl.setUser(profile);
newResearcherUrl.setDateCreated(new Date());
newResearcherUrl.setLastModified(new Date());
if (sourceEntity.getSourceProfile() != null) {
newResearcherUrl.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newResearcherUrl.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newResearcherUrl.setVisibility(updatedOrNew.getVisibility());
newResearcherUrl.setDisplayIndex(updatedOrNew.getDisplayIndex());
researcherUrlDao.persist(newResearcherUrl);
}
}
}
return researcherUrls;
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method createResearcherUrl.
@Override
public ResearcherUrl createResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Validate the researcher url
PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, true, isApiRequest, null);
// Validate it is not duplicated
List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
for (ResearcherUrlEntity existing : existingResearcherUrls) {
if (isDuplicated(existing, researcherUrl, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "researcher-url");
params.put("value", researcherUrl.getUrlName());
throw new OrcidDuplicatedElementException(params);
}
}
ResearcherUrlEntity newEntity = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl);
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());
}
setIncomingPrivacy(newEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
researcherUrlDao.persist(newEntity);
return jpaJaxbResearcherUrlAdapter.toResearcherUrl(newEntity);
}
Aggregations