コード例 #1
0
  @POST
  @Path("/queryMin")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
  public String getMinimumField(String field) {
    String result = null;

    final ParameterQuerySender parameterQuerySenderService =
        (ParameterQuerySender) getServiceTracker().getService();
    if (parameterQuerySenderService != null) {

      DBObject mongoQuery = new BasicDBObject();

      Object qRes = parameterQuerySenderService.queryMin(mongoQuery, field);
      if (qRes instanceof List<?>) {
        List<?> dbResult = (List<?>) qRes;
        if (dbResult.size() == 1) {
          result = JSON.serialize(dbResult.get(0));
        } else {
          LOG.error(
              "Expected only one result from database when querying for minimum value of a field! Received "
                  + dbResult.size());
        }
      } else {
        LOG.error("Object returned from the parameter archiver was not a List<?>");
      }
    } else {
      LOG.warn("No " + SERVICE_INTERFACE + " service found.");
    }

    return result;
  }
コード例 #2
0
  @POST
  @Path("/datatablesquery")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public String queryParameterDatabaseForDataTables(List<Map<String, String>> dataTablesAoData)
      throws JsonGenerationException, JsonMappingException, IOException {
    String result = null;

    final ParameterQuerySender parameterQuerySenderService =
        (ParameterQuerySender) getServiceTracker().getService();
    if (parameterQuerySenderService != null) {
      Map<String, String> aoData = refineAoDataList(dataTablesAoData);
      if (aoData != null) {
        if (LOG.isTraceEnabled()) {
          LOG.trace("Querying with aoData:" + aoData);
        }
        DBObject query = buildMongoQuery(aoData);
        String skip = aoData.get("iDisplayStart");
        String count = aoData.get("iDisplayLength");

        String sortCol = calculateSortColumn(aoData);
        boolean ascending = StringUtils.equals(aoData.get("sSortDir_0"), "asc") ? true : false;

        Object results =
            parameterQuerySenderService.query(
                query, Integer.parseInt(count), Integer.parseInt(skip), sortCol, ascending);
        // FIXME Put results into aaData and return aoData back to server.
        if (results instanceof MongoResult) {
          MongoResult mongoResults = (MongoResult) results;
          ServerSideProcReturnData aaDataStructure = new ServerSideProcReturnData();
          aaDataStructure.sEcho = aoData.get("sEcho");
          aaDataStructure.aaData = mongoResults.results;
          aaDataStructure.iTotalRecords = mongoResults.totalResults;
          aaDataStructure.iTotalDisplayRecords = aaDataStructure.iTotalRecords;
          ObjectMapper mapper = new ObjectMapper();
          Writer out = new StringWriter();
          mapper.writeValue(out, aaDataStructure);
          result = out.toString();
        } else {
          LOG.error("Object returned from the parameter archiver was not a MongoResult object");
        }
      } else {
        LOG.error("Invalid aoData received - data was null");
      }
    } else {
      LOG.warn(
          "Cannot query parameter archive because there is no "
              + SERVICE_INTERFACE
              + " service found.");
    }
    return result;
  }
コード例 #3
0
  /**
   * TODO testing new QueryRequest design. Convert all resources if successful.
   *
   * @param request
   * @return
   */
  @POST
  @Path("/hbirdquery")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public String queryParameterDatabase(QueryRequest request) {
    String result = null;

    final ParameterQuerySender parameterQuerySenderService =
        (ParameterQuerySender) getServiceTracker().getService();
    if (parameterQuerySenderService != null) {
      Object qRes = parameterQuerySenderService.query(request);
      if (qRes instanceof List<?>) {
        result = JSON.serialize(qRes);
      } else {
        LOG.error("Object returned from the parameter archiver was not a List of Mongo Db objects");
      }
    } else {
      LOG.warn("No " + SERVICE_INTERFACE + " service found.");
    }
    return result;
  }