Search in sources :

Example 16 with WorkForm

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;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with WorkForm

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;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) 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 18 with WorkForm

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

Example 19 with WorkForm

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

Example 20 with WorkForm

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

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