Search in sources :

Example 36 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class JpaJaxbEntityAdapterToProfileEntityTest method testReligiousTextConvertedFromBible.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testReligiousTextConvertedFromBible() throws Exception {
    OrcidMessage orcidMessage = getOrcidMessage(ORCID_INTERNAL_FULL_XML);
    List<OrcidWork> currentOrcidWorks = orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork();
    assertTrue(currentOrcidWorks.size() == 1);
    currentOrcidWorks.get(0).setWorkType(WorkType.DATA_SET);
    ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
    List<WorkEntity> works = new ArrayList<WorkEntity>(profileEntity.getWorks());
    assertEquals(1, works.size());
    assertTrue(works.get(0).getWorkType().equals(org.orcid.jaxb.model.record_v2.WorkType.DATA_SET));
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkEntityFactory method create.

@Override
public NotificationWorkEntity create(Object source, MappingContext mappingContext) {
    mappingContext.getSourceObjects();
    NotificationWorkEntity nwe = new NotificationWorkEntity();
    String putCode = ((Item) source).getPutCode();
    if (putCode != null) {
        WorkEntity work = workDao.find(Long.valueOf(putCode));
        nwe.setWork(work);
    }
    return nwe;
}
Also used : NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity)

Example 38 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkDaoImpl method editWork.

@Override
@Transactional
public WorkEntity editWork(WorkEntity updatedWork) {
    WorkEntity workToUpdate = this.find(updatedWork.getId());
    mergeWork(workToUpdate, updatedWork);
    workToUpdate = this.merge(workToUpdate);
    return workToUpdate;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class DeleteWorkByIdentifier method deleteAll.

private void deleteAll(File orcidsToDelete) {
    GenericDao<WorkEntity, Long> workDao = createWorkDao();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(orcidsToDelete);
    } catch (FileNotFoundException e) {
        if (!orcidsToDelete.exists()) {
            System.err.println("Input file does not exist: " + orcidsToDelete);
            return;
        }
        if (!orcidsToDelete.canRead()) {
            System.err.println("Input exists, but can't read: " + orcidsToDelete);
            return;
        }
        System.err.println("Unable to read input file: " + orcidsToDelete + "\n" + e);
        return;
    }
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        String line = null;
        try {
            while ((line = br.readLine()) != null) {
                workDao.remove(Long.valueOf(line.trim()));
            }
        } catch (IOException e) {
            throw new RuntimeException("Error reading from: " + orcidsToDelete, e);
        }
        br.close();
    } catch (IOException e) {
        System.err.println("IOException " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(fis);
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 40 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkManagerReadOnlyImpl method findWorkBulk.

@Override
public WorkBulk findWorkBulk(String orcid, String putCodesAsString, long profileLastModified) {
    List<BulkElement> works = new ArrayList<>();
    String[] putCodes = getPutCodeArray(putCodesAsString);
    for (String putCode : putCodes) {
        try {
            Long id = Long.valueOf(putCode);
            WorkEntity workEntity = workEntityCacheManager.retrieveFullWork(orcid, id, profileLastModified);
            works.add(jpaJaxbWorkAdapter.toWork(workEntity));
        } catch (Exception e) {
            works.add(orcidCoreExceptionMapper.getOrcidError(new PutCodeFormatException("'" + putCode + "' is not a valid put code")));
        }
    }
    WorkBulk bulk = new WorkBulk();
    bulk.setBulk(works);
    return bulk;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ArrayList(java.util.ArrayList) ExceedMaxNumberOfPutCodesException(org.orcid.core.exception.ExceedMaxNumberOfPutCodesException) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException)

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