use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity 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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
newResearcherUrl.setDisplayIndex(updatedOrNew.getDisplayIndex());
researcherUrlDao.persist(newResearcherUrl);
}
}
}
return researcherUrls;
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.
the class ResearcherUrlManagerImpl method deleteResearcherUrl.
@Override
public boolean deleteResearcherUrl(String orcid, Long id, boolean checkSource) {
boolean result = true;
ResearcherUrlEntity toDelete = researcherUrlDao.getResearcherUrl(orcid, id);
if (checkSource) {
orcidSecurityManager.checkSource(toDelete);
}
try {
researcherUrlDao.deleteResearcherUrl(orcid, id);
} catch (Exception e) {
LOGGER.error("Unable to delete researcherUrl with ID: " + id);
result = false;
}
return result;
}
use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity 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.ResearcherUrlEntity 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.ResearcherUrlEntity 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