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

Examples of org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria


            .getCriteria().get(0)).getValue());

      cliAction.setQuery("ProductId:TestProductId ProductName:TestProductName");
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      BooleanQueryCriteria bqc = (BooleanQueryCriteria) clientSetQuery
            .getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
      assertEquals("ProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
      assertEquals("ProductName",
            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
            .get(1)).getValue());

      cliAction
            .setQuery("ProductId:TestProductId NominalDate:[20020101 TO 20030101]");
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
      assertEquals("ProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
      assertEquals("NominalDate",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("20020101",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getStartValue());
      assertEquals("20030101",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getEndValue());
      assertTrue(((RangeQueryCriteria) bqc.getTerms().get(1)).getInclusive());

      cliAction
            .setQuery("ProductId:TestProductId NominalDate:{20020101 TO 20030101}");
      cliAction.execute(printer);
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
      assertEquals("ProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
      assertEquals("NominalDate",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("20020101",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getStartValue());
      assertEquals("20030101",
            ((RangeQueryCriteria) bqc.getTerms().get(1)).getEndValue());
      assertFalse(((RangeQueryCriteria) bqc.getTerms().get(1)).getInclusive());

      cliAction
            .setQuery("ProductId:TestProductId AND ProductName:TestProductName");
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.AND, bqc.getOperator());
      assertEquals("ProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
      assertEquals("ProductName",
            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
            .get(1)).getValue());

      cliAction
            .setQuery("ProductId:TestProductId OR ProductName:TestProductName");
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
      assertEquals("ProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
      assertEquals("ProductName",
            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
            .get(1)).getValue());

      cliAction
            .setQuery("(ProductId:TestProductId OR ProductName:TestProductName) AND NominalDate:20110120");
      cliAction.execute(printer);
      assertEquals(1, clientSetQuery.getCriteria().size());
      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
      assertEquals(2, bqc.getTerms().size());
      assertEquals(BooleanQueryCriteria.AND, bqc.getOperator());
      BooleanQueryCriteria subBqc = (BooleanQueryCriteria) bqc.getTerms()
            .get(0);
      assertEquals("ProductId",
            ((TermQueryCriteria) subBqc.getTerms().get(0)).getElementName());
      assertEquals("TestProductId",
            ((TermQueryCriteria) subBqc.getTerms().get(0)).getValue());
      assertEquals("ProductName",
            ((TermQueryCriteria) subBqc.getTerms().get(1)).getElementName());
      assertEquals("TestProductName", ((TermQueryCriteria) subBqc.getTerms()
            .get(1)).getValue());
      assertEquals("NominalDate",
            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
      assertEquals("20110120",
            ((TermQueryCriteria) bqc.getTerms().get(1)).getValue());
View Full Code Here


              if (query.getCriteria().size() == 0) {
                  getProductSql = "SELECT DISTINCT product_id FROM " + type.getName() + "_metadata";
              }else if (query.getCriteria().size() == 1) {
                  getProductSql = this.getSqlQuery(query.getCriteria().get(0), type);
              }else {
                  getProductSql = this.getSqlQuery(new BooleanQueryCriteria(query.getCriteria(), BooleanQueryCriteria.AND), type);
              }
              getProductSql += " ORDER BY product_id DESC ";
           
            } else {
             
              if (query.getCriteria().size() == 0) {
                getProductSql = "SELECT DISTINCT products.product_id FROM products, " + type.getName() + "_metadata"
                              + " WHERE products.product_id="+type.getName() + "_metadata.product_id";
              else if (query.getCriteria().size() == 1) {
                getProductSql = this.getSqlQuery(query.getCriteria().get(0), type);
              else {
                getProductSql = this.getSqlQuery(new BooleanQueryCriteria(query.getCriteria(), BooleanQueryCriteria.AND), type);
              }
              getProductSql += " ORDER BY products.product_datetime DESC ";
             
            }
           
View Full Code Here

                    ((RangeQueryCriteria)criteria).getStartValue():"");
            criteriaHash.put("elementEndValue", ((RangeQueryCriteria)criteria).getEndValue() != null ?
                    ((RangeQueryCriteria)criteria).getEndValue():"");
            criteriaHash.put("inclusive", Boolean.toString(((RangeQueryCriteria) criteria).getInclusive()));
        } else if(criteria instanceof BooleanQueryCriteria){
            BooleanQueryCriteria boolQuery = (BooleanQueryCriteria) criteria;
            criteriaHash.put("operator", new Integer(boolQuery.getOperator()));
            Vector<Hashtable<String, Object>> termsHash = new Vector<Hashtable<String, Object>>();
            List<QueryCriteria> terms = boolQuery.getTerms();
           
            for(int i=0;i<terms.size();i++){
                QueryCriteria term = terms.get(i);
                Hashtable<String, Object> termHash = getXmlRpcQueryCriteria(term);
                termsHash.add(termHash);
View Full Code Here

    }
   
    protected String getSqlQuery(QueryCriteria queryCriteria, ProductType type) throws ValidationLayerException, CatalogException {
        String sqlQuery = null;
        if (queryCriteria instanceof BooleanQueryCriteria) {
            BooleanQueryCriteria bqc = (BooleanQueryCriteria) queryCriteria;
            if (bqc.getOperator() == BooleanQueryCriteria.NOT) {             
                if (!this.productIdString) {
                  sqlQuery = "SELECT DISTINCT product_id FROM " + type.getName() + "_metadata WHERE product_id NOT IN (" + this.getSqlQuery(bqc.getTerms().get(0), type) + ")";
                } else {
                  sqlQuery = "SELECT DISTINCT products.product_id FROM products," + type.getName() + "_metadata"
                           + " WHERE products.product_id="+type.getName() + "_metadata.product_id"
                           + " AND products.product_id NOT IN (" + this.getSqlQuery(bqc.getTerms().get(0), type) + ")";
                }
            }else {
                sqlQuery = "(" + this.getSqlQuery(bqc.getTerms().get(0), type);
                String op = bqc.getOperator() == BooleanQueryCriteria.AND ? "INTERSECT" : "UNION";
                for (int i = 1; i < bqc.getTerms().size(); i++)
                    sqlQuery += ") " + op + " (" + this.getSqlQuery(bqc.getTerms().get(i), type);
                sqlQuery += ")";
            }
        }else {
            String elementIdStr = this.validationLayer.getElementByName(queryCriteria.getElementName()).getElementId();
            if (fieldIdStringFlag)
View Full Code Here

                    null : (String)criteriaHash.get("elementEndValue");
            ((RangeQueryCriteria)criteria).setStartValue(startVal);
            ((RangeQueryCriteria)criteria).setEndValue(endVal);
            ((RangeQueryCriteria)criteria).setInclusive(Boolean.parseBoolean((String) criteriaHash.get("inclusive")));
        } else if(((String)criteriaHash.get("class")).equals(BooleanQueryCriteria.class.getCanonicalName())){
            criteria = new BooleanQueryCriteria();
            try{
              ((BooleanQueryCriteria)criteria).setOperator( ((Integer)criteriaHash.get("operator")).intValue() );
            } catch (QueryFormulationException e){
                System.out.println("Error generating Boolean Query.");
            }
View Full Code Here

     * Overridden method from superclass to allow for null validation layer.
     */
    protected String getSqlQuery(QueryCriteria queryCriteria, ProductType type) throws ValidationLayerException, CatalogException {
      String sqlQuery = null;
      if (queryCriteria instanceof BooleanQueryCriteria) {
          BooleanQueryCriteria bqc = (BooleanQueryCriteria) queryCriteria;
          if (bqc.getOperator() == BooleanQueryCriteria.NOT) {
              if (!this.productIdString) {
                sqlQuery = "SELECT DISTINCT product_id FROM " + type.getName() + "_metadata WHERE product_id NOT IN (" + this.getSqlQuery(bqc.getTerms().get(0), type) + ")";
              } else {
                 sqlQuery = "SELECT DISTINCT products.product_id FROM products," + type.getName() + "_metadata"
                          + " WHERE products.product_id="+type.getName() + "_metadata.product_id"
                         + " AND products.product_id NOT IN (" + this.getSqlQuery(bqc.getTerms().get(0), type) + ")";
              }
          } else {
              sqlQuery = "(" + this.getSqlQuery(bqc.getTerms().get(0), type);
              String op = bqc.getOperator() == BooleanQueryCriteria.AND ? "INTERSECT" : "UNION";
              for (int i = 1; i < bqc.getTerms().size(); i++)
                  sqlQuery += ") " + op + " (" + this.getSqlQuery(bqc.getTerms().get(i), type);
              sqlQuery += ")";
          }
      }else {
          String elementIdStr = queryCriteria.getElementName();
          if (this.getValidationLayer()!=null) {
View Full Code Here

      } else if (luceneQuery instanceof PhraseQuery) {
         Term[] t = ((PhraseQuery) luceneQuery).getTerms();
         if (t[0].field().equals(FREE_TEXT_BLOCK)) {
            throw new Exception("Free text blocks not supported!");
         } else {
            BooleanQueryCriteria bqc = new BooleanQueryCriteria();
            bqc.setOperator(BooleanQueryCriteria.AND);
            for (int i = 0; i < t.length; i++) {
               bqc.addTerm(new TermQueryCriteria(t[i].field(), t[i]
                     .text()));
            }
            return bqc;
         }
      } else if (luceneQuery instanceof RangeQuery) {
         Term startT = ((RangeQuery) luceneQuery).getLowerTerm();
         Term endT = ((RangeQuery) luceneQuery).getUpperTerm();
         return new RangeQueryCriteria(startT.field(), startT
               .text(), endT.text(), ((RangeQuery) luceneQuery).isInclusive());
      } else if (luceneQuery instanceof BooleanQuery) {
         BooleanClause[] clauses = ((BooleanQuery) luceneQuery).getClauses();
         BooleanQueryCriteria bqc = new BooleanQueryCriteria();
         bqc.setOperator(BooleanQueryCriteria.AND);
         for (int i = 0; i < clauses.length; i++) {
            if (clauses[i].getOccur().equals(BooleanClause.Occur.SHOULD)) {
               bqc.setOperator(BooleanQueryCriteria.OR);
            }
            bqc.addTerm(generateCASQuery(clauses[i].getQuery()));
         }
         return bqc;
      } else {
         throw new Exception(
               "Error parsing query! Cannot determine clause type: ["
View Full Code Here

                    ((RangeQueryCriteria)criteria).getStartValue():"");
            criteriaHash.put("elementEndValue", ((RangeQueryCriteria)criteria).getEndValue() != null ?
                    ((RangeQueryCriteria)criteria).getEndValue():"");
            criteriaHash.put("inclusive", Boolean.toString(((RangeQueryCriteria) criteria).getInclusive()));
        } else if(criteria instanceof BooleanQueryCriteria){
            BooleanQueryCriteria boolQuery = (BooleanQueryCriteria) criteria;
            criteriaHash.put("operator", new Integer(boolQuery.getOperator()));
            Vector<Hashtable<String, Object>> termsHash = new Vector<Hashtable<String, Object>>();
            List<QueryCriteria> terms = boolQuery.getTerms();
           
            for(int i=0;i<terms.size();i++){
                QueryCriteria term = terms.get(i);
                Hashtable<String, Object> termHash = getXmlRpcQueryCriteria(term);
                termsHash.add(termHash);
View Full Code Here

                    null : (String)criteriaHash.get("elementEndValue");
            ((RangeQueryCriteria)criteria).setStartValue(startVal);
            ((RangeQueryCriteria)criteria).setEndValue(endVal);
            ((RangeQueryCriteria)criteria).setInclusive(Boolean.parseBoolean((String) criteriaHash.get("inclusive")));
        } else if(((String)criteriaHash.get("class")).equals(BooleanQueryCriteria.class.getCanonicalName())){
            criteria = new BooleanQueryCriteria();
            try{
              ((BooleanQueryCriteria)criteria).setOperator( ((Integer)criteriaHash.get("operator")).intValue() );
            } catch (QueryFormulationException e){
                System.out.println("Error generating Boolean Query.");
            }
View Full Code Here

                    ((RangeQueryCriteria)criteria).getStartValue():"");
            criteriaHash.put("elementEndValue", ((RangeQueryCriteria)criteria).getEndValue() != null ?
                    ((RangeQueryCriteria)criteria).getEndValue():"");
            criteriaHash.put("inclusive", Boolean.toString(((RangeQueryCriteria) criteria).getInclusive()));
        } else if(criteria instanceof BooleanQueryCriteria){
            BooleanQueryCriteria boolQuery = (BooleanQueryCriteria) criteria;
            criteriaHash.put("operator", new Integer(boolQuery.getOperator()));
            Vector<Hashtable<String, Object>> termsHash = new Vector<Hashtable<String, Object>>();
            List<QueryCriteria> terms = boolQuery.getTerms();
           
            for(int i=0;i<terms.size();i++){
                QueryCriteria term = terms.get(i);
                Hashtable<String, Object> termHash = getXmlRpcQueryCriteria(term);
                termsHash.add(termHash);
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria

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.