コード例 #1
0
ファイル: CommandHelper.java プロジェクト: ramyaveigas/IRIS
  /**
   * Returns a view action property This method will try to replace template parameters "{param}"
   * with query parameters if available
   *
   * @param ctx interaction context
   * @param property action property
   * @return property value
   */
  public static String getViewActionProperty(InteractionContext ctx, String property) {
    String prop = null;
    if (ctx.getCurrentState().getViewAction() != null) {
      Properties properties = ctx.getCurrentState().getViewAction().getProperties();
      if (properties != null && properties.containsKey(property)) {
        // Get the specified action property
        prop = getActionProperty(property, properties, ctx.getQueryParameters());

        // Fill in template parameters
        if (prop != null) {
          Matcher m = parameterPattern.matcher(prop);
          while (m.find()) {
            String templateParam = m.group(1); // e.g. code
            if (ctx.getQueryParameters().containsKey(templateParam)) {
              prop =
                  prop.replaceAll(
                      "\\{" + templateParam + "\\}",
                      ctx.getQueryParameters().getFirst(templateParam));
            } else if (ctx.getPathParameters().containsKey(templateParam)) {
              prop =
                  prop.replaceAll(
                      "\\{" + templateParam + "\\}",
                      ctx.getPathParameters().getFirst(templateParam));
            }
          }
        }
      }
    }
    return prop != null && !prop.equals(property) ? prop : null;
  }
コード例 #2
0
ファイル: JdbcProducer.java プロジェクト: kjanakarajappa/IRIS
  /*
   * Query method for interaction context parameters returning raw sql data.
   *
   * If given a key will return a single row.
   *
   * If given a null key will return all rows.
   */
  public SqlRowSet query(String tableName, String key, InteractionContext ctx)
      throws UnsupportedQueryOperationException, JdbcException, Exception {
    // Not much point selecting from a null table
    if (null == tableName) {
      logger.error("Jdbc producer cannot select from null table.");
      throw (new JdbcException(Status.INTERNAL_SERVER_ERROR, "Null table name"));
    }

    // Get column types from Jdbc. We need these both for constructing the
    // command and processing it's result set.
    // We need the primary key for row ordering.
    // TODO Eventually this should be cached.
    ColumnTypesMap colTypesMap = new ColumnTypesMap(this, tableName, true);

    // Unpack the commands $filter and $select terms.
    AccessProfile accessProfile = getAccessProfile(ctx);

    // Get top and skip parameters (null if not specified).
    MultivaluedMap<String, String> queryParams = ctx.getQueryParameters();
    String top = queryParams.getFirst(ODataParser.TOP_KEY);
    String skip = queryParams.getFirst(ODataParser.SKIP_KEY);

    List<OrderBy> orderBy = ODataParser.parseOrderBy(queryParams.getFirst(ODataParser.ORDERBY_KEY));

    // Build an SQL command
    SqlCommandBuilder sqlBuilder =
        new SqlCommandBuilder(
            tableName, key, accessProfile, colTypesMap, top, skip, orderBy, serverMode);
    String sqlCommand = sqlBuilder.getCommand();

    logger.info("Jdbc producer about to execute \"" + sqlCommand + "\"");

    // Execute the SQL command
    return query(sqlCommand);
  }
コード例 #3
0
 public boolean matches(Object o) {
   if (o instanceof InteractionContext) {
     InteractionContext ctx = (InteractionContext) o;
     MultivaluedMap<String, String> mvmap = ctx.getQueryParameters();
     if (!mvmap.getFirst("$filter").equals("this+that")) {
       return false;
     }
     return true;
   }
   return false;
 }