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;
}
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;
}
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;
}
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")));
}
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) {
}
}
Aggregations