Ejemplo n.º 1
0
  @Override
  public void init() {
    log("Initializing.");
    application = config.loadApplication();
    application.initialize();
    db =
        new Database(
            "jdbc:hsqldb:file:./data/",
            "accounting",
            "SA",
            ""); // config.DBURL,config.DATABASE,config.ADMIN_LOGIN,config.ADMIN_PASSWORD//TODO
    // secure.
    boolean goodConnection = db.testConnection();
    if (!goodConnection) {
      throw new IllegalStateException("Database failure.");
    }
    Result r = createManagementTables();
    if (r.notSuccessful()) {
      log("CreateManagementTables:" + r.name());
      return;
    }
    log("Created Management Tables.");
    r = fillAuxManagementTable();

    if (r.notSuccessful()) {
      log("FillAuxManagementTable:" + r.name());
      return;
    }
    log("Filled Management Tables.");
  }
Ejemplo n.º 2
0
 @Override
 public String getApplicationName() {
   if (application == null) {
     return "Not Loaded Yet.";
   } else {
     return application.toString();
   }
 }
Ejemplo n.º 3
0
  @SuppressWarnings("rawtypes")
  protected Result fillAuxManagementTable() {
    Result r = new Result();
    if (!haveRecords(Manager.AUX_MANAGER)) {
      List<Manager> managers = application.getManagers();
      int i = 0;
      for (Manager m : managers) {
        i++;
        String sInsert =
            "INSERT INTO "
                + Manager.AUX_MANAGER
                + " (id,manager) values ("
                + i
                + ",'"
                + m.getName()
                + "')";
        String identitySql = "CALL IDENTITY();";
        logsql(sInsert);
        r = db.executeInsert(sInsert, identitySql);
        Integer managerId = (Integer) r.objectValue(); // TODO safeguards
        m.setManagerId(managerId);
      }
    }
    String countQuery = "SELECT COUNT(*) FROM " + Manager.AUX_MANAGER + " ";
    logsql(countQuery);
    Result c = db.executeCountQuery(countQuery);
    if (hasCount(c)) {
      db.debugSelectAll("SELECT * FROM " + Manager.AUX_MANAGER + " ");

      List<Manager> managers = application.getManagers();
      int i = 0;
      for (Manager m : managers) {
        i++;
        String sSelect =
            "SELECT ID FROM " + Manager.AUX_MANAGER + " WHERE manager='" + m.getName() + "' ";
        logsql(sSelect);
        r = db.executeSelect(sSelect, m);
      }
    }
    r.success();
    ;
    return r;
  }
Ejemplo n.º 4
0
 @SuppressWarnings("rawtypes")
 private Result getEntityList(Screen.Button button) {
   Result result = new Result();
   Screen next;
   List<Manager> entityList = application.getManagers();
   next = new Screen(this, button.destination());
   next.setValue(Screen.AVAILABLE_ENTITIES, entityList);
   result.objectValue(next);
   result.success();
   return result;
 }
Ejemplo n.º 5
0
  private Result createViewRole(Button button, Role role, boolean redirect) {
    Result result = new Result();
    Screen next;
    next = new Screen(this, button.destination());
    if (redirect) {
      next.makeRedirect();
    }
    // Integer usrId = user.getId();
    result = listPrivileges(role);
    next.setValue(Screen.VIEW_ROLE, role);
    next.setValue(Screen.AVAILABLE_ENTITIES, application.getManagers());
    next.setValue(Screen.AVAILABLE_PRIVILEGES, Privilege.values());

    result.objectValue(next);

    result.success();
    return result;
  }