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));
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations