use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksController method getWorkInfo.
/**
* Returns a blank work
*/
@RequestMapping(value = "/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@RequestParam(value = "workId") Long workId) {
Map<String, String> countries = retrieveIsoCountries();
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
if (workId == null)
return null;
Work work = workManager.getWork(this.getEffectiveUserOrcid(), workId);
if (work != null) {
WorkForm workForm = WorkForm.valueOf(work);
if (workForm.getPublicationDate() == null) {
initializePublicationDate(workForm);
} else {
if (workForm.getPublicationDate().getDay() == null) {
workForm.getPublicationDate().setDay(new String());
}
if (workForm.getPublicationDate().getMonth() == null) {
workForm.getPublicationDate().setMonth(new String());
}
if (workForm.getPublicationDate().getYear() == null) {
workForm.getPublicationDate().setYear(new String());
}
}
// Set country name
if (!PojoUtil.isEmpty(workForm.getCountryCode())) {
Text countryName = Text.valueOf(countries.get(workForm.getCountryCode().getValue()));
workForm.setCountryName(countryName);
}
// Set language name
if (!PojoUtil.isEmpty(workForm.getLanguageCode())) {
Text languageName = Text.valueOf(languages.get(workForm.getLanguageCode().getValue()));
workForm.setLanguageName(languageName);
}
// Set translated title language name
if (!(workForm.getTranslatedTitle() == null) && !StringUtils.isEmpty(workForm.getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(workForm.getTranslatedTitle().getLanguageCode());
workForm.getTranslatedTitle().setLanguageName(languageName);
}
if (workForm.getContributors() != null) {
for (Contributor contributor : workForm.getContributors()) {
if (!PojoUtil.isEmpty(contributor.getOrcid())) {
String contributorOrcid = contributor.getOrcid().getValue();
if (profileEntityManager.orcidExists(contributorOrcid)) {
// contributor is an ORCID user - visibility of user's name in record must be taken into account
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
String publicContributorCreditName = activityManager.getPublicCreditName(profileEntity);
contributor.setCreditName(Text.valueOf(publicContributorCreditName));
}
}
}
}
return workForm;
}
return null;
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksPaginatorTest method testGetWorkWithNulltitle.
/**
* Check null titles don't cause errors
*/
@Test
public void testGetWorkWithNulltitle() {
WorkGroup workGroup = getPublicWorkGroup(0);
for (WorkSummary workSummary : workGroup.getWorkSummary()) {
workSummary.setTitle(null);
}
Works works = new Works();
works.getWorkGroup().add(workGroup);
Mockito.when(worksCacheManager.getGroupedWorks(Mockito.anyString())).thenReturn(works);
WorksPage page = worksPaginator.getAllWorks("orcid", WorksPaginator.TITLE_SORT_KEY, true);
for (org.orcid.pojo.WorkGroup group : page.getWorkGroups()) {
for (WorkForm work : group.getWorks()) {
assertEquals("", work.getTitle().getValue());
}
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorkFormTest method testValueOfAndBack.
@Test
public void testValueOfAndBack() throws Exception {
Work work = getWork();
WorkForm workForm = WorkForm.valueOf(work);
Work backToWork = workForm.toWork();
assertEquals(work, backToWork);
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorkFormTest method getWork.
public static Work getWork() {
Work work = new Work();
work.setCountry(new Country(Iso3166Country.US));
Date date = new Date();
work.setCreatedDate(new CreatedDate(DateUtils.convertToXMLGregorianCalendar(date)));
work.setJournalTitle(new Title("Journal Title"));
work.setLanguageCode("EN");
work.setPublicationDate(new PublicationDate(new Year(2015), new Month(1), new Day(1)));
work.setPutCode(Long.valueOf("12345"));
work.setShortDescription("Short description");
work.setUrl(new Url("http://test.com"));
work.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED);
work.setWorkCitation(new org.orcid.jaxb.model.v3.dev1.record.Citation("Citation", CitationType.BIBTEX));
WorkContributors contributors = new WorkContributors();
org.orcid.jaxb.model.v3.dev1.common.Contributor contributor = new org.orcid.jaxb.model.v3.dev1.common.Contributor();
contributor.setCreditName(new CreditName("Credit name"));
contributor.setContributorOrcid(new ContributorOrcid("0000-0000-0000-0000"));
ContributorAttributes att = new ContributorAttributes();
att.setContributorRole(ContributorRole.ASSIGNEE);
att.setContributorSequence(SequenceType.FIRST);
contributor.setContributorAttributes(att);
contributors.getContributor().add(contributor);
work.setWorkContributors(contributors);
ExternalIDs weis = new ExternalIDs();
ExternalID wei = new ExternalID();
wei.setRelationship(Relationship.SELF);
wei.setUrl(new Url("http://test.com"));
wei.setValue("ID");
wei.setType(WorkExternalIdentifierType.AGR.value());
weis.getExternalIdentifier().add(wei);
work.setWorkExternalIdentifiers(weis);
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title("Work Title"));
workTitle.setSubtitle(new Subtitle("Subtitle"));
TranslatedTitle translated = new TranslatedTitle("Translated", "US");
workTitle.setTranslatedTitle(translated);
work.setWorkTitle(workTitle);
work.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
return work;
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorkFormTest method testSerializeWork.
@Test
public void testSerializeWork() throws Exception {
Work work = getWork();
WorkForm workForm = WorkForm.valueOf(work);
MemoryEfficientByteArrayOutputStream.serialize(workForm);
}
Aggregations