Esempio n. 1
0
  /**
   * Gets all the rules that are avaible for this project
   *
   * @param projectId
   * @return
   * @throws DatabaseException
   * @throws SQLException
   * @throws DatabaseValueNotFoundException
   */
  private ArrayList<Rule> getRules(int projectId)
      throws DatabaseException, SQLException, DatabaseValueNotFoundException {
    PreparedStatement statement =
        this.conApex.prepareStatement("SELECT * FROM BUSINESSRULE WHERE BRG_PROJECTID=?");
    ArrayList<Rule> rules = new ArrayList<Rule>();
    String template = null;
    log.out(Level.INFORMATIVE, "getRules", "Getting rules for project");
    statement.setInt(1, projectId);
    ResultSet result = statement.executeQuery();

    while (result.next()) {
      log.out(Level.INFORMATIVE, "getRules", "Got trigger type");
      PreparedStatement templateStmt =
          this.conApex.prepareStatement("SELECT * FROM TEMPLATE WHERE ID=?");
      templateStmt.setInt(1, result.getInt("TEMPLATEID"));

      ResultSet templateRs = templateStmt.executeQuery();
      while (templateRs.next()) {
        template = templateRs.getString("TEMPLATE");
      }
      log.out(Level.INFORMATIVE, "getRules", "Got template string");

      Rule rule =
          new Rule(
              result.getString("NAME"),
              new Operator(result.getString("OPERATOR")),
              result.getString("TRIGGER_EVENT"),
              result.getString("ERROR_MESSAGE"),
              new RuleType(
                  result.getString("TRIGGER_CODE"),
                  result.getString("EXAMPLE"),
                  result.getString("DESCRIPTION")),
              template);
      rule.setId(result.getInt("ID"));
      rules.add(rule);
    }
    if (!rules.isEmpty()) {
      statement.close();
      return rules;
    } else {
      statement.close();
      log.out(Level.ERROR, "getRules", "No rules found for " + projectId);
      return null;
    }
  }
Esempio n. 2
0
  /**
   * Fetches all collumns from a businessruleid
   *
   * @param businessRuleId
   * @return
   * @throws SQLException
   * @throws DatabaseValueNotFoundException
   */
  private ArrayList<Column> getColumns(int businessRuleId)
      throws SQLException, DatabaseValueNotFoundException {
    log.out(Level.INFORMATIVE, "getColumns", "Getting columns for project");
    PreparedStatement statement =
        this.conApex.prepareStatement("SELECT * FROM RULE_COLUMN WHERE BUSINESSRULEID=?");
    ArrayList<Column> columns = new ArrayList<Column>();
    statement.setInt(1, businessRuleId);
    ResultSet result = statement.executeQuery();

    while (result.next()) {
      columns.add(new Column(result.getString("NAME")));
    }
    if (!columns.isEmpty()) {
      statement.close();
      return columns;
    } else {
      statement.close();
      log.out(Level.ERROR, "getCollumns", "No collumns found for BRI: " + businessRuleId);
      return null;
    }
  }
Esempio n. 3
0
  /**
   * Default constructor. Tries to load the profile from the file %lt;profile>.properties, falling
   * back on defaults if is not successful.
   *
   * @param profile
   * @throws InvalidProfileConfigurationException if the profile contains invalid values
   */
  public Profile(String profile) {
    properties = new Properties(defaultProperties);
    if (profile != null) {
      try {
        final InputStream propFileStream =
            getClass().getResourceAsStream("/" + profile + ".properties");
        if (propFileStream != null) {
          properties.load(propFileStream);
          LOGGER.info("Loaded profile %s", profile.toUpperCase());
        } else {
          LOGGER.error(
              "Could not load properties for profile %s, running with default profile", profile);
        }

      } catch (Exception e) {
        LOGGER.error(
            "Could not load properties for profile %s, running with default profile", profile);
      }
    }
    LOGGER.info(
        "Configured profile (%s):\n%s ",
        profile == null ? "DEFAULT" : profile.toUpperCase(), getPropertiesAsString());
    validate();
  }
Esempio n. 4
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {

    // Initialise context and get our context variables from the DD
    ServletContext ctx = sce.getServletContext();
    DatabaseQueryExecutor db = initDatabaseConnection(ctx);

    // init managers and set them in the context
    ctx.setAttribute("userManager", initUserManager(db));
    ctx.setAttribute("handsetAccessManager", initHandsetAccessManager(db));
    ctx.setAttribute("tourManager", initTourManager(db));
    ctx.setAttribute("exhibitManager", initExhibitManager(db));
    ctx.setAttribute("audioManager", initAudioManager(db));
    ctx.setAttribute("questionSetManager", initQuestionSetManager(db));
    ctx.setAttribute("routerManager", initRouterManager(db));
    ctx.setAttribute("databaseExecutor", db);
    ctx.setAttribute("groupManager", initGroupManager(db));
    ctx.setAttribute("audioPortManager", new AudioPortManager(60000, 63000));
    Logger.setLogFact(new LogFactory(db));
  }
