use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method persistAddedWorks.
private void persistAddedWorks(String orcid, List<OrcidWork> updatedOrcidWorksList) {
for (OrcidWork updatedOrcidWork : updatedOrcidWorksList) {
populateContributorInfo(updatedOrcidWork);
// Create the work entity
WorkEntity workEntity = jaxb2JpaAdapter.getWorkEntity(orcid, updatedOrcidWork, null);
workDao.persist(workEntity);
updatedOrcidWork.setPutCode(String.valueOf(workEntity.getId()));
}
orcidProfileCacheManager.remove(orcid);
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method checkForAlreadyExistingWorks.
private void checkForAlreadyExistingWorks(String orcid, OrcidWorks existingOrcidWorks, List<OrcidWork> updatedOrcidWorksList) {
if (existingOrcidWorks != null) {
Set<OrcidWork> existingOrcidWorksSet = new HashSet<>();
for (OrcidWork existingWork : existingOrcidWorks.getOrcidWork()) {
existingOrcidWorksSet.add(existingWork);
}
for (Iterator<OrcidWork> updatedWorkIterator = updatedOrcidWorksList.iterator(); updatedWorkIterator.hasNext(); ) {
OrcidWork updatedWork = updatedWorkIterator.next();
for (OrcidWork orcidWork : existingOrcidWorksSet) {
if (orcidWork.isDuplicated(updatedWork)) {
// Update the existing work
WorkEntity workEntity = workDao.find(Long.valueOf(orcidWork.getPutCode()));
workEntity.clean();
workEntity = jaxb2JpaAdapter.getWorkEntity(orcid, updatedWork, workEntity);
workDao.persist(workEntity);
// Since it was already updated, remove it from the list
// of updated works
updatedWorkIterator.remove();
break;
}
}
}
}
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method getOrcidWork.
private OrcidWork getOrcidWork(String workName, boolean isExistingWork) {
OrcidWork orcidWork = new OrcidWork();
if (isExistingWork) {
orcidWork.setPutCode(String.valueOf(currentWorkId));
currentWorkId += 1;
}
// Set title
WorkTitle title = new WorkTitle();
if (isExistingWork)
title.setTitle(new Title("Title for " + workName));
else
title.setTitle(new Title("Title for " + workName + "->updated"));
orcidWork.setWorkTitle(title);
// Set source
Source workSource = new Source(TEST_ORCID);
orcidWork.setSource(workSource);
// Set external identifiers
WorkExternalIdentifier extId1 = new WorkExternalIdentifier();
extId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("doi-" + workName));
extId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
WorkExternalIdentifier extId2 = new WorkExternalIdentifier();
if (isExistingWork)
extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + workName));
else
extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + workName + "->updated"));
extId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.ISSN);
WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
extIds.getWorkExternalIdentifier().add(extId1);
extIds.getWorkExternalIdentifier().add(extId2);
orcidWork.setWorkExternalIdentifiers(extIds);
return orcidWork;
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testCheckWorkExternalIdentifiersAreNotDuplicated1.
@Test
@Transactional
public void testCheckWorkExternalIdentifiersAreNotDuplicated1() {
List<OrcidWork> newOrcidWorksList = new ArrayList<OrcidWork>();
List<OrcidWork> existingWorkList = new ArrayList<OrcidWork>();
OrcidWork newWork1 = getOrcidWork("work1", false);
OrcidWork newWork2 = getOrcidWork("work2", false);
OrcidWork existingWork4 = getOrcidWork("work4", true);
OrcidWork existingWork5 = getOrcidWork("work5", true);
// Check no duplicates at all
newOrcidWorksList.add(newWork1);
newOrcidWorksList.add(newWork2);
existingWorkList.add(existingWork4);
existingWorkList.add(existingWork5);
try {
orcidProfileManager.checkWorkExternalIdentifiersAreNotDuplicated(newOrcidWorksList, existingWorkList);
} catch (Exception e) {
fail();
}
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testCheckWorkExternalIdentifiersAreNotDuplicated3.
@Test
@Transactional
public void testCheckWorkExternalIdentifiersAreNotDuplicated3() {
List<OrcidWork> newOrcidWorksList = new ArrayList<OrcidWork>();
List<OrcidWork> existingWorkList = new ArrayList<OrcidWork>();
OrcidWork newWork1 = getOrcidWork("work1", false);
OrcidWork newWork2 = getOrcidWork("work2", false);
OrcidWork newWork3 = getOrcidWork("work3", false);
OrcidWork newWork3_fixed = getOrcidWork("work3", false);
WorkTitle updatedTitle = new WorkTitle();
updatedTitle.setTitle(new Title("updated title"));
newWork3_fixed.setWorkTitle(updatedTitle);
// Check #3: Check duplicates in new works
newOrcidWorksList.add(newWork1);
newOrcidWorksList.add(newWork2);
newOrcidWorksList.add(newWork3);
newOrcidWorksList.add(newWork3_fixed);
try {
orcidProfileManager.checkWorkExternalIdentifiersAreNotDuplicated(newOrcidWorksList, existingWorkList);
fail();
} catch (IllegalArgumentException iae) {
assertEquals("Works \"Title for work3->updated\" and \"updated title\" have the same external id \"doi-work3\"", iae.getMessage());
}
}
Aggregations