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 JpaJaxbEntityAdapterToProfileEntityTest method testToProfileEntity.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testToProfileEntity() throws JAXBException {
OrcidMessage orcidMessage = getOrcidMessage(ORCID_PROTECTED_FULL_XML);
ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
assertNotNull(profileEntity);
profileDao.persist(profileEntity);
ProfileEntity retrievedProfileEntity = profileDao.find(orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath());
assertNotNull(retrievedProfileEntity);
assertEquals("Josiah", retrievedProfileEntity.getRecordNameEntity().getGivenNames());
// Check all email visibility and values
Set<EmailEntity> emails = profileEntity.getEmails();
assertNotNull(emails);
assertEquals(2, emails.size());
Map<String, EmailEntity> emailMap = EmailEntity.mapById(emails);
EmailEntity primaryEmail = emailMap.get("josiah_carberry@brown.edu");
assertNotNull(primaryEmail);
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, primaryEmail.getVisibility());
assertTrue(primaryEmail.getPrimary());
assertTrue(primaryEmail.getCurrent());
assertTrue(primaryEmail.getVerified());
assertEquals("4444-4444-4444-4446", primaryEmail.getElementSourceId());
EmailEntity nonPrimaryEmail1 = emailMap.get("josiah_carberry_1@brown.edu");
assertNotNull(nonPrimaryEmail1);
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, nonPrimaryEmail1.getVisibility());
assertFalse(nonPrimaryEmail1.getPrimary());
assertTrue(nonPrimaryEmail1.getCurrent());
assertFalse(nonPrimaryEmail1.getVerified());
assertEquals("4444-4444-4444-4446", nonPrimaryEmail1.getElementSourceId());
Set<WorkEntity> workEntities = profileEntity.getWorks();
assertEquals(3, workEntities.size());
for (WorkEntity workEntity : workEntities) {
String contributorsJson = workEntity.getContributorsJson();
if ("Work title 1".equals(workEntity.getTitle())) {
assertEquals("Journal Title # 1", workEntity.getJournalTitle());
assertNotNull(contributorsJson);
assertTrue(contributorsJson.startsWith("{\"contributor\":[{\""));
Map<String, Object> mappedJson = JsonUtils.<HashMap>readObjectFromJsonString(contributorsJson, HashMap.class);
List<Map<String, Object>> contributorsList = (List<Map<String, Object>>) mappedJson.get("contributor");
Map<String, Object> contributor0 = contributorsList.get(0);
assertEquals(4, contributor0.keySet().size());
Map<String, Object> contributorOrcid0 = (Map<String, Object>) contributor0.get("contributorOrcid");
assertEquals("http://orcid.org/4444-4444-4444-4446", contributorOrcid0.get("uri"));
assertEquals("4444-4444-4444-4446", contributorOrcid0.get("path"));
assertEquals("orcid.org", contributorOrcid0.get("host"));
assertTrue(contributorOrcid0.containsKey("value"));
assertNull(contributorOrcid0.get("value"));
assertTrue(contributorOrcid0.containsKey("valueAsString"));
assertNull(contributorOrcid0.get("valueAsString"));
assertTrue(contributor0.containsKey("creditName"));
assertNull(contributor0.get("creditName"));
assertTrue(contributor0.containsKey("contributorEmail"));
assertNull(contributor0.get("contributorEmail"));
Map<String, Object> contributorAttributes0 = (Map<String, Object>) contributor0.get("contributorAttributes");
assertNotNull(contributorAttributes0);
assertEquals("FIRST", contributorAttributes0.get("contributorSequence"));
assertEquals("AUTHOR", contributorAttributes0.get("contributorRole"));
Map<String, Object> contributor1 = contributorsList.get(1);
assertEquals(4, contributor1.keySet().size());
assertTrue(contributor1.containsKey("contributorOrcid"));
assertNull(contributor1.get("contributorOrcid"));
assertEquals("John W. Spaeth", ((Map<String, Object>) contributor1.get("creditName")).get("content"));
assertEquals("PUBLIC", ((Map<String, Object>) contributor1.get("creditName")).get("visibility"));
assertTrue(contributor1.containsKey("contributorEmail"));
assertNull(contributor1.get("contributorEmail"));
assertTrue(contributor1.containsKey("contributorAttributes"));
assertNull(contributor1.get("contributorAttributes"));
} else if (workEntity.getTitle().equals("Work title 2")) {
assertNull(contributorsJson);
assertEquals("Journal Title # 2", workEntity.getJournalTitle());
} else {
assertNull(contributorsJson);
assertNull(workEntity.getJournalTitle());
}
}
assertEquals(2, profileEntity.getProfileFunding().size());
for (ProfileFundingEntity profileGrantEntity : profileEntity.getProfileFunding()) {
assertNotNull(profileGrantEntity.getContributorsJson());
}
assertNull(profileEntity.getGivenPermissionBy());
}
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());
}
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 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