Search in sources :

Example 1 with PeerReviewForm

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

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

the class PeerReviewsController method getPeerReviewsJson.

/**
     * List peer reviews associated with a profile
     * */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/get-peer-reviews.json", method = RequestMethod.GET)
@ResponseBody
public List<PeerReviewForm> getPeerReviewsJson(HttpServletRequest request, @RequestParam(value = "peerReviewIds") String peerReviewIdsStr) {
    List<PeerReviewForm> peerReviewList = new ArrayList<>();
    PeerReviewForm peerReview = null;
    String[] peerReviewIds = peerReviewIdsStr.split(",");
    if (peerReviewIds != null) {
        HashMap<Long, PeerReviewForm> peerReviewMap = (HashMap<Long, PeerReviewForm>) request.getSession().getAttribute(PEER_REVIEW_MAP);
        // this should never happen, but just in case.
        if (peerReviewMap == null) {
            createPeerReviewIdList(request);
            peerReviewMap = (HashMap<Long, PeerReviewForm>) request.getSession().getAttribute(PEER_REVIEW_MAP);
        }
        for (String peerReviewId : peerReviewIds) {
            peerReview = peerReviewMap.get(Long.valueOf(peerReviewId));
            peerReviewList.add(peerReview);
        }
    }
    return peerReviewList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with PeerReviewForm

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

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

the class PeerReviewsControllerTest method testAddWithInvalidGroupId.

@Test
public void testAddWithInvalidGroupId() {
    PeerReviewForm form = getForm();
    form.getGroupId().setValue("bad-group-id");
    PeerReviewForm newForm = peerReviewsController.postPeerReview(form);
    assertNotNull(newForm);
    assertTrue(PojoUtil.isEmpty(newForm.getPutCode()));
    assertTrue(form.getErrors().contains(peerReviewsController.getMessage("peer_review.group_id.not_valid")));
}
Also used : PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 5 with PeerReviewForm

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

the class PeerReviewsControllerTest method testDeletePeerReview.

@Test
public void testDeletePeerReview() {
    HttpSession session = mock(HttpSession.class);
    when(servletRequest.getSession()).thenReturn(session);
    PeerReviewForm form = getForm();
    PeerReviewForm newForm = peerReviewsController.postPeerReview(form);
    assertNotNull(newForm);
    assertFalse(PojoUtil.isEmpty(newForm.getPutCode()));
    String putCode = newForm.getPutCode().getValue();
    peerReviewsController.deletePeerReviewJson(newForm);
    try {
        peerReviewsController.getPeerReviewJson(Long.valueOf(putCode));
        fail();
    } catch (NoResultException nre) {
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) NoResultException(javax.persistence.NoResultException) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

PeerReviewForm (org.orcid.pojo.ajaxForm.PeerReviewForm)9 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)4 WorkExternalIdentifier (org.orcid.pojo.ajaxForm.WorkExternalIdentifier)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashMap (java.util.HashMap)2 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)2 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)2 Date (org.orcid.pojo.ajaxForm.Date)2 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)2 NoResultException (javax.persistence.NoResultException)1 HttpSession (javax.servlet.http.HttpSession)1