use of org.orcid.persistence.jpa.entities.WorkEntity 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)) {
List<Work> existingWorks = this.findWorks(orcid);
if ((existingWorks.size() + 1) > this.maxNumOfActivities) {
throw new ExceedMaxNumberOfElementsException();
}
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.setOrcid(orcid);
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, createItemList(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerImpl method checkSourceAndRemoveWork.
@Override
public boolean checkSourceAndRemoveWork(String orcid, Long workId) {
boolean result = true;
WorkEntity workEntity = workDao.getWork(orcid, workId);
orcidSecurityManager.checkSource(workEntity);
try {
workDao.removeWork(orcid, workId);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity));
} catch (Exception e) {
LOGGER.error("Unable to delete work with ID: " + workId);
result = false;
}
return result;
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerReadOnlyImpl method findWorks.
@Override
public List<Work> findWorks(String orcid, List<WorkLastModifiedEntity> elements) {
List<Work> result = new ArrayList<Work>();
for (WorkLastModifiedEntity w : elements) {
WorkEntity entity = workEntityCacheManager.retrieveFullWork(orcid, w.getId(), w.getLastModified().getTime());
result.add(jpaJaxbWorkAdapter.toWork(entity));
}
return result;
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setWorks.
@Override
@Deprecated
public void setWorks(ProfileEntity profileEntity, OrcidWorks orcidWorks) {
String orcid = profileEntity.getId();
// Get the existing works
List<WorkEntity> existingWorks = workDao.getWorksByOrcidId(orcid);
Map<Long, WorkEntity> existingWorksMap = new HashMap<Long, WorkEntity>();
// Iterate over the existing list of works and delete the ones that are not in the orcidWorks list
for (WorkEntity entity : existingWorks) {
boolean deleteMe = true;
if (orcidWorks != null && orcidWorks.getOrcidWork() != null) {
for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
if (!PojoUtil.isEmpty(orcidWork.getPutCode()) && entity.getId().equals(Long.valueOf(orcidWork.getPutCode()))) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
workDao.remove(entity.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete work with id " + entity.getId(), e);
}
} else {
existingWorksMap.put(entity.getId(), entity);
}
}
// Iterate over the list of orcidWorks and update the ones that have a put code and insert the ones that doesnt have any put code
if (orcidWorks != null && orcidWorks.getOrcidWork() != null) {
for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
if (!PojoUtil.isEmpty(orcidWork.getPutCode())) {
if (orcidWork.isModified()) {
WorkEntity updatedEntity = getWorkEntity(orcid, orcidWork, existingWorksMap.get(Long.valueOf(orcidWork.getPutCode())));
updatedEntity.setLastModified(new Date());
workDao.merge(updatedEntity);
}
} else {
WorkEntity newEntity = getWorkEntity(orcid, orcidWork, null);
Date now = new Date();
newEntity.setDateCreated(now);
newEntity.setLastModified(now);
workDao.persist(newEntity);
}
}
}
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerTest method testAddMultipleModifiesIndexingStatus.
@Test
public void testAddMultipleModifiesIndexingStatus() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Work w1 = getWork("extId1");
w1 = workManager.createWork(claimedOrcid, w1, true);
Work w2 = getWork("extId2");
w2 = workManager.createWork(claimedOrcid, w2, true);
Work w3 = getWork("extId3");
w3 = workManager.createWork(claimedOrcid, w3, true);
WorkEntity entity1 = workDao.find(w1.getPutCode());
WorkEntity entity2 = workDao.find(w2.getPutCode());
WorkEntity entity3 = workDao.find(w3.getPutCode());
assertNotNull(entity1.getDisplayIndex());
assertNotNull(entity2.getDisplayIndex());
assertNotNull(entity3.getDisplayIndex());
assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
// Rollback all changes
workDao.remove(entity1.getId());
workDao.remove(entity2.getId());
workDao.remove(entity3.getId());
}
Aggregations