use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksControllerTest method testEditOtherSourceThrowsError.
@Test
public void testEditOtherSourceThrowsError() throws Exception {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
WorkForm work = worksController.getWorkInfo(Long.valueOf("7"));
boolean throwsError = false;
try {
worksController.postWork(null, work);
} catch (Exception e) {
throwsError = true;
}
assertTrue(throwsError);
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksControllerTest method testAddWork.
@Test
public void testAddWork() throws Exception {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
WorkForm work = worksController.getWork(null);
// Set title
work.setTitle(Text.valueOf("Test add work"));
work.setWorkType(Text.valueOf("artistic-performance"));
WorkExternalIdentifier wei = work.getWorkExternalIdentifiers().get(0);
wei.setWorkExternalIdentifierId(Text.valueOf("1"));
wei.setWorkExternalIdentifierType(Text.valueOf("doi"));
if (!PojoUtil.isEmpty(work.getPutCode())) {
work.setPutCode(Text.valueOf(""));
}
if (work.getCitation() != null && work.getCitation().getCitation() != null && PojoUtil.isEmpty(work.getCitation().getCitation())) {
work.getCitation().getCitation().setValue("test");
}
work = worksController.postWork(null, work);
assertNotNull(work);
assertFalse(PojoUtil.isEmpty(work.getPutCode()));
assertEquals(1, work.getWorkExternalIdentifiers().size());
assertEquals("doi", work.getWorkExternalIdentifiers().get(0).getWorkExternalIdentifierType().getValue());
assertEquals("1", work.getWorkExternalIdentifiers().get(0).getWorkExternalIdentifierId().getValue());
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorkFormTest method testEmptyTranslatedTitleDontGetIntoTheWork.
@Test
public void testEmptyTranslatedTitleDontGetIntoTheWork() {
WorkForm form = new WorkForm();
form.setTitle(Text.valueOf("The title"));
org.orcid.pojo.ajaxForm.TranslatedTitleForm translatedTitle = new org.orcid.pojo.ajaxForm.TranslatedTitleForm();
//Test with empty values
translatedTitle.setContent(" ");
translatedTitle.setLanguageCode(" ");
form.setTranslatedTitle(translatedTitle);
Work work = form.toWork();
assertNotNull(work);
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("The title", work.getWorkTitle().getTitle().getContent());
assertNull(work.getWorkTitle().getTranslatedTitle());
//Test with empty content
translatedTitle.setContent(" ");
translatedTitle.setLanguageCode("en");
form.setTranslatedTitle(translatedTitle);
work = form.toWork();
assertNotNull(work);
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("The title", work.getWorkTitle().getTitle().getContent());
assertNull(work.getWorkTitle().getTranslatedTitle());
//Test with empty strings
translatedTitle.setContent("");
translatedTitle.setLanguageCode("");
form.setTranslatedTitle(translatedTitle);
work = form.toWork();
assertNotNull(work);
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("The title", work.getWorkTitle().getTitle().getContent());
assertNull(work.getWorkTitle().getTranslatedTitle());
//Test with null values
translatedTitle.setContent(null);
translatedTitle.setLanguageCode(null);
form.setTranslatedTitle(translatedTitle);
work = form.toWork();
assertNotNull(work);
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("The title", work.getWorkTitle().getTitle().getContent());
assertNull(work.getWorkTitle().getTranslatedTitle());
//Test with a both values
translatedTitle.setContent("Translated title");
translatedTitle.setLanguageCode("en");
form.setTranslatedTitle(translatedTitle);
work = form.toWork();
assertNotNull(work);
assertNotNull(work.getWorkTitle());
assertNotNull(work.getWorkTitle().getTitle());
assertEquals("The title", work.getWorkTitle().getTitle().getContent());
assertNotNull(work.getWorkTitle().getTranslatedTitle());
assertEquals("Translated title", work.getWorkTitle().getTranslatedTitle().getContent());
assertEquals("en", work.getWorkTitle().getTranslatedTitle().getLanguageCode());
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorksController method getWorkJson.
/**
* List works associated with a profile
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "/works.json", method = RequestMethod.GET)
@ResponseBody
public List<WorkForm> getWorkJson(HttpServletRequest request, @RequestParam(value = "workIds") String workIdsStr) {
Map<String, String> countries = retrieveIsoCountries();
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
List<WorkForm> workList = new ArrayList<>();
WorkForm work = null;
String[] workIds = workIdsStr.split(",");
if (workIds != null) {
HashMap<String, WorkForm> worksMap = (HashMap<String, WorkForm>) request.getSession().getAttribute(WORKS_MAP);
// this should never happen, but just in case.
if (worksMap == null) {
createWorksIdList(request);
worksMap = (HashMap<String, WorkForm>) request.getSession().getAttribute(WORKS_MAP);
}
for (String workId : workIds) {
work = worksMap.get(Long.valueOf(workId));
// Set country name
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);
}
workList.add(work);
}
}
return workList;
}
use of org.orcid.pojo.ajaxForm.WorkForm in project ORCID-Source by ORCID.
the class WorkFormTest method toWorkTest.
@Test
public void toWorkTest() {
WorkForm form = getWorkForm();
Work work = form.toWork();
assertEquals(getWork(), work);
}
Aggregations