Search in sources :

Example 11 with WorkForm

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WorkForm(org.orcid.pojo.ajaxForm.WorkForm) HttpSession(javax.servlet.http.HttpSession) WorkFormTest(orcid.pojo.ajaxForm.WorkFormTest) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 12 with WorkForm

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WorkForm(org.orcid.pojo.ajaxForm.WorkForm) HttpSession(javax.servlet.http.HttpSession) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) WorkFormTest(orcid.pojo.ajaxForm.WorkFormTest) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 13 with WorkForm

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());
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 14 with WorkForm

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;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with WorkForm

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);
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Aggregations

WorkForm (org.orcid.pojo.ajaxForm.WorkForm)20 Test (org.junit.Test)12 Work (org.orcid.jaxb.model.record_v2.Work)9 WorkFormTest (orcid.pojo.ajaxForm.WorkFormTest)6 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ArrayList (java.util.ArrayList)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 HttpSession (javax.servlet.http.HttpSession)4 Contributor (org.orcid.pojo.ajaxForm.Contributor)4 WorkExternalIdentifier (org.orcid.pojo.ajaxForm.WorkExternalIdentifier)4 HashMap (java.util.HashMap)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 Text (org.orcid.pojo.ajaxForm.Text)3 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1