コード例 #1
0
ファイル: CdaCoreService.java プロジェクト: jwarlander/cda
  // @Exposed(accessLevel = AccessLevel.PUBLIC)
  public void unwrapQuery(
      final OutputStream out,
      final String path,
      final String solution,
      final String file,
      final String uuid)
      throws Exception {
    final CdaEngine engine = CdaEngine.getInstance();
    // final ICommonParameterProvider requestParams = requParam;
    final String relativePath = getRelativePath(path, solution, file);
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFile(relativePath);
    // String uuid = requestParams.getStringParameter("uuid", null);
    QueryOptions queryOptions = engine.unwrapQuery(uuid);
    if (queryOptions != null) {
      Exporter exporter =
          ExporterEngine.getInstance()
              .getExporter(queryOptions.getOutputType(), queryOptions.getExtraSettings());

      String attachmentName = exporter.getAttachmentName();
      String mimeType = (attachmentName == null) ? null : getMimeType(attachmentName);
      if (StringUtils.isEmpty(mimeType)) {
        mimeType = exporter.getMimeType();
      }

      if (relativePath != null && uuid != null) ; // XXX  ==  if (this.parameterProviders != null)
      {
        setResponseHeaders(mimeType, attachmentName);
      }
      engine.doQuery(out, cdaSettings, queryOptions);
    } else {
      logger.error("unwrapQuery: uuid " + uuid + " not found.");
    }
  }
