use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class OrcidInfo method getWorkInfo.
/**
* Returns the work info for a given work id
*
* @param workId
* The id of the work
* @return the content of that work
*/
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@PathVariable("orcid") String orcid, @RequestParam(value = "workId") Long workId) {
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
if (workId == null)
return null;
Work workObj = workManager.getWork(orcid, workId, profileEntManager.getLastModified(orcid));
if (workObj != null) {
validateVisibility(workObj.getVisibility());
sourceUtils.setSourceName(workObj);
WorkForm work = WorkForm.valueOf(workObj);
// Set country name
if (!PojoUtil.isEmpty(work.getCountryCode())) {
Text countryName = Text.valueOf(retrieveIsoCountries().get(work.getCountryCode().getValue()));
work.setCountryName(countryName);
}
// Set language name
if (!PojoUtil.isEmpty(work.getLanguageCode())) {
Text languageName = Text.valueOf(languages.get(work.getLanguageCode().getValue()));
work.setLanguageName(languageName);
}
// Set translated title language name
if (work.getTranslatedTitle() != null && !StringUtils.isEmpty(work.getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(work.getTranslatedTitle().getLanguageCode());
work.getTranslatedTitle().setLanguageName(languageName);
}
if (work.getContributors() != null) {
for (Contributor contributor : work.getContributors()) {
if (!PojoUtil.isEmpty(contributor.getOrcid())) {
String contributorOrcid = contributor.getOrcid().getValue();
if (profileEntManager.orcidExists(contributorOrcid)) {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
String publicContributorCreditName = activityCacheManager.getPublicCreditName(profileEntity);
contributor.setCreditName(Text.valueOf(publicContributorCreditName));
}
}
}
}
return work;
}
return null;
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class OrcidInfo method getWorkJson.
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/works.json")
@ResponseBody
public List<WorkForm> getWorkJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "workIds") String workIdsStr) {
Map<String, String> countries = retrieveIsoCountries();
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
HashMap<Long, WorkForm> minimizedWorksMap = activityCacheManager.pubMinWorksMap(orcid, getLastModifiedTime(orcid));
List<WorkForm> works = new ArrayList<WorkForm>();
String[] workIds = workIdsStr.split(",");
for (String workId : workIds) {
if (minimizedWorksMap.containsKey(Long.valueOf(workId))) {
WorkForm work = minimizedWorksMap.get(Long.valueOf(workId));
validateVisibility(work.getVisibility());
if (!PojoUtil.isEmpty(work.getCountryCode())) {
Text countryName = Text.valueOf(countries.get(work.getCountryCode().getValue()));
work.setCountryName(countryName);
}
// Set language name
if (!PojoUtil.isEmpty(work.getLanguageCode())) {
Text languageName = Text.valueOf(languages.get(work.getLanguageCode().getValue()));
work.setLanguageName(languageName);
}
// Set translated title language name
if (work.getTranslatedTitle() != null && !StringUtils.isEmpty(work.getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(work.getTranslatedTitle().getLanguageCode());
work.getTranslatedTitle().setLanguageName(languageName);
}
works.add(work);
}
}
return works;
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksControllerTest method testFieldValidators.
@Test
public void testFieldValidators() throws Exception {
Work work = WorkFormTest.getWork();
WorkForm workForm = WorkForm.valueOf(work);
worksController.workTitleValidate(workForm);
assertEquals(0, workForm.getTitle().getErrors().size());
worksController.workSubtitleValidate(workForm);
assertEquals(0, workForm.getSubtitle().getErrors().size());
worksController.workTranslatedTitleValidate(workForm);
assertEquals(0, workForm.getTranslatedTitle().getErrors().size());
worksController.workUrlValidate(workForm);
assertEquals(0, workForm.getUrl().getErrors().size());
worksController.workJournalTitleValidate(workForm);
assertEquals(0, workForm.getJournalTitle().getErrors().size());
worksController.workLanguageCodeValidate(workForm);
assertEquals(0, workForm.getLanguageCode().getErrors().size());
worksController.workdescriptionValidate(workForm);
assertEquals(0, workForm.getShortDescription().getErrors().size());
worksController.workWorkTypeValidate(workForm);
assertEquals(0, workForm.getWorkType().getErrors().size());
worksController.workWorkExternalIdentifiersValidate(workForm);
for (WorkExternalIdentifier wId : workForm.getWorkExternalIdentifiers()) {
assertEquals(0, wId.getWorkExternalIdentifierId().getErrors().size());
assertEquals(0, wId.getWorkExternalIdentifierType().getErrors().size());
}
worksController.workCitationValidate(workForm);
assertEquals(0, workForm.getCitation().getCitation().getErrors().size());
assertEquals(0, workForm.getCitation().getCitationType().getErrors().size());
assertNotNull(workForm.getCountryCode());
assertNotNull(workForm.getCountryCode().getValue());
assertEquals(Iso3166Country.US.value(), workForm.getCountryCode().getValue());
// Set wrong values to each field
workForm.setTitle(Text.valueOf(buildLongWord()));
workForm.setSubtitle(Text.valueOf(buildLongWord()));
workForm.getTranslatedTitle().setContent(buildLongWord());
workForm.getTranslatedTitle().setLanguageCode(buildLongWord());
workForm.getUrl().setValue(buildLongWord());
workForm.getJournalTitle().setValue(buildLongWord());
workForm.getLanguageCode().setValue(buildLongWord());
workForm.getShortDescription().setValue(buildLongWord());
workForm.getWorkType().setValue(new String());
worksController.workTitleValidate(workForm);
assertEquals(1, workForm.getTitle().getErrors().size());
worksController.workSubtitleValidate(workForm);
assertEquals(1, workForm.getSubtitle().getErrors().size());
worksController.workTranslatedTitleValidate(workForm);
assertEquals(2, workForm.getTranslatedTitle().getErrors().size());
worksController.workUrlValidate(workForm);
assertEquals(2, workForm.getUrl().getErrors().size());
worksController.workJournalTitleValidate(workForm);
assertEquals(1, workForm.getJournalTitle().getErrors().size());
worksController.workLanguageCodeValidate(workForm);
assertEquals(1, workForm.getLanguageCode().getErrors().size());
worksController.workdescriptionValidate(workForm);
assertEquals(1, workForm.getShortDescription().getErrors().size());
worksController.workWorkTypeValidate(workForm);
assertEquals(1, workForm.getWorkType().getErrors().size());
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksControllerTest method testUpdateWork.
@Test
public void testUpdateWork() throws Exception {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
WorkForm work = worksController.getWorkInfo(Long.valueOf("6"));
// Set title
work.setTitle(Text.valueOf("Test update work"));
work.setSubtitle(Text.valueOf("Test update subtitle"));
TranslatedTitleForm tTitle = new TranslatedTitleForm();
tTitle.setContent("Test translated title");
tTitle.setLanguageCode("EN");
work.setTranslatedTitle(tTitle);
work.setWorkType(Text.valueOf("artistic-performance"));
work.setWorkExternalIdentifiers(new ArrayList<WorkExternalIdentifier>());
WorkExternalIdentifier wei1 = new WorkExternalIdentifier();
wei1.setWorkExternalIdentifierId(Text.valueOf("1"));
wei1.setWorkExternalIdentifierType(Text.valueOf("doi"));
work.getWorkExternalIdentifiers().add(wei1);
WorkExternalIdentifier wei2 = new WorkExternalIdentifier();
wei2.setWorkExternalIdentifierId(Text.valueOf("2"));
wei2.setWorkExternalIdentifierType(Text.valueOf("arxiv"));
work.getWorkExternalIdentifiers().add(wei2);
work.getPublicationDate().setDay("2");
work.getPublicationDate().setMonth("3");
work.getPublicationDate().setYear("2014");
worksController.validateWork(work);
if (!work.getErrors().isEmpty()) {
work.getErrors().forEach(n -> System.out.println(n));
fail("invalid work update");
}
worksController.postWork(null, work);
WorkForm updatedWork = worksController.getWorkInfo(Long.valueOf("6"));
assertNotNull(updatedWork);
assertEquals("6", updatedWork.getPutCode().getValue());
assertEquals("Test update work", updatedWork.getTitle().getValue());
assertEquals("Test update subtitle", updatedWork.getSubtitle().getValue());
assertEquals("Test translated title", updatedWork.getTranslatedTitle().getContent());
assertEquals("EN", updatedWork.getTranslatedTitle().getLanguageCode());
assertNotNull(updatedWork.getWorkExternalIdentifiers());
assertEquals(2, updatedWork.getWorkExternalIdentifiers().size());
List<WorkExternalIdentifier> extIds = updatedWork.getWorkExternalIdentifiers();
for (WorkExternalIdentifier extId : extIds) {
if (extId.getWorkExternalIdentifierType().getValue().equals("doi") || extId.getWorkExternalIdentifierType().getValue().equals("arxiv")) {
if (extId.getWorkExternalIdentifierType().getValue().equals("doi")) {
assertEquals("1", extId.getWorkExternalIdentifierId().getValue());
} else {
assertEquals("2", extId.getWorkExternalIdentifierId().getValue());
}
} else {
fail("Invalid external identifier found: " + extId.getWorkExternalIdentifierType().getValue() + " : " + extId.getWorkExternalIdentifierId().getValue());
}
}
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksControllerTest method testGetWorkInfo.
@Test
public void testGetWorkInfo() {
WorkForm work = worksController.getWorkInfo(Long.valueOf("5"));
assertNotNull(work);
assertEquals("5", work.getPutCode().getValue());
assertNotNull(work.getPublicationDate());
assertEquals("2011", work.getPublicationDate().getYear());
assertEquals("02", work.getPublicationDate().getMonth());
assertEquals("01", work.getPublicationDate().getDay());
assertNotNull(work.getTitle());
assertEquals("Journal article A", work.getTitle().getValue());
assertNotNull(work.getVisibility());
assertEquals(Visibility.PUBLIC, work.getVisibility());
assertEquals("journal-article", work.getWorkType().getValue());
}
Aggregations