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

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


    }
   
    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


            throws QueryFormulationException {
        if (!Pattern.matches("((?:SQL)|(?:sql))\\s*(.*)\\s*\\{\\s*SELECT.*FROM.*(?:WHERE.*){0,1}\\}", sqlStringQueryMethod))
            throw new QueryFormulationException("Malformed SQL method");
       
        try {
            ComplexQuery complexQuery = parseSqlQuery(stripOutSqlDefinition(sqlStringQueryMethod));
           
            for (Expression expr : getSqlStatementArgs(sqlStringQueryMethod)) {
                if (expr.getKey().toUpperCase().equals("FORMAT"))
                    complexQuery.setToStringResultFormat(expr.getValue());
                else if (expr.getKey().toUpperCase().equals("SORT_BY"))
                    complexQuery.setSortByMetKey(expr.getValue());
                else if (expr.getKey().toUpperCase().equals("FILTER"))
                    complexQuery.setQueryFilter(createFilter(expr));
            }
           
            return complexQuery;
        }catch (Exception e) {
            e.printStackTrace();
View Full Code Here

            throws QueryFormulationException {
        String[] splitSqlStatement = sqlStringQuery
                .split("((?:SELECT)|(?:FROM)|(?:WHERE))");
        String[] selectValues = (splitSqlStatement[1].trim() + ",").split(",");
        String[] fromValues = (splitSqlStatement[2].trim() + ",").split(",");
        ComplexQuery sq = new ComplexQuery();
        List<String> selectValuesList = Arrays.asList(selectValues);
        if (!selectValuesList.contains("*"))
            sq.setReducedMetadata(Arrays.asList(selectValues));
        List<String> fromValuesList = Arrays.asList(fromValues);
        if (!fromValuesList.contains("*"))
            sq.setReducedProductTypeNames(fromValuesList);
       
        if (splitSqlStatement.length > 3)
            sq.addCriterion(parseStatement(toPostFix(splitSqlStatement[3]
                    .trim())));
        return sq;
    }
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(
            refUrl2.getFile()), 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

        return complexQueryHash;
    }
   
    @SuppressWarnings("unchecked")
    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

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.