public void setResourceLoader(ResourceLoader resourceLoader) {
    this.resourceLoader = resourceLoader;
    try {
      // setPROPERTIES_DIR();
      webapp = getWebAppName(resourceLoader.getResource("/").getURI().getPath());
      logMe("is web app name null?" + webapp);

      String dbName = dataInfo.getProperty("dbType");

      DATAINFO = dataInfo;
      dataInfo =
          setDataInfoProperties(); // weird, but there are references to dataInfo...MainMenuServlet
                                   // for instance
      // setDataInfoPath();
      EXTRACTINFO = extractInfo;

      DB_NAME = dbName;
      SQLFactory factory = SQLFactory.getInstance();
      factory.run(dbName, resourceLoader);
      copyBaseToDest(resourceLoader);
      extractProperties = findExtractProperties();
      // tbh, following line to be removed
      // reportUrl();

    } catch (OpenClinicaSystemException e) {
      logger.debug(e.getMessage());
      logger.debug(e.toString());
      throw new OpenClinicaSystemException(e.getMessage(), e.fillInStackTrace());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  private void copyBaseToDest(ResourceLoader resourceLoader) {
    // System.out.println("Properties directory?"+resourceLoader.getResource("properties/xslt"));

    ByteArrayInputStream listSrcFiles[] = new ByteArrayInputStream[10];
    String[] fileNames = {
      "odm_spss_dat.xsl",
      "ODMToTAB.xsl",
      "odm_to_html.xsl",
      "odm_to_xslfo.xsl",
      "ODM-XSLFO-Stylesheet.xsl",
      "odm_spss_sps.xsl",
      "copyXML.xsl",
      "odm1.3_to_1.2.xsl",
      "odm1.3_to_1.2_extensions.xsl"
    };
    try {
      listSrcFiles[0] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[0])
                  .getInputStream();
      listSrcFiles[1] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[1])
                  .getInputStream();
      listSrcFiles[2] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[2])
                  .getInputStream();
      listSrcFiles[3] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[3])
                  .getInputStream();
      listSrcFiles[4] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[4])
                  .getInputStream();
      listSrcFiles[5] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[5])
                  .getInputStream();
      listSrcFiles[6] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[6])
                  .getInputStream();
      listSrcFiles[7] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[7])
                  .getInputStream();
      listSrcFiles[8] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[8])
                  .getInputStream();

    } catch (IOException ioe) {
      OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to read source files");
      oe.initCause(ioe);
      oe.setStackTrace(ioe.getStackTrace());
      logger.debug(ioe.getMessage());
      throw oe;
    }
    File dest = new File(getField("filePath") + "xslt");
    if (!dest.exists()) {
      if (!dest.mkdirs()) {
        throw new OpenClinicaSystemException(
            "Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
      }
    }

    for (int i = 0; i < fileNames.length; i++) {
      File dest1 = new File(dest, fileNames[i]);
      // File src1 = listSrcFiles[i];
      if (listSrcFiles[i] != null) copyFiles(listSrcFiles[i], dest1);
    }
  }
 private void copyFiles(ByteArrayInputStream fis, File dest) {
   FileOutputStream fos = null;
   byte[] buffer = new byte[512]; // Buffer 4K at a time (you can change this).
   int bytesRead;
   logger.debug("fis?" + fis);
   try {
     fos = new FileOutputStream(dest);
     while ((bytesRead = fis.read(buffer)) >= 0) {
       fos.write(buffer, 0, bytesRead);
     }
   } catch (IOException ioe) { // error while copying files
     OpenClinicaSystemException oe =
         new OpenClinicaSystemException(
             "Unable to copy file: "
                 + fis
                 + "to"
                 + dest.getAbsolutePath()
                 + "."
                 + dest.getAbsolutePath()
                 + ".");
     oe.initCause(ioe);
     oe.setStackTrace(ioe.getStackTrace());
     throw oe;
   } finally { // Ensure that the files are closed (if they were open).
     if (fis != null) {
       try {
         fis.close();
       } catch (IOException ioe) {
         OpenClinicaSystemException oe =
             new OpenClinicaSystemException(
                 "Unable to copy file: "
                     + fis
                     + "to"
                     + dest.getAbsolutePath()
                     + "."
                     + dest.getAbsolutePath()
                     + ".");
         oe.initCause(ioe);
         oe.setStackTrace(ioe.getStackTrace());
         logger.debug(ioe.getMessage());
         throw oe;
       }
     }
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException ioe) {
         OpenClinicaSystemException oe =
             new OpenClinicaSystemException(
                 "Unable to copy file: "
                     + fis
                     + "to"
                     + dest.getAbsolutePath()
                     + "."
                     + dest.getAbsolutePath()
                     + ".");
         oe.initCause(ioe);
         oe.setStackTrace(ioe.getStackTrace());
         logger.debug(ioe.getMessage());
         throw oe;
       }
     }
   }
 }
  public HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>
      runRulesBulk(
          List<RuleSetBean> ruleSets,
          Boolean dryRun,
          StudyBean currentStudy,
          HashMap<String, String> variableAndValue,
          UserAccountBean ub) {

    if (variableAndValue == null || variableAndValue.isEmpty()) {
      logger.warn("You must be executing Rules in Batch");
      variableAndValue = new HashMap<String, String>();
    }

    HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>
        crfViewSpecificOrderedObjects =
            new HashMap<
                RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>();
    for (RuleSetBean ruleSet : ruleSets) {
      for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
        ruleSet.setTarget(expressionBean);

        for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
          String result = null;
          RuleBean rule = ruleSetRule.getRuleBean();
          ExpressionObjectWrapper eow =
              new ExpressionObjectWrapper(
                  ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
          try {
            OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
            result = oep.parseAndEvaluateExpression(rule.getExpression().getValue());

            // Actions
            List<RuleActionBean> actionListBasedOnRuleExecutionResult =
                ruleSetRule.getActions(result);

            if (dryRun && actionListBasedOnRuleExecutionResult.size() > 0) {
              crfViewSpecificOrderedObjects =
                  populateForCrfBasedRulesView(
                      crfViewSpecificOrderedObjects,
                      ruleSet,
                      rule,
                      result,
                      currentStudy,
                      actionListBasedOnRuleExecutionResult);
            }

            // If not a dryRun meaning run Actions
            if (!dryRun) {
              for (RuleActionBean ruleAction : actionListBasedOnRuleExecutionResult) {
                int itemDataBeanId =
                    getExpressionService()
                        .getItemDataBeanFromDb(ruleSet.getTarget().getValue())
                        .getId();
                ruleAction.setCuratedMessage(curateMessage(ruleAction, ruleSetRule));
                // getDiscrepancyNoteService().saveFieldNotes(ruleAction.getSummary(),
                // itemDataBeanId, "ItemData", currentStudy, ub);
                ActionProcessor ap =
                    ActionProcessorFacade.getActionProcessor(ruleAction.getActionType(), ds);
                ap.execute(
                    ruleAction,
                    itemDataBeanId,
                    "ItemData",
                    currentStudy,
                    ub,
                    prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
              }
            }
          } catch (OpenClinicaSystemException osa) {
            // TODO: Auditing might happen here failed rule
            logger.warn(
                "RuleSet with target  : {} , Ran Rule : {} , It resulted in an error due to : {}",
                new Object[] {ruleSet.getTarget().getValue(), rule.getName(), osa.getMessage()});
          }
        }
      }
    }
    logCrfViewSpecificOrderedObjects(crfViewSpecificOrderedObjects);
    return crfViewSpecificOrderedObjects;
  }