Search in sources :

Example 1 with WorkExternalIdentifier

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

the class PeerReviewsController method createPeerReviewIdList.

/**
     * Create a funding id list and sorts a map associated with the list in in
     * the session
     * 
     */
private List<String> createPeerReviewIdList(HttpServletRequest request) {
    String orcid = getCurrentUserOrcid();
    List<PeerReview> peerReviews = peerReviewManager.findPeerReviews(orcid, profileEntityManager.getLastModified(orcid));
    Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
    HashMap<Long, PeerReviewForm> peerReviewMap = new HashMap<>();
    List<String> peerReviewIds = new ArrayList<String>();
    if (peerReviews != null) {
        for (PeerReview peerReview : peerReviews) {
            try {
                PeerReviewForm form = PeerReviewForm.valueOf(peerReview);
                if (form.getExternalIdentifiers() != null && !form.getExternalIdentifiers().isEmpty()) {
                    for (WorkExternalIdentifier wExtId : form.getExternalIdentifiers()) {
                        if (PojoUtil.isEmpty(wExtId.getRelationship())) {
                            wExtId.setRelationship(Text.valueOf(Relationship.SELF.value()));
                        }
                    }
                }
                if (form.getTranslatedSubjectName() != null) {
                    // Set translated title language name
                    if (!(form.getTranslatedSubjectName() == null) && !StringUtils.isEmpty(form.getTranslatedSubjectName().getLanguageCode())) {
                        String languageName = languages.get(form.getTranslatedSubjectName().getLanguageCode());
                        form.getTranslatedSubjectName().setLanguageName(languageName);
                    }
                }
                form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, peerReview.getOrganization().getAddress().getCountry().name())));
                //Set the numeric id (the table id in the group_id_record table) of the group id
                if (form.getGroupId() != null && !PojoUtil.isEmpty(form.getGroupId().getValue())) {
                    GroupIdRecord groupId = groupIdRecordManager.findByGroupId(form.getGroupId().getValue()).get();
                    form.setGroupIdPutCode(Text.valueOf(groupId.getPutCode()));
                }
                peerReviewMap.put(peerReview.getPutCode(), form);
                peerReviewIds.add(String.valueOf(peerReview.getPutCode()));
            } catch (Exception e) {
                LOGGER.error("Failed to parse as PeerReview. Put code" + peerReview.getPutCode(), e);
            }
        }
        request.getSession().setAttribute(PEER_REVIEW_MAP, peerReviewMap);
    }
    return peerReviewIds;
}
Also used : HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview)

Example 2 with WorkExternalIdentifier

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

the class PeerReviewsController method postPeerReview.

/**
     * Persist a funding object on database
     * */
@RequestMapping(value = "/peer-review.json", method = RequestMethod.POST)
@ResponseBody
public PeerReviewForm postPeerReview(@RequestBody PeerReviewForm peerReview) {
    // Reset errors
    peerReview.setErrors(new ArrayList<String>());
    // Remove empty external identifiers
    removeEmptyExternalIds(peerReview);
    // Remove empty external identifiers on subject
    removeEmptyExternalIdsOnSubject(peerReview);
    validateOrgName(peerReview);
    validateCity(peerReview);
    validateRegion(peerReview);
    validateCountry(peerReview);
    validateUrl(peerReview);
    validateExternalIdentifiers(peerReview);
    validateGroupId(peerReview);
    copyErrors(peerReview.getOrgName(), peerReview);
    copyErrors(peerReview.getCity(), peerReview);
    copyErrors(peerReview.getRegion(), peerReview);
    copyErrors(peerReview.getCountry(), peerReview);
    copyErrors(peerReview.getUrl(), peerReview);
    copyErrors(peerReview.getGroupId(), peerReview);
    if (peerReview.getExternalIdentifiers() != null) {
        for (WorkExternalIdentifier extId : peerReview.getExternalIdentifiers()) {
            copyErrors(extId.getWorkExternalIdentifierId(), peerReview);
            copyErrors(extId.getWorkExternalIdentifierType(), peerReview);
        }
    }
    if (peerReview.getCompletionDate() != null) {
        validateCompletionDate(peerReview);
        copyErrors(peerReview.getCompletionDate(), peerReview);
    }
    validateSubjectType(peerReview);
    copyErrors(peerReview.getSubjectType(), peerReview);
    validateSubjectName(peerReview);
    copyErrors(peerReview.getSubjectName(), peerReview);
    validateSubjectUrl(peerReview);
    copyErrors(peerReview.getSubjectUrl(), peerReview);
    validateSubjectExternalIdentifier(peerReview);
    copyErrors(peerReview.getSubjectExternalIdentifier(), peerReview);
    // If there are no errors, persist to DB
    if (peerReview.getErrors().isEmpty()) {
        if (PojoUtil.isEmpty(peerReview.getPutCode())) {
            peerReview = addPeerReview(peerReview);
        } else {
            peerReview = editPeerReview(peerReview);
        }
    }
    return peerReview;
}
Also used : WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with WorkExternalIdentifier

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

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

the class PeerReviewsControllerTest method getForm.

