use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method getWorkEntities.
private SortedSet<WorkEntity> getWorkEntities(ProfileEntity profileEntity, OrcidWorks orcidWorks) {
SortedSet<WorkEntity> existingWorkEntities = profileEntity.getWorks();
Map<String, WorkEntity> existingWorkEntitiesMap = createWorkEntitiesMap(existingWorkEntities);
SortedSet<WorkEntity> workEntities = null;
if (existingWorkEntities == null) {
workEntities = new TreeSet<WorkEntity>();
} else {
// To allow for orphan deletion
existingWorkEntities.clear();
workEntities = existingWorkEntities;
}
if (orcidWorks != null && orcidWorks.getOrcidWork() != null && !orcidWorks.getOrcidWork().isEmpty()) {
List<OrcidWork> orcidWorkList = orcidWorks.getOrcidWork();
for (OrcidWork orcidWork : orcidWorkList) {
WorkEntity workEntity = getWorkEntity(orcidWork, existingWorkEntitiesMap.get(orcidWork.getPutCode()));
if (workEntity != null) {
workEntity.setProfile(profileEntity);
workEntities.add(workEntity);
}
}
}
return workEntities;
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method checkForAlreadyExistingWorks.
private void checkForAlreadyExistingWorks(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
long workId = Long.valueOf(orcidWork.getPutCode());
WorkEntity workEntity = workDao.find(workId);
workEntity.clean();
workEntity = jaxb2JpaAdapter.getWorkEntity(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.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class JpaJaxbWorkAdapterTest method fromProfileWorkEntityToWorkTest.
@Test
public void fromProfileWorkEntityToWorkTest() {
// Set base url to https to ensure source URI is converted to http
orcidUrlManager.setBaseUrl("https://testserver.orcid.org");
WorkEntity work = getWorkEntity();
assertNotNull(work);
Work w = jpaJaxbWorkAdapter.toWork(work);
assertNotNull(w);
assertNotNull(w.getCreatedDate());
assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getCreatedDate().getValue()));
assertNotNull(w.getLastModifiedDate());
assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getLastModifiedDate().getValue()));
assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.CR.value(), w.getCountry().getValue().value());
assertEquals("work:citation", w.getWorkCitation().getCitation());
assertEquals("work:description", w.getShortDescription());
assertEquals("work:journalTitle", w.getJournalTitle().getContent());
assertEquals(CitationType.BIBTEX.value(), w.getWorkCitation().getWorkCitationType().value());
assertEquals(Long.valueOf(12345), w.getPutCode());
assertEquals(Visibility.LIMITED.value(), w.getVisibility().value());
assertEquals("work:title", w.getWorkTitle().getTitle().getContent());
assertEquals("work:subtitle", w.getWorkTitle().getSubtitle().getContent());
assertEquals("work:translatedTitle", w.getWorkTitle().getTranslatedTitle().getContent());
assertEquals("ES", w.getWorkTitle().getTranslatedTitle().getLanguageCode());
assertEquals(WorkType.ARTISTIC_PERFORMANCE.value(), w.getWorkType().value());
assertNotNull(w.getWorkExternalIdentifiers());
assertNotNull(w.getWorkExternalIdentifiers().getExternalIdentifier());
assertEquals(1, w.getWorkExternalIdentifiers().getExternalIdentifier().size());
ExternalID workExtId = w.getWorkExternalIdentifiers().getExternalIdentifier().get(0);
assertNotNull(workExtId.getValue());
assertEquals("123", workExtId.getValue());
assertNotNull(workExtId.getType());
assertEquals(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value(), workExtId.getType());
String sourcePath = w.getSource().retrieveSourcePath();
assertNotNull(sourcePath);
assertEquals("APP-5555555555555555", sourcePath);
// Identifier URIs should always be http, event if base url is https
assertEquals("http://testserver.orcid.org/client/APP-5555555555555555", w.getSource().retriveSourceUri());
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class JpaJaxbWorkAdapterTest method getWorkEntity.
private WorkEntity getWorkEntity() {
Date date = DateUtils.convertToDate("2015-06-05T10:15:20");
WorkEntity work = new WorkEntity();
work.setDateCreated(date);
work.setLastModified(date);
work.setProfile(new ProfileEntity("0000-0000-0000-0001"));
work.setVisibility(Visibility.LIMITED);
work.setDisplayIndex(1234567890L);
work.setClientSourceId("APP-5555555555555555");
work.setCitation("work:citation");
work.setCitationType(CitationType.BIBTEX);
work.setDateCreated(date);
work.setDescription("work:description");
work.setId(12345L);
work.setIso2Country(Iso3166Country.CR);
work.setJournalTitle("work:journalTitle");
work.setLanguageCode("EN");
work.setLastModified(date);
work.setPublicationDate(new PublicationDateEntity(2000, 1, 1));
work.setSubtitle("work:subtitle");
work.setTitle("work:title");
work.setTranslatedTitle("work:translatedTitle");
work.setTranslatedTitleLanguageCode("ES");
work.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
work.setWorkUrl("work:url");
work.setContributorsJson("{\"contributor\":[]}");
work.setExternalIdentifiersJson("{\"workExternalIdentifier\":[{\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"123\"}}]}");
return work;
}
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));
}
Aggregations