Esempio n. 5
0
  private ArrayList<Value> getValues(int businessRuleId)
      throws SQLException, DatabaseValueNotFoundException {
    PreparedStatement statement =
        this.conApex.prepareStatement("SELECT * FROM RULE_VALUE WHERE BUSINESSRULEID=?");
    ArrayList<Value> value = new ArrayList<Value>();
    statement.setInt(1, businessRuleId);
    ResultSet result = statement.executeQuery();

    while (result.next()) {
      value.add(new Value(result.getString("NAME")));
    }
    if (!value.isEmpty()) {
      statement.close();
      return value;
    } else {
      statement.close();
      log.out(Level.ERROR, "getValues", "No values found for BRI: " + businessRuleId);
      return null;
    }
  }
 // TODO later updates (after initialization)
 public void increment(Sample s) {
   String code = s.getCode();
   try {
     String exp = s.getExperimentIdentifierOrNull().split(project + "E")[1];
     int expNum = Integer.parseInt(exp);
     if (expNum > expID) expID = expNum;
   } catch (Exception e) {
     logger.warn(
         "While counting existing experiments in project "
             + project
             + " unfamiliar experiment identifier "
             + s.getExperimentIdentifierOrNull()
             + " was found. Either this project is atypical or your code sucks!");
   }
   if (Functions.isQbicBarcode(code)) {
     int num = Integer.parseInt(code.substring(5, 8));
     if (num >= barcodeID) barcodeID = num;
   } else if (s.getSampleTypeCode().equals(("Q_BIOLOGICAL_ENTITY"))) {
     int num = Integer.parseInt(s.getCode().split("-")[1]);
     if (num >= entityID) entityID = num;
   }
 }
Esempio n. 7
0
  /** Soubory a slozky ke smazani jsou v promenny files. */
  @Override
  protected void executeCommand() {

    if (opt_f || opt_i) {
      parser.getShell().printLine("Sorry unimplemented funcionality");
      return;
    }

    String currentDir = getCurrentDir();

    for (String filePath : files) {

      filePath = resolvePath(currentDir, filePath);

      if (!parser.device.getFilesystem().exists(filePath)) {
        parser.getShell().printLine("rm: " + filePath + "file doesn't exist");
        continue;
      }

      if (parser.device.getFilesystem().isDir(filePath)
          && !opt_r) { // if path is a directory and -r parameter is not activated
        parser.getShell().printLine("rm: " + filePath + "path is a directory, use -r parametr");
        continue;
      }
      boolean deleted = false;
      try {
        deleted = parser.device.getFilesystem().rm_r(filePath);
      } catch (FileNotFoundException ex) {
        Logger.log(
            Logger.WARNING,
            LoggingCategory.LINUX_COMMANDS,
            "Cannot delete file. File is not found, but file existence was confirmed.");
      }

      if (!deleted) {
        parser.getShell().printLine("rm: " + filePath + "deletion failed. Unknown reason");
      }
    }
  }
Esempio n. 8
0
 /**
  * Abstract class DataAccessObject has functions needed in other DAO files, please add functions
  * that you other DAO's might use and keep them generic
  *
  * @throws IOException
  * @throws DatabaseException
  * @throws MissingPropertiesFile
  * @throws SQLException
  * @throws ConnectionClosedException
  */
 public DataAccessObject()
     throws IOException, DatabaseException, MissingPropertiesFile, SQLException,
         ConnectionClosedException {
   log.out(Level.INFORMATIVE, "DataAccessObject", "Trying to get database connection");
   conApex = ConnectorFactory.getApexConnection();
 }
Esempio n. 9
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String exhibitName = request.getParameter("name");
    String exhibitDescription = request.getParameter("description");
    String audioLevel1ID = request.getParameter("audioIDLevel1");
    String audioLevel2ID = request.getParameter("audioIDLevel2");
    String audioLevel3ID = request.getParameter("audioIDLevel3");
    String audioLevel4ID = request.getParameter("audioIDLevel4");

    if (exhibitName == null || exhibitName == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please enter a name for the exhibit</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    } else if (exhibitDescription == null || exhibitDescription == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please enter a description for the exhibit</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    } else if (audioLevel1ID == null || audioLevel1ID == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please select an audio file for level one</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    } else if (audioLevel2ID == null || audioLevel2ID == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please select an audio file for level two</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    } else if (audioLevel3ID == null || audioLevel3ID == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please select an audio file for level three</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    } else if (audioLevel4ID == null || audioLevel4ID == "") {
      request.setAttribute(
          "message", "<h2 style='color:red'>Please select an audio file for level four</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    }

    int level1ID, level2ID, level3ID, level4ID;
    try {
      level1ID = Integer.parseInt(audioLevel1ID);
      level2ID = Integer.parseInt(audioLevel2ID);
      level3ID = Integer.parseInt(audioLevel3ID);
      level4ID = Integer.parseInt(audioLevel4ID);
    } catch (NumberFormatException e) {
      request.setAttribute(
          "message", "<h2 style='color:red'>Error parsing audio ID as integer.</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    }

    ExhibitManager manager = (ExhibitManager) getServletContext().getAttribute("exhibitManager");
    if (!manager.addExhibit(
        exhibitName, exhibitDescription, level1ID, level2ID, level3ID, level4ID)) {
      request.setAttribute(
          "message", "<h2 style='color:red'>Error creating exhibit. Please try again</h2>");
      Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
      return;
    }

    Exhibit exhibitJustAdded =
        manager.getListOfExhibits().get(manager.getListOfExhibits().size() - 1);
    Logger.Log(
        Logger.LogType.EXHIBITADD,
        new String[] {
          String.valueOf(exhibitJustAdded.getExhibitID()),
          exhibitJustAdded.getName(),
          (String) request.getSession().getAttribute("username")
        });
    request.setAttribute("message", "<h2>Successfully added a new exhibit.</h2>");
    Redirector.redirect(request, response, "/admin/addNewExhibit.jsp");
  }