public static Map<String, Object> getXmlRpcQueryCriteria(QueryCriteria criteria) { Map<String, Object> criteriaHash = new Hashtable<String, Object>(); criteriaHash.put("class", criteria.getClass().getCanonicalName()); if (criteria instanceof TermQueryCriteria) { criteriaHash.put("elementName", criteria.getElementName()); criteriaHash.put("elementValue", ((TermQueryCriteria) criteria).getValue()); } else if (criteria instanceof RangeQueryCriteria) { criteriaHash.put("elementName", criteria.getElementName()); criteriaHash.put("elementStartValue", ((RangeQueryCriteria) criteria).getStartValue() != null ? ((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", boolQuery.getOperator()); Vector<Map<String, Object>> termsHash = new Vector<Map<String, Object>>(); List<QueryCriteria> terms = boolQuery.getTerms(); for (QueryCriteria term : terms) { Map<String, Object> termHash = getXmlRpcQueryCriteria(term); termsHash.add(termHash); } criteriaHash.put("terms", termsHash); } return criteriaHash; }
if (criteriaHash.get("class").equals(TermQueryCriteria.class.getCanonicalName())) { criteria = new TermQueryCriteria(); criteria.setElementName((String) criteriaHash.get("elementName")); ((TermQueryCriteria) criteria).setValue((String) criteriaHash.get("elementValue")); } else if (criteriaHash.get("class").equals(RangeQueryCriteria.class.getCanonicalName())) { criteria = new RangeQueryCriteria(); criteria.setElementName((String) criteriaHash.get("elementName")); String startVal = criteriaHash.get("elementStartValue").equals("") ? null : (String) criteriaHash.get("elementStartValue");
/** * @return A String representation of this Query. */ public String toString() { StringBuilder rStr = new StringBuilder(); rStr.append("q="); int numCriteria = criteria.size(); for (int i = 0; i < numCriteria; i++) { QueryCriteria c = (QueryCriteria) criteria.get(i); rStr.append(c.toString()); if (i != numCriteria - 1) { rStr.append(" AND "); } } return rStr.toString(); }
public static Map<String, Object> getXmlRpcQueryCriteria(QueryCriteria criteria) { Map<String, Object> criteriaHash = new Hashtable<String, Object>(); criteriaHash.put("class", criteria.getClass().getCanonicalName()); if (criteria instanceof TermQueryCriteria) { criteriaHash.put("elementName", criteria.getElementName()); criteriaHash.put("elementValue", ((TermQueryCriteria) criteria).getValue()); } else if (criteria instanceof RangeQueryCriteria) { criteriaHash.put("elementName", criteria.getElementName()); criteriaHash.put("elementStartValue", ((RangeQueryCriteria) criteria).getStartValue() != null ? ((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", boolQuery.getOperator()); Vector<Map<String, Object>> termsHash = new Vector<Map<String, Object>>(); List<QueryCriteria> terms = boolQuery.getTerms(); for (QueryCriteria term : terms) { Map<String, Object> termHash = getXmlRpcQueryCriteria(term); termsHash.add(termHash); } criteriaHash.put("terms", termsHash); } return criteriaHash; }
/** * @return A String representation of this Query. */ public String toString() { StringBuilder rStr = new StringBuilder(); rStr.append("q="); int numCriteria = criteria.size(); for (int i = 0; i < numCriteria; i++) { QueryCriteria c = (QueryCriteria) criteria.get(i); rStr.append(c.toString()); if (i != numCriteria - 1) { rStr.append(" AND "); } } return rStr.toString(); }
if (criteriaHash.get("class").equals(TermQueryCriteria.class.getCanonicalName())) { criteria = new TermQueryCriteria(); criteria.setElementName((String) criteriaHash.get("elementName")); ((TermQueryCriteria) criteria).setValue((String) criteriaHash.get("elementValue")); } else if (criteriaHash.get("class").equals(RangeQueryCriteria.class.getCanonicalName())) { criteria = new RangeQueryCriteria(); criteria.setElementName((String) criteriaHash.get("elementName")); String startVal = criteriaHash.get("elementStartValue").equals("") ? null : (String) criteriaHash.get("elementStartValue");
private QueryCriteria handleQueryCriteria(QueryCriteria qc) throws QueryFormulationException { if (qc instanceof BooleanQueryCriteria) { LinkedList<QueryCriteria> qcList = new LinkedList<QueryCriteria>(); for (QueryCriteria criteria : ((BooleanQueryCriteria) qc).getTerms()) { qcList.add(this.handleQueryCriteria(criteria)); } BooleanQueryCriteria bqc = new BooleanQueryCriteria(); bqc.setOperator(((BooleanQueryCriteria) qc).getOperator()); bqc.setElementName(qc.getElementName()); for (QueryCriteria criteria : qcList) { bqc.addTerm(criteria); } return bqc; }else if (qc.getElementName().equals(elementName) && qc instanceof TermQueryCriteria) { return this.handleTermQueryCriteria((TermQueryCriteria) qc); }else if (qc.getElementName().equals(elementName) && qc instanceof RangeQueryCriteria) { return this.handleRangeQueryCriteria((RangeQueryCriteria) qc); }else { return qc; } }
/** * Method to convert the query to a string. * * @return string equivement of the query */ public String toString() { StringBuilder query = new StringBuilder(); if (operator == AND) { query.append("AND("); } else if (operator == OR) { query.append("OR("); } else { query.append("NOT("); } for (int i = 0; i < terms.size(); i++) { query.append(terms.get(i).toString()); if (i < (terms.size() - 1)) { query.append(", "); } } query.append(")"); return query.toString(); } }
if(avroQueryCriteria.getClassName().equals(TermQueryCriteria.class.getCanonicalName())){ queryCriteria = new TermQueryCriteria(); queryCriteria.setElementName(avroQueryCriteria.getElementName()); ((TermQueryCriteria)queryCriteria).setValue(avroQueryCriteria.getElementValue()); }else if (avroQueryCriteria.getClassName().equals(RangeQueryCriteria.class.getCanonicalName())){ queryCriteria = new RangeQueryCriteria(); queryCriteria.setElementName(avroQueryCriteria.getElementName()); ((RangeQueryCriteria)queryCriteria).setStartValue(avroQueryCriteria.getElementStartValue()); ((RangeQueryCriteria)queryCriteria).setEndValue(avroQueryCriteria.getElementEndValue());
private QueryCriteria handleQueryCriteria(QueryCriteria qc) throws QueryFormulationException { if (qc instanceof BooleanQueryCriteria) { LinkedList<QueryCriteria> qcList = new LinkedList<QueryCriteria>(); for (QueryCriteria criteria : ((BooleanQueryCriteria) qc).getTerms()) { qcList.add(this.handleQueryCriteria(criteria)); } BooleanQueryCriteria bqc = new BooleanQueryCriteria(); bqc.setOperator(((BooleanQueryCriteria) qc).getOperator()); bqc.setElementName(qc.getElementName()); for (QueryCriteria criteria : qcList) { bqc.addTerm(criteria); } return bqc; }else if (qc.getElementName().equals(elementName) && qc instanceof TermQueryCriteria) { return this.handleTermQueryCriteria((TermQueryCriteria) qc); }else if (qc.getElementName().equals(elementName) && qc instanceof RangeQueryCriteria) { return this.handleRangeQueryCriteria((RangeQueryCriteria) qc); }else { return qc; } }
/** * Method to convert the query to a string. * * @return string equivement of the query */ public String toString() { StringBuilder query = new StringBuilder(); if (operator == AND) { query.append("AND("); } else if (operator == OR) { query.append("OR("); } else { query.append("NOT("); } for (int i = 0; i < terms.size(); i++) { query.append(terms.get(i).toString()); if (i < (terms.size() - 1)) { query.append(", "); } } query.append(")"); return query.toString(); } }
fieldIdStringFlag ? "'" + this.validationLayer.getElementByName(criteria.getElementName()) .getElementId() + "'" : this.validationLayer.getElementByName(criteria.getElementName()).getElementId();
/** * Common utility to retrieve a range of products matching the specified {@link Query} and {@link ProductType}. * This method transforms the given constraints in a map of HTTP (name, value) pairs and delegates to the following method. * * @param query * @param type * @param offset * @param limit * @return * @throws CatalogException */ private QueryResponse getProducts(Query query, ProductType type, int offset, int limit) throws CatalogException { // build HTTP request ConcurrentHashMap<String, String[]> params = new ConcurrentHashMap<String, String[]>(); // product type constraint params.put("q", new String[]{Parameters.PRODUCT_TYPE_NAME+":"+type.getName()} ); // convert filemgr query into a Solr query List<String> qc = new ArrayList<String>(); for (QueryCriteria queryCriteria : query.getCriteria()) { LOG.info("Query criteria="+queryCriteria.toString()); qc.add(queryCriteria.toString()); } params.put("fq", qc.toArray( new String[ qc.size() ] )); // sort params.put("sort", new String[]{ Parameters.PRODUCT_RECEIVED_TIME+" desc"} ); return this.getProducts(params, offset, limit); }
fieldIdStringFlag ? "'" + this.validationLayer.getElementByName(criteria.getElementName()) .getElementId() + "'" : this.validationLayer.getElementByName(criteria.getElementName()).getElementId();
/** * Common utility to retrieve a range of products matching the specified {@link Query} and {@link ProductType}. * This method transforms the given constraints in a map of HTTP (name, value) pairs and delegates to the following method. * * @param query * @param type * @param offset * @param limit * @return * @throws CatalogException */ private QueryResponse getProducts(Query query, ProductType type, int offset, int limit) throws CatalogException { // build HTTP request ConcurrentHashMap<String, String[]> params = new ConcurrentHashMap<String, String[]>(); // product type constraint params.put("q", new String[]{Parameters.PRODUCT_TYPE_NAME+":"+type.getName()} ); // convert filemgr query into a Solr query List<String> qc = new ArrayList<String>(); for (QueryCriteria queryCriteria : query.getCriteria()) { LOG.info("Query criteria="+queryCriteria.toString()); qc.add(queryCriteria.toString()); } params.put("fq", qc.toArray( new String[ qc.size() ] )); // sort params.put("sort", new String[]{ Parameters.PRODUCT_RECEIVED_TIME+" desc"} ); return this.getProducts(params, offset, limit); }
String elementIdStr = this.validationLayer.getElementByName(queryCriteria.getElementName()).getElementId(); if (fieldIdStringFlag) { elementIdStr = "'" + elementIdStr + "'";
String elementIdStr = this.validationLayer.getElementByName(queryCriteria.getElementName()).getElementId(); if (fieldIdStringFlag) { elementIdStr = "'" + elementIdStr + "'";
if (getValidationLayer() != null) { elementIdStr = "'" + this.getValidationLayer().getElementByName(criteria.getElementName()).getElementId() + "'"; } else { elementIdStr = "'" + criteria.getElementName() + "'"; elementIdStr = this.getValidationLayer().getElementByName(criteria.getElementName()).getElementId(); } else { elementIdStr = criteria.getElementName();
occur = BooleanClause.Occur.MUST_NOT; booleanQuery.add(new WildcardQuery(new Term(((BooleanQueryCriteria) queryCriteria) .getTerms().get(0).getElementName(), "*")), BooleanClause.Occur.SHOULD); break; default: } else if (queryCriteria instanceof TermQueryCriteria) { String val = ((TermQueryCriteria) queryCriteria).getValue(); return new TermQuery(new Term(queryCriteria.getElementName(), val)); } else if (queryCriteria instanceof RangeQueryCriteria) { String startVal = ((RangeQueryCriteria) queryCriteria).getStartValue(); Term startTerm = null; if (!startVal.equals("")) { startTerm = new Term(queryCriteria.getElementName(), startVal);
if (getValidationLayer() != null) { elementIdStr = "'" + this.getValidationLayer().getElementByName(criteria.getElementName()).getElementId() + "'"; } else { elementIdStr = "'" + criteria.getElementName() + "'"; elementIdStr = this.getValidationLayer().getElementByName(criteria.getElementName()).getElementId(); } else { elementIdStr = criteria.getElementName();