コード例 #2
0
 @Override
 public void execute() throws Exception {
   ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
     if (!loadArguments()) {
       logger.error("Not executed: unable to process arguments.");
       return;
     }
     if (logger.isDebugEnabled()) {
       logger.debug(
           String.format(
               "executing %s:%s\n\t %s",
               cdaSettings.getId(), queryOptions.getDataAccessId(), jsonStringArg));
     } else {
       logger.info(
           String.format(
               "executing %s:%s...", cdaSettings.getId(), queryOptions.getDataAccessId()));
     }
     CdaEngine.getInstance().doQuery(cdaSettings, queryOptions);
   } catch (Exception e) {
     logger.error("Execution failed.", e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }
コード例 #3
0
 public static QueryOptions createQueryOptions(JSONObject json) throws JSONException {
   QueryOptions queryOpts = new QueryOptions();
   queryOpts.setDataAccessId(json.getString("dataAccessId"));
   if (json.has("parameters")) {
     Object parameters = json.get("parameters");
     if (parameters instanceof JSONArray) {
       JSONArray parametersArray = (JSONArray) parameters;
       for (int i = 0; i < parametersArray.length(); i++) {
         JSONObject param = parametersArray.getJSONObject(i);
         String name = param.getString("name");
         JSONArray arrayOpt = param.optJSONArray("value");
         if (arrayOpt != null) {
           // array parameter
           String[] values = new String[(arrayOpt.length())];
           for (int j = 0; j < values.length; j++) {
             values[i] = arrayOpt.getString(j);
           }
           queryOpts.addParameter(name, values);
         } else {
           // regular parameter
           String value = param.getString("value");
           queryOpts.addParameter(name, value);
         }
       }
     }
   }
   // ensure cache is refreshed
   queryOpts.setCacheBypass(true);
   return queryOpts;
 }
コード例 #4
0
ファイル: SqlTest.java プロジェクト: pstoellberger/cda
  public void testSqlQuery() throws Exception {

    // Define an outputStream
    OutputStream out = System.out;

    logger.info("Building CDA settings from sample file");

    final SettingsManager settingsManager = SettingsManager.getInstance();
    URL file = this.getClass().getResource("sample-sql.cda");
    File settingsFile = new File(file.toURI());
    final CdaSettings cdaSettings =
        settingsManager.parseSettingsFile(settingsFile.getAbsolutePath());
    logger.debug("Doing query on Cda - Initializing CdaEngine");
    final CdaEngine engine = CdaEngine.getInstance();

    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate", "2003-04-01");
    queryOptions.setOutputType(ExporterEngine.OutputType.XML);
    // queryOptions.addParameter("status","In Process");

    logger.info("Doing first query");
    engine.doQuery(out, cdaSettings, queryOptions);

    logger.info("Doing query with different parameters");
    queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate", "2004-01-01");
    engine.doQuery(out, cdaSettings, queryOptions);

    // Querying 2nd time to test cache
    logger.info("Doing query using the initial parameters - Cache should be used");
    queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate", "2003-04-01");
    engine.doQuery(out, cdaSettings, queryOptions);

    // Querying 2nd time to test cache
    logger.info("Doing query again to see if cache expires");
    try {
      Thread.sleep(6000);
    } catch (InterruptedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
    engine.doQuery(out, cdaSettings, queryOptions);
  }
コード例 #5
0
ファイル: MdxJdbcTest.java プロジェクト: pstoellberger/cda
  public void testSqlQuery() throws Exception {

    // Define an outputStream
    OutputStream out = System.out;

    logger.info("Building CDA settings from sample file");

    final SettingsManager settingsManager = SettingsManager.getInstance();
    URL file = this.getClass().getResource("sample-mondrian.cda");
    File settingsFile = new File(file.toURI());
    final CdaSettings cdaSettings =
        settingsManager.parseSettingsFile(settingsFile.getAbsolutePath());
    logger.debug("Doing query on Cda - Initializing CdaEngine");
    final CdaEngine engine = CdaEngine.getInstance();

    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("2");
    queryOptions.setOutputType("json");
    queryOptions.addParameter("status", "Shipped");

    logger.info("Doing query");
    engine.doQuery(out, cdaSettings, queryOptions);
  }
コード例 #6
0
  public void testFormulaCacheSql() throws Exception {
    // Define an outputStream
    OutputStream out = System.out;

    logger.info("Building CDA settings from sample file");

    final SettingsManager settingsManager = SettingsManager.getInstance();
    URL file = this.getClass().getResource("sample-sql-formula.cda");
    File settingsFile = new File(file.toURI());
    final CdaSettings cdaSettings =
        settingsManager.parseSettingsFile(settingsFile.getAbsolutePath());
    logger.debug("Doing query on Cda - Initializing CdaEngine");
    final CdaEngine engine = CdaEngine.getInstance();

    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate", "${TODAY()}");
    queryOptions.setOutputType("csv");

    logger.info("Doing first query --> TODAY()");
    engine.doQuery(out, cdaSettings, queryOptions);

    logger.info("Doing query with different parameters");
    queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate", "${DATE(2004;1;1)}");
    engine.doQuery(out, cdaSettings, queryOptions);

    // Querying 2nd time to test cache (formula translated before cache check)
    logger.info("Doing query using manual TODAY - Cache should be used");
    queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    Calendar cal = Calendar.getInstance();
    queryOptions.addParameter(
        "orderDate",
        "${DATE("
            + cal.get(Calendar.YEAR)
            + ";"
            + (cal.get(Calendar.MONTH) + 1)
            + ";"
            + cal.get(Calendar.DAY_OF_MONTH)
            + ")}");
    engine.doQuery(out, cdaSettings, queryOptions);
  }
コード例 #7
0
  public void testSqlQuery() throws Exception {

    final CdaSettings cdaSettings = parseSettingsFile("sample-mondrian-compact.cda");

    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setOutputType("json");
    queryOptions.addParameter("status", "Shipped");

    logger.info("Doing query 1");
    queryOptions.setDataAccessId("1");
    doQuery(cdaSettings, queryOptions);

    logger.info("\nDoing query 2");
    queryOptions.setDataAccessId("2");
    doQuery(cdaSettings, queryOptions);

    logger.info("\nDoing query 3");
    queryOptions.setDataAccessId("3");
    doQuery(cdaSettings, queryOptions);

    logger.info("\nDoing query 4");
    queryOptions.setDataAccessId("4");
    doQuery(cdaSettings, queryOptions);
  }
コード例 #8
0
ファイル: CdaCoreService.java プロジェクト: jwarlander/cda
  public void doQuery(final OutputStream out, DoQueryParameters parameters) throws Exception {
    final CdaEngine engine = CdaEngine.getInstance();
    final QueryOptions queryOptions = new QueryOptions();

    final String path =
        getRelativePath(parameters.getPath(), parameters.getSolution(), parameters.getFile());
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFile(path);

    // Handle paging options
    // We assume that any paging options found mean that the user actively wants paging.
    final long pageSize = parameters.getPageSize();
    final long pageStart = parameters.getPageStart();
    final boolean paginate = parameters.isPaginateQuery();
    if (pageSize > 0 || pageStart > 0 || paginate) {
      if (pageSize > Integer.MAX_VALUE || pageStart > Integer.MAX_VALUE) {
        throw new ArithmeticException("Paging values too large");
      }
      queryOptions.setPaginate(true);
      queryOptions.setPageSize(pageSize > 0 ? (int) pageSize : paginate ? DEFAULT_PAGE_SIZE : 0);
      queryOptions.setPageStart(
          pageStart > 0 ? (int) pageStart : paginate ? DEFAULT_START_PAGE : 0);
    }

    // Support for bypassCache (we'll maintain the name we use in CDE
    /*if(requestParams.hasParameter("bypassCache")){
      queryOptions.setCacheBypass(Boolean.parseBoolean(requestParams.getStringParameter("bypassCache","false")));
    }*/

    queryOptions.setCacheBypass(parameters.isBypassCache());

    // Handle the query itself and its output format...
    queryOptions.setOutputType(parameters.getOutputType());
    queryOptions.setDataAccessId(parameters.getDataAccessId());
    try {
      queryOptions.setOutputIndexId(parameters.getOutputIndexId());
    } catch (NumberFormatException e) {
      logger.error("Illegal outputIndexId '" + parameters.getOutputIndexId() + "'");
    }

    final ArrayList<String> sortBy = new ArrayList<String>();
    String[] def = {};
    for (Object obj : parameters.getSortBy()) {
      if (!((String) obj).equals("")) {
        sortBy.add((String) obj);
      }
    }
    queryOptions.setSortBy(sortBy);

    // ... and the query parameters
    // We identify any pathParams starting with "param" as query parameters and extra settings
    // prefixed with "setting"
    @SuppressWarnings("unchecked")
    final Iterator settings = parameters.getExtraSettings().entrySet().iterator();
    while (settings.hasNext()) {
      Map.Entry<String, Object> pairs = (Map.Entry) settings.next();
      final String name = pairs.getKey();
      final Object parameter = pairs.getValue();
      queryOptions.addSetting(name, (String) parameter);
    }
    final Iterator params = parameters.getExtraParams().entrySet().iterator();
    while (params.hasNext()) {

      Map.Entry<String, Object> pairs = (Map.Entry) params.next();
      final String name = pairs.getKey();
      final Object parameter = pairs.getValue();
      queryOptions.addParameter(name, parameter);

      //      if(name.startsWith(PREFIX_PARAMETER)){
      //          queryOptions.addParameter(name.substring(PREFIX_PARAMETER.length()), parameter);
      //          logger.debug("##########"+name+"##############");

    }
    /*
    if (param.startsWith(PREFIX_PARAMETER))
    {
      queryOptions.addParameter(param.substring(PREFIX_PARAMETER.length()), requestParams.getParameter(param));
    }
    else if (param.startsWith(PREFIX_SETTING))
    {
      queryOptions.addSetting(param.substring(PREFIX_SETTING.length()), requestParams.getStringParameter(param, ""));
    }*/

    if (parameters.isWrapItUp()) {
      String uuid = engine.wrapQuery(out, cdaSettings, queryOptions);
      logger.debug("doQuery: query wrapped as " + uuid);
      writeOut(out, uuid);
      return;
    }

    // we'll allow for the special "callback" param to be used, and passed as settingcallback to
    // jsonp exports
    if (!parameters.getJsonCallback().equals("<blank>")) {
      queryOptions.addSetting(JSONP_CALLBACK, parameters.getJsonCallback());
    }
    Exporter exporter =
        ExporterEngine.getInstance()
            .getExporter(queryOptions.getOutputType(), queryOptions.getExtraSettings());

    String attachmentName = exporter.getAttachmentName();
    String mimeType = (attachmentName == null) ? null : getMimeType(attachmentName);
    if (StringUtils.isEmpty(mimeType)) {
      mimeType = exporter.getMimeType();
    }

    if (parameters != null) ; // XXX + FIXME ==  if (this.parameterProviders != null)
    {
      setResponseHeaders(mimeType, attachmentName);
    }
    // Finally, pass the query to the engine
    engine.doQuery(out, cdaSettings, queryOptions);
  }