Package org.apache.oodt.cas.filemgr.structs.query

Examples of org.apache.oodt.cas.filemgr.structs.query.ComplexQuery


   @Override
   public void execute(ActionMessagePrinter printer)
         throws CmdLineActionException {
      try {
         ComplexQuery complexQuery = getQuery();
         complexQuery.setSortByMetKey(sortBy);
         complexQuery.setToStringResultFormat(outputFormat);

         if (filterAlgor != null) {
            Validate.notNull(startDateTimeMetKey,
                  "Must specify startDateTimeMetKey");
            Validate.notNull(endDateTimeMetKey,
                  "Must specify endDateTimeMetKey");
            Validate.notNull(priorityMetKey, "Must specify priorityMetKey");
            QueryFilter filter = new QueryFilter(startDateTimeMetKey,
                  endDateTimeMetKey, priorityMetKey, filterAlgor);
            if (versionConverter != null) {
               filter.setConverter(versionConverter);
            }
            complexQuery.setQueryFilter(filter);
         }
         List<QueryResult> results = getClient().complexQuery(complexQuery);
         StringBuffer returnString = new StringBuffer("");
         for (QueryResult qr : results) {
            returnString.append(qr.toString() + delimiter);
View Full Code Here


   @Override
   public ComplexQuery getQuery() throws Exception {
      Validate.notNull(query, "Must specify query");

      ComplexQuery complexQuery = new ComplexQuery();
      complexQuery.setCriteria(Lists.newArrayList(generateCASQuery(parseQuery(query))));
      complexQuery.setReducedProductTypeNames(reducedProductTypes);
      complexQuery.setReducedMetadata(reducedMetadataKeys);
      return complexQuery;
   }
View Full Code Here

            complexQueryHash.put("queryFilter", getXmlRpcQueryFilter(complexQuery.getQueryFilter()));
        return complexQueryHash;
    }
   
    public static ComplexQuery getComplexQueryFromXmlRpc(Hashtable<String, Object> complexQueryHash) {
        ComplexQuery complexQuery = new ComplexQuery();
        complexQuery.setCriteria(getQueryFromXmlRpc(complexQueryHash).getCriteria());
        if (((Vector<String>) complexQueryHash.get("reducedProductTypeNames")).size() > 0)
            complexQuery.setReducedProductTypeNames((Vector<String>) complexQueryHash.get("reducedProductTypeNames"));
        if (((Vector<String>) complexQueryHash.get("reducedMetadata")).size() > 0)
            complexQuery.setReducedMetadata((Vector<String>) complexQueryHash.get("reducedMetadata"));
        complexQuery.setSortByMetKey((String) complexQueryHash.get("sortByMetKey"));
        complexQuery.setToStringResultFormat((String) complexQueryHash.get("toStringResultFormat"));
        if (complexQueryHash.get("queryFilter") != null)
            complexQuery.setQueryFilter(getQueryFilterFromXmlRpc((Hashtable<String, Object>) complexQueryHash.get("queryFilter")));
        return complexQuery;
    }
View Full Code Here

    }

    public Vector<Hashtable<String, Object>> complexQuery(
            Hashtable<String, Object> complexQueryHash) throws CatalogException {
        try {
            ComplexQuery complexQuery = XmlRpcStructFactory
                    .getComplexQueryFromXmlRpc(complexQueryHash);

            // get ProductTypes
            List<ProductType> productTypes = null;
            if (complexQuery.getReducedProductTypeNames() == null) {
                productTypes = this.repositoryManager.getProductTypes();
            } else {
                productTypes = new Vector<ProductType>();
                for (String productTypeName : complexQuery
                        .getReducedProductTypeNames())
                    productTypes.add(this.repositoryManager
                            .getProductTypeByName(productTypeName));
            }

            // get Metadata
            List<QueryResult> queryResults = new LinkedList<QueryResult>();
            for (ProductType productType : productTypes) {
                List<String> productIds = catalog.query(this.getCatalogQuery(
                        complexQuery, productType), productType);
                for (String productId : productIds) {
                    Product product = catalog.getProductById(productId);
                    product.setProductType(productType);
                    QueryResult qr = new QueryResult(product, this
                            .getReducedMetadata(product, complexQuery
                                    .getReducedMetadata()));
                    qr.setToStringFormat(complexQuery
                            .getToStringResultFormat());
                    queryResults.add(qr);
                }
            }

            LOG.log(Level.INFO, "Query returned " + queryResults.size()
                    + " results");

            // filter query results
            if (complexQuery.getQueryFilter() != null) {
                queryResults = applyFilterToResults(queryResults, complexQuery
                        .getQueryFilter());
                LOG.log(Level.INFO, "Filter returned " + queryResults.size()
                        + " results");
            }

            // sort query results
            if (complexQuery.getSortByMetKey() != null)
                queryResults = sortQueryResultList(queryResults, complexQuery
                        .getSortByMetKey());

            return XmlRpcStructFactory.getXmlRpcQueryResults(queryResults);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

        prodMet.replaceMetadata(CoreMetKeys.PRODUCT_NAME, "TestFile2");
        ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
            "./src/testdata/ingest/test-file-2.txt"), prodMet);  
       
        //perform complex query
        ComplexQuery complexQuery = new ComplexQuery();
        List<String> reducedMetadata = new Vector<String>();
        reducedMetadata.add(CoreMetKeys.FILENAME);
        complexQuery.setReducedMetadata(reducedMetadata);
        List<String> productTypeNames = new Vector<String>();
        productTypeNames.add("GenericFile");
        complexQuery.setReducedProductTypeNames(productTypeNames);
        complexQuery.setSortByMetKey(CoreMetKeys.FILENAME);
        complexQuery.setToStringResultFormat("$" + CoreMetKeys.FILENAME);
        complexQuery.addCriterion(SqlParser.parseSqlWhereClause("Filename != 'test.txt'"));
        XmlRpcFileManagerClient fmc = new XmlRpcFileManagerClient(new URL(
                "http://localhost:" + FM_PORT));
        List<QueryResult> queryResults = fmc.complexQuery(complexQuery);
        assertEquals("[test-file-1.txt, test-file-2.txt]", queryResults.toString());
    }
