コード例 #1
0
  @Override
  public void registerRoleForUser(String sessID, String user, Set<UserRole> roles)
      throws RemoteException, SessionExpiredException, SQLException, SecurityException {
    checkAdmin(sessID);

    // Check if any of the roles given are already assigned, and if so remove them from the
    // roles to register.
    Set<UserRole> assignedRoles = getRolesForUser(sessID, user);
    if (assignedRoles.containsAll(roles)) {
      return;
    } else if (assignedRoles.size() > 0) {
      roles.removeAll(assignedRoles);
    }

    // register the remaining roles.
    TableSchema raTable = MedSavantDatabase.UserRoleAssignmentTableSchema;
    for (UserRole role : roles) {
      InsertQuery iq = new InsertQuery(raTable.getTableName());
      iq.addColumn(
          raTable.getDBColumn(
              MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_ROLE_ID),
          role.getRoleId());
      iq.addColumn(
          raTable.getDBColumn(
              MedSavantDatabase.UserRoleAssignmentTableSchema.COLUMNNAME_OF_USERNAME),
          user);
      ConnectionController.executeUpdate(sessID, iq.toString());
    }
  }
コード例 #2
0
  public int addAnnotationLogEntry(
      String sid, int projectId, int referenceId, Action action, Status status)
      throws SQLException, RemoteException, SessionExpiredException {

    String user = SessionController.getInstance().getUserForSession(sid);

    Timestamp sqlDate = SQLUtils.getCurrentTimestamp();

    TableSchema table = MedSavantDatabase.VariantpendingupdateTableSchema;
    InsertQuery query = new InsertQuery(table.getTable());
    query.addColumn(
        table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_PROJECT_ID), projectId);
    query.addColumn(
        table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_REFERENCE_ID), referenceId);
    query.addColumn(
        table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_ACTION),
        AnnotationLog.actionToInt(action));
    query.addColumn(
        table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_STATUS),
        AnnotationLog.statusToInt(status));
    query.addColumn(
        table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_TIMESTAMP), sqlDate);
    query.addColumn(table.getDBColumn(VariantPendingUpdateTableSchema.COLUMNNAME_OF_USER), user);

    Connection c = ConnectionController.connectPooled(sid);
    PreparedStatement stmt = c.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
    stmt.execute();

    ResultSet rs = stmt.getGeneratedKeys();
    rs.next();
    c.close();
    return rs.getInt(1);
  }
コード例 #3
0
  @Override
  public UserRole addRole(String sessID, String roleName, String roleDescription)
      throws RemoteException, SessionExpiredException, SQLException, SecurityException {
    String thisDatabase = SessionManager.getInstance().getDatabaseForSession(sessID);
    checkAdmin(sessID);

    // Check if role already exists, and if so, return it.
    Set<UserRole> roles = getAllRoles(sessID);
    for (UserRole r : roles) {
      if (r.getDatabase().equals(thisDatabase) && r.getRoleName().equals(roleName)) {
        return r;
      }
    }

    TableSchema roleTable = MedSavantDatabase.UserRoleTableSchema;
    InsertQuery iq = new InsertQuery(roleTable.getTableName());
    iq.addColumn(
        roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLENAME),
        roleName);
    iq.addColumn(
        roleTable.getDBColumn(MedSavantDatabase.UserRoleTableSchema.COLUMNNAME_OF_ROLE_DESCRIPTION),
        roleDescription);

    PooledConnection conn = ConnectionController.connectPooled(sessID);
    PreparedStatement stmt = null;
    ResultSet res = null;
    int roleId = -1;
    try {
      stmt = conn.prepareStatement(iq.toString(), Statement.RETURN_GENERATED_KEYS);
      stmt.execute();
      res = stmt.getGeneratedKeys();
      res.next();
      roleId = res.getInt(1);

      return new UserRole(roleId, roleName, roleDescription, thisDatabase);
    } finally {
      if (stmt != null) {
        stmt.close();
      }
      if (res != null) {
        res.close();
      }
      if (conn != null) {
        conn.close();
      }
    }
  }