Search in sources :

Example 6 with WorkExternalIdentifier

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

the class WorksController method validateWork.

@RequestMapping(value = "/workValidate.json", method = RequestMethod.POST)
@ResponseBody
public WorkForm validateWork(@RequestBody WorkForm work) {
    work.setErrors(new ArrayList<String>());
    if (work.getCitation() != null) {
        workCitationValidate(work);
        copyErrors(work.getCitation().getCitationType(), work);
        copyErrors(work.getCitation().getCitation(), work);
    }
    workTitleValidate(work);
    copyErrors(work.getTitle(), work);
    if (work.getSubtitle() != null) {
        workSubtitleValidate(work);
        copyErrors(work.getSubtitle(), work);
    }
    if (work.getTranslatedTitle() != null) {
        workTranslatedTitleValidate(work);
        copyErrors(work.getTranslatedTitle(), work);
    }
    // allowed to be null
    if (work.getShortDescription() != null) {
        workdescriptionValidate(work);
        copyErrors(work.getShortDescription(), work);
    }
    if (work.getWorkCategory() != null)
        workWorkCategoryValidate(work);
    workWorkTypeValidate(work);
    copyErrors(work.getWorkType(), work);
    if (work.getWorkExternalIdentifiers() != null) {
        workWorkExternalIdentifiersValidate(work);
        for (WorkExternalIdentifier wId : work.getWorkExternalIdentifiers()) {
            copyErrors(wId.getWorkExternalIdentifierId(), work);
            copyErrors(wId.getWorkExternalIdentifierType(), work);
        }
    }
    if (work.getUrl() != null) {
        workUrlValidate(work);
        copyErrors(work.getUrl(), work);
    }
    if (work.getJournalTitle() != null) {
        workJournalTitleValidate(work);
        copyErrors(work.getJournalTitle(), work);
    }
    if (work.getPublicationDate() != null) {
        workPublicationDateValidate(work);
        copyErrors(work.getPublicationDate(), work);
    }
    // allowed to be null
    if (work.getLanguageCode() != null) {
        workLanguageCodeValidate(work);
        copyErrors(work.getLanguageCode(), work);
    }
    // null
    if (work.getPutCode() != null) {
        validateWorkId(work);
    }
    return work;
}
Also used : WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with WorkExternalIdentifier

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

the class WorksController method workWorkExternalIdentifiersValidate.