View Full Code Here

            complexQueryHash.put("queryFilter", getXmlRpcQueryFilter(complexQuery.getQueryFilter()));
        return complexQueryHash;
    }
   
    public static ComplexQuery getComplexQueryFromXmlRpc(Hashtable<String, Object> complexQueryHash) {
        ComplexQuery complexQuery = new ComplexQuery();
        complexQuery.setCriteria(getQueryFromXmlRpc(complexQueryHash).getCriteria());
        if (((Vector<String>) complexQueryHash.get("reducedProductTypeNames")).size() > 0)
            complexQuery.setReducedProductTypeNames((Vector<String>) complexQueryHash.get("reducedProductTypeNames"));
        if (((Vector<String>) complexQueryHash.get("reducedMetadata")).size() > 0)
            complexQuery.setReducedMetadata((Vector<String>) complexQueryHash.get("reducedMetadata"));
        complexQuery.setSortByMetKey((String) complexQueryHash.get("sortByMetKey"));
        complexQuery.setToStringResultFormat((String) complexQueryHash.get("toStringResultFormat"));
        if (complexQueryHash.get("queryFilter") != null)
            complexQuery.setQueryFilter(getQueryFilterFromXmlRpc((Hashtable<String, Object>) complexQueryHash.get("queryFilter")));
        return complexQuery;
    }
