Search in sources :

Example 51 with WorkEntity

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);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExceedMaxNumberOfElementsException(org.orcid.core.exception.ExceedMaxNumberOfElementsException) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with 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;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) ExceedMaxNumberOfElementsException(org.orcid.core.exception.ExceedMaxNumberOfElementsException)

Example 53 with WorkEntity

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;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) WorkLastModifiedEntity(org.orcid.persistence.jpa.entities.WorkLastModifiedEntity) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ArrayList(java.util.ArrayList)

Example 54 with WorkEntity

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);
            }
        }
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ApplicationException(org.orcid.core.exception.ApplicationException) HashMap(java.util.HashMap) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ApplicationException(org.orcid.core.exception.ApplicationException) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) PublicationDate(org.orcid.jaxb.model.message.PublicationDate) DeactivationDate(org.orcid.jaxb.model.message.DeactivationDate)

Example 55 with WorkEntity

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)57 Test (org.junit.Test)22 MinimizedWorkEntity (org.orcid.persistence.jpa.entities.MinimizedWorkEntity)20 Date (java.util.Date)15 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 Work (org.orcid.jaxb.model.v3.dev1.record.Work)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Work (org.orcid.jaxb.model.record_v2.Work)9 ArrayList (java.util.ArrayList)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 BaseTest (org.orcid.core.BaseTest)7 ExceedMaxNumberOfElementsException (org.orcid.core.exception.ExceedMaxNumberOfElementsException)6 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 PublicationDateEntity (org.orcid.persistence.jpa.entities.PublicationDateEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)5 HashMap (java.util.HashMap)4 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4