コード例 #1
0
  @Test
  public void testRequiredConstraint() {

    Constraint requiredConstraint = new Constraint();
    requiredConstraint.setConstraintType(ConstraintType.REQUIRED);

    /*
    	Object nullObject = null;
    	assertFalse(constraintHandler.evaluateConstraint(nullObject, requiredConstraint));

    	String stringObject = "";
    	assertFalse(constraintHandler.evaluateConstraint(stringObject, requiredConstraint));
    	stringObject = "whatever";
    	assertTrue(constraintHandler.evaluateConstraint(stringObject, requiredConstraint));
    */

  }
  @RequestMapping(
      value =
          "/ajax/protocols/{protocolId}/protocol-forms/{protocolFormId}/reportable-new-information/protocol-form-xml-datas/{protocolFormXmlDataId}/validate",
      method = RequestMethod.GET)
  public @ResponseBody List<ValidationResponse> validateProtocolReportableNewInformationForm(
      @PathVariable("protocolFormXmlDataId") long protocolFormXmlDataId) {

    ProtocolFormXmlData protocolXmlData = protocolFormXmlDataDao.findById(protocolFormXmlDataId);

    String xmldata = protocolXmlData.getXmlData();

    List<ValidationResponse> validationResponses = new ArrayList<ValidationResponse>();
    if (StringUtils.hasText(xmldata)) {

      List<Rule> reportableNewInformationValidationRules =
          getValidationRuleContainer()
              .getValidationRules("reportableNewInformationValidationRules");

      Assert.notNull(reportableNewInformationValidationRules);

      Set<String> valueKeys =
          getValidationRuleContainer()
              .getCachedValueKeys("reportableNewInformationValidationRules");

      Assert.notNull(valueKeys);

      Map<String, List<String>> values = null;

      // setup values
      try {
        values = xmlProcessor.listElementStringValuesByPaths(valueKeys, xmldata);
      } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      validationResponses =
          validationRuleHandler.validate(reportableNewInformationValidationRules, values);
    }

    if (!isReportableOrNot(protocolXmlData)) {
      Constraint notReportableConstraint = new Constraint();
      Map<String, Object> notReportableAdditionalData = new HashMap<String, Object>();

      notReportableConstraint.setConstraintLevel(ConstraintLevel.ERROR);
      notReportableConstraint.setErrorMessage(
          "This event/information does not meet the criteria for an Unanticipated Problem Involving Risk "
              + "to Subjects or Others (UPIRTSO) and does not require immediate reporting to the IRB."
              + "<br/>"
              + "Please submit the information in summary format at Continuing Review."
              + "<br/>"
              + "A suggested summary format is available at:<a href=\"http://www.uams.edu/irb/Reporting%20Events%20and%20Deviations.asp\" target=\"_blank\">http://www.uams.edu/irb/Reporting%20Events%20and%20Deviations.asp</a>"
              + "<br/>"
              + "The IRB recommends that events be compiled throughout the year."
              + "<br/>"
              + "If you need to update documents now, please do so using a Modification.");

      notReportableAdditionalData.put("pagename", "Review");
      notReportableAdditionalData.put("pageref", "review");

      ValidationResponse budgetVP =
          new ValidationResponse(notReportableConstraint, notReportableAdditionalData);

      validationResponses.add(budgetVP);
    }

    return validationResponses;
  }