Search in sources :

Example 11 with WorkExternalIdentifier

use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier 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 12 with WorkExternalIdentifier

use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.

the class PeerReviewsController method getEmptyPeerReview.

/**
     * Returns a blank peer review form
     * */
@RequestMapping(value = "/peer-review.json", method = RequestMethod.GET)
@ResponseBody
public PeerReviewForm getEmptyPeerReview() {
    Date emptyDate = new Date();
    emptyDate.setDay(StringUtils.EMPTY);
    emptyDate.setMonth(StringUtils.EMPTY);
    emptyDate.setYear(StringUtils.EMPTY);
    TranslatedTitleForm emptyTranslatedTitle = new TranslatedTitleForm();
    emptyTranslatedTitle.setErrors(Collections.<String>emptyList());
    emptyTranslatedTitle.setContent(StringUtils.EMPTY);
    emptyTranslatedTitle.setLanguageCode(StringUtils.EMPTY);
    emptyTranslatedTitle.setLanguageName(StringUtils.EMPTY);
    WorkExternalIdentifier emptyExternalId = new WorkExternalIdentifier();
    emptyExternalId.setErrors(new ArrayList<String>());
    emptyExternalId.setWorkExternalIdentifierId(Text.valueOf(StringUtils.EMPTY));
    emptyExternalId.getWorkExternalIdentifierId().setRequired(false);
    emptyExternalId.setWorkExternalIdentifierType(Text.valueOf(StringUtils.EMPTY));
    emptyExternalId.getWorkExternalIdentifierType().setRequired(false);
    emptyExternalId.setRelationship(Text.valueOf(Relationship.SELF.value()));
    emptyExternalId.setUrl(Text.valueOf(StringUtils.EMPTY));
    List<WorkExternalIdentifier> emptyExtIdsList = new ArrayList<WorkExternalIdentifier>();
    emptyExtIdsList.add(emptyExternalId);
    PeerReviewForm form = new PeerReviewForm();
    form.setErrors(Collections.<String>emptyList());
    form.setCompletionDate(emptyDate);
    form.setCreatedDate(emptyDate);
    form.setCity(Text.valueOf(StringUtils.EMPTY));
    form.setRegion(Text.valueOf(StringUtils.EMPTY));
    form.getRegion().setRequired(false);
    form.setCountry(Text.valueOf(StringUtils.EMPTY));
    form.setCountryForDisplay(StringUtils.EMPTY);
    form.setDisambiguationSource(Text.valueOf(StringUtils.EMPTY));
    form.getDisambiguationSource().setRequired(false);
    form.setOrgName(Text.valueOf(StringUtils.EMPTY));
    form.setPutCode(Text.valueOf(StringUtils.EMPTY));
    form.getPutCode().setRequired(false);
    form.setRole(Text.valueOf(Role.REVIEWER.value()));
    form.setType(Text.valueOf(PeerReviewType.REVIEW.value()));
    form.setUrl(Text.valueOf(StringUtils.EMPTY));
    form.getUrl().setRequired(false);
    form.setExternalIdentifiers(emptyExtIdsList);
    form.setGroupId(Text.valueOf(StringUtils.EMPTY));
    form.setSubjectContainerName(Text.valueOf(StringUtils.EMPTY));
    form.setSubjectExternalIdentifier(emptyExternalId);
    form.setSubjectName(Text.valueOf(StringUtils.EMPTY));
    form.setSubjectType(Text.valueOf(StringUtils.EMPTY));
    form.setSubjectUrl(Text.valueOf(StringUtils.EMPTY));
    return form;
}
Also used : ArrayList(java.util.ArrayList) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) Date(org.orcid.pojo.ajaxForm.Date) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with WorkExternalIdentifier

use of org.orcid.pojo.ajaxForm.WorkExternalIdentifier in project ORCID-Source by ORCID.

the class PeerReviewsController method removeEmptyExternalIds.

private void removeEmptyExternalIds(PeerReviewForm peerReview) {
    List<WorkExternalIdentifier> extIds = peerReview.getExternalIdentifiers();
    List<WorkExternalIdentifier> updatedExtIds = new ArrayList<WorkExternalIdentifier>();
    if (extIds != null) {
        // For all external identifiers
        for (WorkExternalIdentifier extId : extIds) {
            // Keep only the ones that contains a value or url
            if (!PojoUtil.isEmpty(extId.getWorkExternalIdentifierId())) {
                updatedExtIds.add(extId);
            }
        }
    }
    if (updatedExtIds.isEmpty()) {
        WorkExternalIdentifier wei = new WorkExternalIdentifier();
        updatedExtIds.add(wei);
    }
    peerReview.setExternalIdentifiers(updatedExtIds);
}
Also used : ArrayList(java.util.ArrayList) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier)

Aggregations

WorkExternalIdentifier (org.orcid.pojo.ajaxForm.WorkExternalIdentifier)13 ArrayList (java.util.ArrayList)7 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)5 WorkForm (org.orcid.pojo.ajaxForm.WorkForm)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 WorkFormTest (orcid.pojo.ajaxForm.WorkFormTest)3 Test (org.junit.Test)3 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)3 Date (org.orcid.pojo.ajaxForm.Date)3 PeerReviewForm (org.orcid.pojo.ajaxForm.PeerReviewForm)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 Contributor (org.orcid.pojo.ajaxForm.Contributor)2 Text (org.orcid.pojo.ajaxForm.Text)2 HashMap (java.util.HashMap)1 CreatedDate (org.orcid.jaxb.model.common_v2.CreatedDate)1 FuzzyDate (org.orcid.jaxb.model.common_v2.FuzzyDate)1 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)1 PublicationDate (org.orcid.jaxb.model.common_v2.PublicationDate)1