@RequestMapping(value = "/work/workExternalIdentifiersValidate.json", method = RequestMethod.POST)
@ResponseBody
public WorkForm workWorkExternalIdentifiersValidate(@RequestBody WorkForm work) {
    for (WorkExternalIdentifier wId : work.getWorkExternalIdentifiers()) {
        if (wId.getWorkExternalIdentifierId() == null)
            wId.setWorkExternalIdentifierId(new Text());
        if (wId.getWorkExternalIdentifierType() == null)
            wId.setWorkExternalIdentifierType(new Text());
        wId.getWorkExternalIdentifierId().setErrors(new ArrayList<String>());
        wId.getWorkExternalIdentifierType().setErrors(new ArrayList<String>());
        // if has id type must be specified
        if (wId.getWorkExternalIdentifierId().getValue() != null && !wId.getWorkExternalIdentifierId().getValue().trim().equals("") && (wId.getWorkExternalIdentifierType().getValue() == null || wId.getWorkExternalIdentifierType().getValue().equals(""))) {
            setError(wId.getWorkExternalIdentifierType(), "NotBlank.currentWorkExternalIds.idType");
        } else if (wId.getWorkExternalIdentifierId().getValue() != null && wId.getWorkExternalIdentifierId().getValue().length() > 2084) {
            setError(wId.getWorkExternalIdentifierId(), "manualWork.length_less_2084");
        }
        // if type is set a id must set
        if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().equals("") && (wId.getWorkExternalIdentifierId().getValue() == null || wId.getWorkExternalIdentifierId().getValue().trim().equals(""))) {
            setError(wId.getWorkExternalIdentifierId(), "NotBlank.currentWorkExternalIds.id");
        }
        Map<String, IdentifierType> types = identifierTypeManager.fetchIdentifierTypesByAPITypeName(getLocale());
        if (wId.getWorkExternalIdentifierType().getValue() != null && !wId.getWorkExternalIdentifierType().getValue().trim().isEmpty() && !types.keySet().contains(wId.getWorkExternalIdentifierType().getValue())) {
            setError(wId.getWorkExternalIdentifierType(), "manualWork.id_invalid");
        }
    }
    return work;
}
Also used : Text(org.orcid.pojo.ajaxForm.Text) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) IdentifierType(org.orcid.pojo.IdentifierType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with WorkExternalIdentifier

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

the class WorksController method initializeFields.

private void initializeFields(WorkForm w) {
    if (w.getVisibility() == null) {
        ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
        Visibility v = profile.getActivitiesVisibilityDefault() == null ? Visibility.fromValue(OrcidVisibilityDefaults.WORKS_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault();
        w.setVisibility(v);
    }
    if (w.getTitle() == null) {
        w.setTitle(new Text());
    }
    if (w.getSubtitle() == null) {
        w.setSubtitle(new Text());
    }
    if (w.getTranslatedTitle() == null) {
        TranslatedTitleForm tt = new TranslatedTitleForm();
        tt.setContent(new String());
        tt.setLanguageCode(new String());
        tt.setLanguageName(new String());
        w.setTranslatedTitle(tt);
    }
    if (PojoUtil.isEmpty(w.getJournalTitle())) {
        Text jt = new Text();
        jt.setRequired(false);
        w.setJournalTitle(jt);
    }
    if (PojoUtil.isEmpty(w.getWorkCategory())) {
        Text wCategoryText = new Text();
        wCategoryText.setValue(new String());
        wCategoryText.setRequired(true);
        w.setWorkCategory(wCategoryText);
    }
    if (PojoUtil.isEmpty(w.getWorkType())) {
        Text wTypeText = new Text();
        wTypeText.setValue(new String());
        wTypeText.setRequired(true);
        w.setWorkType(wTypeText);
    }
    initializePublicationDate(w);
    if (w.getWorkExternalIdentifiers() == null || w.getWorkExternalIdentifiers().isEmpty()) {
        WorkExternalIdentifier wei = new WorkExternalIdentifier();
        Text wdiType = new Text();
        wdiType.setValue(new String());
        wei.setWorkExternalIdentifierId(new Text());
        wei.setWorkExternalIdentifierType(wdiType);
        wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
        List<WorkExternalIdentifier> wdiL = new ArrayList<WorkExternalIdentifier>();
        wdiL.add(wei);
        w.setWorkExternalIdentifiers(wdiL);
    }
    if (PojoUtil.isEmpty(w.getUrl())) {
        w.setUrl(new Text());
    }
    if (w.getContributors() == null || w.getContributors().isEmpty()) {
        List<Contributor> contrList = new ArrayList<Contributor>();
        w.setContributors(contrList);
    }
    if (PojoUtil.isEmpty(w.getShortDescription())) {
        w.setShortDescription(new Text());
    }
    if (PojoUtil.isEmpty(w.getLanguageCode())) {
        Text lc = new Text();
        lc.setRequired(false);
        w.setLanguageCode(lc);
    }
    if (PojoUtil.isEmpty(w.getLanguageName())) {
        Text ln = new Text();
        ln.setRequired(false);
        w.setLanguageName(ln);
    }
    if (PojoUtil.isEmpty(w.getCountryCode())) {
        w.setCountryCode(new Text());
    }
    if (PojoUtil.isEmpty(w.getCountryName())) {
        w.setCountryName(new Text());
    }
}
Also used : ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Text(org.orcid.pojo.ajaxForm.Text) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm)

Example 9 with WorkExternalIdentifier

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

the class WorksController method removeEmptyExternalIdentifiers.

private void removeEmptyExternalIdentifiers(WorkForm workForm) {
    if (workForm != null) {
        if (workForm.getWorkExternalIdentifiers() != null && !workForm.getWorkExternalIdentifiers().isEmpty()) {
            List<WorkExternalIdentifier> cleanExtIds = new ArrayList<WorkExternalIdentifier>();
            for (WorkExternalIdentifier wExtId : workForm.getWorkExternalIdentifiers()) {
                if (!PojoUtil.isEmpty(wExtId.getWorkExternalIdentifierType())) {
                    if (!PojoUtil.isEmpty(wExtId.getWorkExternalIdentifierId())) {
                        cleanExtIds.add(wExtId);
                    }
                }
            }
            workForm.setWorkExternalIdentifiers(cleanExtIds);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier)

Example 10 with WorkExternalIdentifier

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

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