View Full Code Here

    }
   
    private static String performSqlQuery(String query, String sortBy, String outputFormat, String delimiter, String filemgrUrl)
            throws MalformedURLException, CatalogException, ConnectionException, QueryFormulationException {
        ComplexQuery complexQuery = SqlParser.parseSqlQuery(query);
        complexQuery.setSortByMetKey(sortBy);
        complexQuery.setToStringResultFormat(outputFormat);
        List<QueryResult> results = new XmlRpcFileManagerClient(new URL(filemgrUrl)).complexQuery(complexQuery);
        StringBuffer returnString = new StringBuffer("");
        for (QueryResult qr : results)
            returnString.append(qr.toString() + delimiter);
        return returnString.substring(0, returnString.length() - delimiter.length());
View Full Code Here

    }

    public Vector<Hashtable<String, Object>> complexQuery(
            Hashtable<String, Object> complexQueryHash) throws CatalogException {
        try {
            ComplexQuery complexQuery = XmlRpcStructFactory
                    .getComplexQueryFromXmlRpc(complexQueryHash);

            // get ProductTypes
            List<ProductType> productTypes = null;
            if (complexQuery.getReducedProductTypeNames() == null) {
                productTypes = this.repositoryManager.getProductTypes();
            } else {
                productTypes = new Vector<ProductType>();
                for (String productTypeName : complexQuery
                        .getReducedProductTypeNames())
                    productTypes.add(this.repositoryManager
                            .getProductTypeByName(productTypeName));
            }

            // get Metadata
            List<QueryResult> queryResults = new LinkedList<QueryResult>();
            for (ProductType productType : productTypes) {
                List<String> productIds = catalog.query(this.getCatalogQuery(
                        complexQuery, productType), productType);
                for (String productId : productIds) {
                    Product product = catalog.getProductById(productId);
                    product.setProductType(productType);
                    QueryResult qr = new QueryResult(product, this
                            .getReducedMetadata(product, complexQuery
                                    .getReducedMetadata()));
                    qr.setToStringFormat(complexQuery
                            .getToStringResultFormat());
                    queryResults.add(qr);
                }
            }

            LOG.log(Level.INFO, "Query returned " + queryResults.size()
                    + " results");

            // filter query results
            if (complexQuery.getQueryFilter() != null) {
                queryResults = applyFilterToResults(queryResults, complexQuery
                        .getQueryFilter());
                LOG.log(Level.INFO, "Filter returned " + queryResults.size()
                        + " results");
            }

            // sort query results
            if (complexQuery.getSortByMetKey() != null)
                queryResults = sortQueryResultList(queryResults, complexQuery
                        .getSortByMetKey());

            return XmlRpcStructFactory.getXmlRpcQueryResults(queryResults);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

        prodMet.replaceMetadata(CoreMetKeys.PRODUCT_NAME, "TestFile2");
        ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
            "./src/testdata/ingest/test-file-2.txt"), prodMet);  
       
        //perform complex query
        ComplexQuery complexQuery = new ComplexQuery();
        List<String> reducedMetadata = new Vector<String>();
        reducedMetadata.add(CoreMetKeys.FILENAME);
        complexQuery.setReducedMetadata(reducedMetadata);
        List<String> productTypeNames = new Vector<String>();
        productTypeNames.add("GenericFile");
        complexQuery.setReducedProductTypeNames(productTypeNames);
        complexQuery.setSortByMetKey(CoreMetKeys.FILENAME);
        complexQuery.setToStringResultFormat("$" + CoreMetKeys.FILENAME);
        complexQuery.addCriterion(SqlParser.parseSqlWhereClause("Filename != 'test.txt'"));
        XmlRpcFileManagerClient fmc = new XmlRpcFileManagerClient(new URL(
                "http://localhost:" + FM_PORT));
        List<QueryResult> queryResults = fmc.complexQuery(complexQuery);
        assertEquals("[test-file-1.txt, test-file-2.txt]", queryResults.toString());
    }
View Full Code Here

                  + " --reducedProductTypes " + reducedProductTypes
                  + " --sortBy " + sortBy
                  + " --delimiter " + delimiter).split(" "));
      methodCallDetails = client.getLastMethodCallDetails();
      assertEquals("complexQuery", methodCallDetails.getMethodName());
      ComplexQuery complexQuery = (ComplexQuery) methodCallDetails.getArgs().get(0);
      assertEquals("ProductId", ((TermQueryCriteria) complexQuery.getCriteria().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) complexQuery.getCriteria().get(0)).getValue());
      assertEquals(Lists.newArrayList(reducedMetadataKeys.split(" ")), complexQuery.getReducedMetadata());
      assertEquals(outputFormat, complexQuery.getToStringResultFormat());
      assertEquals(Lists.newArrayList(reducedProductTypes.split(" ")), complexQuery.getReducedProductTypeNames());
      assertEquals(sortBy, complexQuery.getSortByMetKey());
   }
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.filemgr.structs.query.ComplexQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.