use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkDaoTest method testAddWork.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddWork() {
String title = "New Work";
String subtitle = "Subtitle";
String citation = "Test citation";
String description = "Description for new work";
String url = "http://work.com";
WorkEntity work = new WorkEntity();
work.setCitation(citation);
work.setCitationType(CitationType.FORMATTED_UNSPECIFIED);
work.setDescription(description);
work.setTitle(title);
work.setSubtitle(subtitle);
work.setWorkType(WorkType.BOOK);
work.setWorkUrl(url);
ProfileEntity profile = new ProfileEntity(USER_ORCID);
work.setProfile(profile);
work.setSourceId(USER_ORCID);
work.setAddedToProfileDate(new Date());
assertNull(work.getId());
try {
work = workDao.addWork(work);
} catch (Exception e) {
fail();
}
assertNotNull(work.getId());
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method getWorkEntity.
public WorkEntity getWorkEntity(OrcidWork orcidWork, WorkEntity workEntity) {
if (orcidWork != null) {
if (workEntity == null) {
String putCode = orcidWork.getPutCode();
if (StringUtils.isNotBlank(putCode) && !"-1".equals(putCode)) {
throw new IllegalArgumentException("Invalid put-code was supplied: " + putCode);
}
workEntity = new WorkEntity();
} else {
workEntity.clean();
}
Citation workCitation = orcidWork.getWorkCitation();
if (workCitation != null && StringUtils.isNotBlank(workCitation.getCitation()) && workCitation.getWorkCitationType() != null) {
workEntity.setCitation(workCitation.getCitation());
workEntity.setCitationType(CitationType.fromValue(workCitation.getWorkCitationType().value()));
}
// New way of doing work contributors
workEntity.setContributorsJson(getWorkContributorsJson(orcidWork.getWorkContributors()));
workEntity.setDescription(orcidWork.getShortDescription() != null ? orcidWork.getShortDescription() : null);
// New way of doing work external ids
workEntity.setExternalIdentifiersJson(getWorkExternalIdsJson(orcidWork));
workEntity.setPublicationDate(getWorkPublicationDate(orcidWork));
WorkTitle workTitle = orcidWork.getWorkTitle();
if (workTitle != null) {
workEntity.setSubtitle(workTitle.getSubtitle() != null ? workTitle.getSubtitle().getContent() : null);
workEntity.setTitle(workTitle.getTitle() != null ? workTitle.getTitle().getContent().trim() : null);
TranslatedTitle translatedTitle = workTitle.getTranslatedTitle();
if (translatedTitle != null) {
workEntity.setTranslatedTitle(StringUtils.isEmpty(translatedTitle.getContent()) ? null : translatedTitle.getContent());
workEntity.setTranslatedTitleLanguageCode(StringUtils.isEmpty(translatedTitle.getLanguageCode()) ? null : translatedTitle.getLanguageCode());
}
}
workEntity.setJournalTitle(orcidWork.getJournalTitle() != null ? orcidWork.getJournalTitle().getContent() : null);
workEntity.setLanguageCode(orcidWork.getLanguageCode() != null ? orcidWork.getLanguageCode() : null);
if (orcidWork.getCountry() != null && orcidWork.getCountry().getValue() != null) {
workEntity.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(orcidWork.getCountry().getValue().value()));
}
workEntity.setWorkUrl(orcidWork.getUrl() != null ? orcidWork.getUrl().getValue() : null);
if (orcidWork.getWorkType() != null) {
workEntity.setWorkType(org.orcid.jaxb.model.record_v2.WorkType.fromValue(orcidWork.getWorkType().value()));
}
if (orcidWork.getVisibility() != null) {
workEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(orcidWork.getVisibility().value()));
} else {
workEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
workEntity.setAddedToProfileDate(new Date());
//Set source
setSource(orcidWork.getSource(), workEntity);
if (workEntity.getDisplayIndex() == null) {
workEntity.setDisplayIndex(0L);
}
return workEntity;
}
return null;
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerTest method displayIndexIsSetTo_1_FromUI.
@Test
public void displayIndexIsSetTo_1_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Work w1 = getWork("fromUI-1");
w1 = workManager.createWork(claimedOrcid, w1, false);
WorkEntity w = workDao.find(w1.getPutCode());
assertNotNull(w1);
assertEquals(Long.valueOf(1), w.getDisplayIndex());
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class WorkManagerTest method displayIndexIsSetTo_0_FromAPI.
@Test
public void displayIndexIsSetTo_0_FromAPI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Work w1 = getWork("fromAPI-1");
w1 = workManager.createWork(claimedOrcid, w1, true);
WorkEntity w = workDao.find(w1.getPutCode());
assertNotNull(w1);
assertEquals(Long.valueOf(0), w.getDisplayIndex());
}
use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.
the class JpaJaxbWorkAdapterTest method fromProfileWorkEntityToWorkSummaryTest.
@Test
public void fromProfileWorkEntityToWorkSummaryTest() {
WorkEntity work = getWorkEntity();
assertNotNull(work);
WorkSummary ws = jpaJaxbWorkAdapter.toWorkSummary(work);
assertNotNull(ws);
assertEquals(Long.valueOf(12345), ws.getPutCode());
assertEquals(Visibility.LIMITED.value(), ws.getVisibility().value());
assertEquals("1234567890", ws.getDisplayIndex());
assertNotNull(ws.getExternalIdentifiers());
assertNotNull(ws.getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, ws.getExternalIdentifiers().getExternalIdentifier().size());
ExternalID workExtId = ws.getExternalIdentifiers().getExternalIdentifier().get(0);
assertNotNull(workExtId.getValue());
assertEquals("123", workExtId.getValue());
assertNotNull(workExtId.getType());
assertEquals(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value(), workExtId.getType());
}
Aggregations