private PeerReviewForm getForm() {
    PeerReviewForm form = new PeerReviewForm();
    form.setCity(Text.valueOf("The City"));
    form.setCountry(Text.valueOf("CR"));
    form.setOrgName(Text.valueOf("OrgName"));
    form.setRegion(Text.valueOf("The Region"));
    form.setRole(Text.valueOf("reviewer"));
    form.setType(Text.valueOf("evaluation"));
    form.setUrl(Text.valueOf("http://orcid.org"));
    form.setVisibility(Visibility.LIMITED);
    Date completionDate = new Date();
    completionDate.setDay("01");
    completionDate.setMonth("01");
    completionDate.setYear("2015");
    form.setCompletionDate(completionDate);
    WorkExternalIdentifier wei = new WorkExternalIdentifier();
    wei.setWorkExternalIdentifierId(Text.valueOf("extId1"));
    wei.setWorkExternalIdentifierType(Text.valueOf("bibcode"));
    wei.setRelationship(Text.valueOf(Relationship.SELF.value()));
    wei.setUrl(Text.valueOf("http://myurl.com"));
    List<WorkExternalIdentifier> extIds = new ArrayList<WorkExternalIdentifier>();
    extIds.add(wei);
    form.setExternalIdentifiers(extIds);
    form.setSubjectContainerName(Text.valueOf("Journal Title"));
    form.setSubjectName(Text.valueOf("Title"));
    TranslatedTitleForm translated = new TranslatedTitleForm();
    translated.setContent("Translated title");
    translated.setLanguageCode("es");
    form.setTranslatedSubjectName(translated);
    form.setSubjectUrl(Text.valueOf("http://subject.com"));
    form.setSubjectExternalIdentifier(wei);
    form.setSubjectType(Text.valueOf("book-review"));
    form.setGroupId(Text.valueOf("issn:0000001"));
    return form;
}
Also used : ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) Date(org.orcid.pojo.ajaxForm.Date) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm)

Example 5 with WorkExternalIdentifier

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

the class WorkFormTest method getWorkForm.

private WorkForm getWorkForm() {
    WorkForm form = new WorkForm();
    form.setCitation(new Citation("Citation", "formatted-unspecified"));
    List<Contributor> çontributors = new ArrayList<Contributor>();
    Contributor contributor = new Contributor();
    contributor.setContributorRole(Text.valueOf("co_inventor"));
    contributor.setContributorSequence(Text.valueOf("first"));
    contributor.setCreditName(Text.valueOf("Contributor credit name"));
    contributor.setEmail(null);
    contributor.setOrcid(Text.valueOf("Contributor orcid"));
    contributor.setUri(Text.valueOf("Contributor uri"));
    çontributors.add(contributor);
    form.setContributors(çontributors);
    form.setCountryCode(Text.valueOf("US"));
    Date createdDate = new Date();
    createdDate.setDay("1");
    createdDate.setMonth("1");
    createdDate.setYear("2015");
    form.setCreatedDate(createdDate);
    form.setJournalTitle(Text.valueOf("Journal title"));
    form.setLanguageCode(Text.valueOf("en"));
    Date lastModifiedDate = new Date();
    lastModifiedDate.setDay("2");
    lastModifiedDate.setMonth("2");
    lastModifiedDate.setYear("2015");
    form.setLastModified(lastModifiedDate);
    Date publicationDate = new Date();
    publicationDate.setDay("03");
    publicationDate.setMonth("03");
    publicationDate.setYear("2015");
    form.setPublicationDate(publicationDate);
    form.setDateSortString(PojoUtil.createDateSortString(null, FuzzyDate.valueOf(2015, 3, 3)));
    form.setPutCode(Text.valueOf("1"));
    form.setShortDescription(Text.valueOf("Short description"));
    form.setSource("0000-0000-0000-0000");
    form.setSubtitle(Text.valueOf("Subtitle"));
    form.setTitle(Text.valueOf("Title"));
    form.setTranslatedTitle(new TranslatedTitleForm("Translated Title", "es"));
    form.setUrl(Text.valueOf("http://myurl.com"));
    form.setVisibility(Visibility.PUBLIC);
    List<WorkExternalIdentifier> extIds = new ArrayList<WorkExternalIdentifier>();
    WorkExternalIdentifier extId = new WorkExternalIdentifier();
    extId.setWorkExternalIdentifierId(Text.valueOf("External Identifier ID"));
    extId.setWorkExternalIdentifierType(Text.valueOf("asin"));
    extId.setRelationship(Text.valueOf(Relationship.SELF.value()));
    extIds.add(extId);
    form.setWorkExternalIdentifiers(extIds);
    form.setWorkType(Text.valueOf("artistic-performance"));
    WorkCategory category = WorkCategory.fromWorkType(WorkType.fromValue(form.getWorkType().getValue()));
    form.setWorkCategory(Text.valueOf(category.value()));
    return form;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Citation(org.orcid.pojo.ajaxForm.Citation) WorkExternalIdentifier(org.orcid.pojo.ajaxForm.WorkExternalIdentifier) WorkCategory(org.orcid.jaxb.model.record_v2.WorkCategory) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) CreatedDate(org.orcid.jaxb.model.common_v2.CreatedDate) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) Date(org.orcid.pojo.ajaxForm.Date) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm)

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