public ActionForward printQuestionnaireAnswer( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO : this is only available after questionnaire is saved ? ActionForward forward = mapping.findForward(Constants.MAPPING_BASIC); Map<String, Object> reportParameters = new HashMap<String, Object>(); ProtocolFormBase protocolForm = (ProtocolFormBase) form; ProtocolBase protocol = protocolForm.getActionHelper().getProtocol(); final int answerHeaderIndex = this.getSelectedLine(request); String methodToCall = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); String formProperty = StringUtils.substringBetween(methodToCall, ".printQuestionnaireAnswer.", ".line"); QuestionnaireHelperBase helper = (QuestionnaireHelperBase) BeanUtilsBean.getInstance().getPropertyUtils().getProperty(form, formProperty); AnswerHeader answerHeader = helper.getAnswerHeaders().get(answerHeaderIndex); // TODO : a flag to check whether to print answer or not // for release 3 : if questionnaire questions has answer, then print answer. reportParameters.put( QuestionnaireConstants.QUESTIONNAIRE_SEQUENCE_ID_PARAMETER_NAME, answerHeader.getQuestionnaire().getQuestionnaireSeqIdAsInteger()); reportParameters.put("template", answerHeader.getQuestionnaire().getTemplate()); reportParameters.put("coeusModuleSubItemCode", answerHeader.getModuleSubItemCode()); AttachmentDataSource dataStream = getQuestionnairePrintingService().printQuestionnaireAnswer(protocol, reportParameters); if (dataStream.getData() != null) { streamToResponse(dataStream, response); forward = null; } return forward; }
/** * This method is for the 'update' button to update questionnaire answer to new version * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward updateAnswerToNewVersion( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String methodToCallStart = "methodToCall.updateAnswerToNewVersion."; String methodToCallEnd = ".line"; String methodToCall = ((String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE)); String questionnaireHelperPath = methodToCall.substring(methodToCallStart.length(), methodToCall.indexOf(methodToCallEnd)); QuestionnaireHelperBase helper = (QuestionnaireHelperBase) PropertyUtils.getNestedProperty(form, questionnaireHelperPath); helper.updateQuestionnaireAnswer(getLineToDelete(request)); getBusinessObjectService().save(helper.getAnswerHeaders()); return mapping.findForward(Constants.MAPPING_BASIC); }