Author: bfoster
Date: Thu Dec 8 02:12:51 2011
New Revision: 1211740
URL: http://svn.apache.org/viewvc?rev=1211740&view=rev
Log:
- Add support for LuceneQuery action to optionally return more than just
Product ID results
-------------------
OODT-363
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java
(with props)
Modified:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/SqlQueryCliAction.java
oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
Added:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java?rev=1211740&view=auto
==============================================================================
---
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java
(added)
+++
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java
Thu Dec 8 02:12:51 2011
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.cli.action;
+
+//JDK imports
+import java.util.List;
+
+//Apache imports
+import org.apache.commons.lang.Validate;
+
+//OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryFilter;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
+import org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+
+/**
+ * Abstract query {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public abstract class AbstractQueryCliAction extends FileManagerCliAction {
+
+ private String sortBy;
+ private String outputFormat;
+ private String delimiter;
+
+ private FilterAlgor filterAlgor;
+ private String startDateTimeMetKey;
+ private String endDateTimeMetKey;
+ private String priorityMetKey;
+ private VersionConverter versionConverter;
+
+ public AbstractQueryCliAction() {
+ delimiter = "\n";
+ }
+
+ @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);
+ }
+ if (returnString.length() > 0) {
+ printer.println(returnString.substring(0, returnString.length()
+ - delimiter.length()));
+ } else {
+ printer.println("Query returned no results");
+ }
+ } catch (Exception e) {
+ throw new CmdLineActionException("Failed to perform sql query : "
+ + "sortBy '"
+ + sortBy
+ + "', "
+ + "outputFormat '"
+ + outputFormat
+ + "', and delimiter '"
+ + delimiter
+ + "', filterAlgor '"
+ + (filterAlgor != null ? filterAlgor.getClass()
+ .getCanonicalName() : null)
+ + "', startDateTimeMetKey '"
+ + startDateTimeMetKey
+ + "', endDateTimeMetKey '"
+ + endDateTimeMetKey
+ + "', priorityMetKey '"
+ + priorityMetKey
+ + "', "
+ + (versionConverter != null ? versionConverter.getClass()
+ .getCanonicalName() : null) + "' : " + e.getMessage(), e);
+ }
+ }
+
+ public abstract ComplexQuery getQuery() throws Exception;
+
+ public void setSortBy(String sortBy) {
+ this.sortBy = sortBy;
+ }
+
+ public void setOutputFormat(String outputFormat) {
+ this.outputFormat = outputFormat;
+ }
+
+ public void setDelimiter(String delimiter) {
+ this.delimiter = delimiter;
+ }
+
+ public void setFilterAlgor(FilterAlgor filterAlgor) {
+ this.filterAlgor = filterAlgor;
+ }
+
+ public void setStartDateTimeMetKey(String startDateTimeMetKey) {
+ this.startDateTimeMetKey = startDateTimeMetKey;
+ }
+
+ public void setEndDateTimeMetKey(String endDateTimeMetKey) {
+ this.endDateTimeMetKey = endDateTimeMetKey;
+ }
+
+ public void setPriorityMetKey(String priorityMetKey) {
+ this.priorityMetKey = priorityMetKey;
+ }
+
+ public void setVersionConverter(VersionConverter versionConverter) {
+ this.versionConverter = versionConverter;
+ }
+}
Propchange:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/AbstractQueryCliAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java
(original)
+++
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/LuceneQueryCliAction.java
Thu Dec 8 02:12:51 2011
@@ -32,14 +32,11 @@ import org.apache.lucene.search.RangeQue
import org.apache.lucene.search.TermQuery;
//OODT imports
-import org.apache.oodt.cas.cli.exception.CmdLineActionException;
import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.filemgr.structs.ProductType;
import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
-import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
import org.apache.oodt.cas.filemgr.tools.CASAnalyzer;
//Google imports
@@ -51,67 +48,47 @@ import com.google.common.collect.Lists;
*
* @author bfoster (Brian Foster)
*/
-public class LuceneQueryCliAction extends FileManagerCliAction {
+public class LuceneQueryCliAction extends AbstractQueryCliAction {
private static final String FREE_TEXT_BLOCK = "__FREE__";
private String query;
+ private List<String> reducedProductTypes;
+ private List<String> reducedMetadataKeys;
+
+ public LuceneQueryCliAction() {
+ super();
+ }
@Override
- public void execute(ActionMessagePrinter printer)
- throws CmdLineActionException {
- try {
- Validate.notNull(query, "Must specify query");
-
- XmlRpcFileManagerClient client = getClient();
- List<ProductType> productTypes = client.getProductTypes();
- if (productTypes == null) {
- throw new Exception("FileManager return null list of product
types");
- }
- org.apache.oodt.cas.filemgr.structs.Query casQuery = new
org.apache.oodt.cas.filemgr.structs.Query();
-
casQuery.setCriteria(Lists.newArrayList(generateCASQuery(parseQuery(query))));
+ public ComplexQuery getQuery() throws Exception {
+ Validate.notNull(query, "Must specify query");
- List<String> productIds = query(client, casQuery, productTypes);
- if (productIds == null) {
- throw new Exception("FileManager returned null list of Product
IDs");
- }
- for (String productId : productIds) {
- printer.println(productId);
- }
- } catch (Exception e) {
- throw new CmdLineActionException("Failed to perform lucene query '"
- + query + "' : " + e.getMessage(), e);
- }
+ ComplexQuery complexQuery = new ComplexQuery();
+
complexQuery.setCriteria(Lists.newArrayList(generateCASQuery(parseQuery(query))));
+ complexQuery.setReducedProductTypeNames(reducedProductTypes);
+ complexQuery.setReducedMetadata(reducedMetadataKeys);
+ return complexQuery;
}
public void setQuery(String query) {
this.query = query;
}
+ public void setReducedProductTypes(List<String> reducedProductTypes) {
+ this.reducedProductTypes = reducedProductTypes;
+ }
+
+ public void setReducedMetadataKeys(List<String> reducedMetadataKeys) {
+ this.reducedMetadataKeys = reducedMetadataKeys;
+ }
+
private Query parseQuery(String query) throws ParseException {
// note that "__FREE__" is a control work for free text searching
return (Query) new QueryParser(FREE_TEXT_BLOCK, new CASAnalyzer())
.parse(query);
}
- private List<String> query(XmlRpcFileManagerClient client,
- org.apache.oodt.cas.filemgr.structs.Query fmQuery,
- List<ProductType> productTypes) throws Exception {
- List<String> productIds = Lists.newArrayList();
- for (ProductType type : productTypes) {
- List<Product> products = client.query(fmQuery, type);
- if (products == null) {
- throw new Exception(
- "FileManager returned null products for query '" + query
- + "' and product type '" + type.getName() + "'");
- }
- for (Product product : products) {
- productIds.add(product.getProductId());
- }
- }
- return productIds;
- }
-
private QueryCriteria generateCASQuery(Query luceneQuery)
throws Exception {
if (luceneQuery instanceof TermQuery) {
Modified:
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/SqlQueryCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/SqlQueryCliAction.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/SqlQueryCliAction.java
(original)
+++
oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/cli/action/SqlQueryCliAction.java
Thu Dec 8 02:12:51 2011
@@ -16,19 +16,11 @@
*/
package org.apache.oodt.cas.filemgr.cli.action;
-//JDK imports
-import java.util.List;
-
//Apache imports
import org.apache.commons.lang.Validate;
//OODT imports
-import org.apache.oodt.cas.cli.exception.CmdLineActionException;
import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
-import org.apache.oodt.cas.filemgr.structs.query.QueryFilter;
-import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
-import org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter;
-import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
import org.apache.oodt.cas.filemgr.util.SqlParser;
/**
@@ -37,124 +29,22 @@ import org.apache.oodt.cas.filemgr.util.
*
* @author bfoster (Brian Foster)
*/
-public class SqlQueryCliAction extends FileManagerCliAction {
+public class SqlQueryCliAction extends AbstractQueryCliAction {
private String query;
- private String sortBy;
- private String outputFormat;
- private String delimiter;
-
- private List<String> reducedProductTypes;
- private List<String> reducedMetadataKeys;
-
- private FilterAlgor filterAlgor;
- private String startDateTimeMetKey;
- private String endDateTimeMetKey;
- private String priorityMetKey;
- private VersionConverter versionConverter;
public SqlQueryCliAction() {
- delimiter = "\n";
+ super();
}
@Override
- public void execute(ActionMessagePrinter printer)
- throws CmdLineActionException {
- try {
- Validate.notNull(query, "Must specify query");
-
- ComplexQuery complexQuery = SqlParser.parseSqlQuery(query);
- complexQuery.setSortByMetKey(sortBy);
- complexQuery.setToStringResultFormat(outputFormat);
- complexQuery.setReducedProductTypeNames(reducedProductTypes);
- complexQuery.setReducedMetadata(reducedMetadataKeys);
- 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);
- }
- printer.println(returnString.substring(0, returnString.length()
- - delimiter.length()));
- } catch (Exception e) {
- throw new CmdLineActionException("Failed to perform sql query for"
- + " query '"
- + query
- + "', sortBy '"
- + sortBy
- + "', "
- + "outputFormat '"
- + outputFormat
- + "', and delimiter '"
- + delimiter
- + "', filterAlgor '"
- + (filterAlgor != null ? filterAlgor.getClass()
- .getCanonicalName() : null)
- + "', startDateTimeMetKey '"
- + startDateTimeMetKey
- + "', endDateTimeMetKey '"
- + endDateTimeMetKey
- + "', priorityMetKey '"
- + priorityMetKey
- + "', "
- + (versionConverter != null ? versionConverter.getClass()
- .getCanonicalName() : null) + "' : " + e.getMessage(), e);
- }
+ public ComplexQuery getQuery() throws Exception {
+ Validate.notNull(query, "Must specify query");
+
+ return SqlParser.parseSqlQuery(query);
}
public void setQuery(String query) {
this.query = query;
}
-
- public void setSortBy(String sortBy) {
- this.sortBy = sortBy;
- }
-
- public void setOutputFormat(String outputFormat) {
- this.outputFormat = outputFormat;
- }
-
- public void setDelimiter(String delimiter) {
- this.delimiter = delimiter;
- }
-
- public void setReducedProductTypes(List<String> reducedProductTypes) {
- this.reducedProductTypes = reducedProductTypes;
- }
-
- public void setReducedMetadataKeys(List<String> reducedMetadataKeys) {
- this.reducedMetadataKeys = reducedMetadataKeys;
- }
-
- public void setStartDateTimeMetKey(String startDateTimeMetKey) {
- this.startDateTimeMetKey = startDateTimeMetKey;
- }
-
- public void setEndDateTimeMetKey(String endDateTimeMetKey) {
- this.endDateTimeMetKey = endDateTimeMetKey;
- }
-
- public void setPriorityMetKey(String priorityMetKey) {
- this.priorityMetKey = priorityMetKey;
- }
-
- public void setConverter(VersionConverter versionConverter) {
- this.versionConverter = versionConverter;
- }
-
- public void setFilterAlgor(FilterAlgor filterAlgor) {
- this.filterAlgor = filterAlgor;
- }
}
Modified: oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml (original)
+++ oodt/trunk/filemgr/src/main/resources/cmd-line-options.xml Thu Dec 8
02:12:51 2011
@@ -589,175 +589,7 @@
</property>
</bean>
- <bean id="sortBy"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
- <property name="shortOption" value="sb" />
- <property name="longOption" value="sortBy" />
- <property name="description" value="Metadata field to sort query results
by" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="metadata field" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="OPTIONAL" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
- <bean id="outputFormat"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
- <property name="shortOption" value="of" />
- <property name="longOption" value="outputFormat" />
- <property name="description" value="Output format string (i.e. Filename =
$Filename)" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="output-format-string" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="OPTIONAL" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="delimiter"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
- <property name="shortOption" value="dlmtr" />
- <property name="longOption" value="delimiter" />
- <property name="description" value="String to use the separate query
results" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="delimiter-string" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="OPTIONAL" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="filter" class="org.apache.oodt.cas.cli.option.GroupCmdLineOption">
- <property name="shortOption" value="f" />
- <property name="longOption" value="filter" />
- <property name="description" value="Query filter" />
- <property name="hasArgs" value="false" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="OPTIONAL" />
- </list>
- </property>
- <property name="subOptions">
- <list>
- <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
- p:option-ref="algor" p:required="true" />
- <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
- p:option-ref="converter" p:required="false" />
- <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
- p:option-ref="startDateTimeMetKey" p:required="true" />
- <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
- p:option-ref="endDateTimeMetKey" p:required="true" />
- <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
- p:option-ref="priorityMetKey" p:required="true" />
- </list>
- </property>
- </bean>
-
- <bean id="algor" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
- p:isSubOption="true">
- <property name="shortOption" value="algor" />
- <property name="longOption" value="algor" />
- <property name="description" value="FilterAlgor class" />
- <property name="type"
value="org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="classpath" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="REQUIRED" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="converter"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
- p:isSubOption="true">
- <property name="shortOption" value="conv" />
- <property name="longOption" value="converter" />
- <property name="description" value="VersionConverter class" />
- <property name="type"
value="org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="classpath" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="OPTIONAL" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="startDateTimeMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
- p:isSubOption="true">
- <property name="shortOption" value="sdtMetKey" />
- <property name="longOption" value="startDateTimeMetKey" />
- <property name="description" value="Start date time metadata key" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="metadata-key" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="REQUIRED" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="endDateTimeMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
- p:isSubOption="true">
- <property name="shortOption" value="edtMetKey" />
- <property name="longOption" value="endDateTimeMetKey" />
- <property name="description" value="End date time metadata key" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="metadata-key" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="REQUIRED" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
-
- <bean id="priorityMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
- p:isSubOption="true">
- <property name="shortOption" value="prMetKey" />
- <property name="longOption" value="priorityMetKey" />
- <property name="description" value="Priority metadata key" />
- <property name="hasArgs" value="true" />
- <property name="argsDescription" value="metadata-key" />
- <property name="requirementRules">
- <list>
- <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
- p:actionName="SqlQuery" p:relation="REQUIRED" />
- </list>
- </property>
- <property name="handler">
- <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
- </property>
- </bean>
<!-- GetProductById Options -->
<bean id="getProductById"
class="org.apache.oodt.cas.cli.option.ActionCmdLineOption"
@@ -897,6 +729,42 @@
</property>
</bean>
+ <bean id="reducedProductTypes"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+ <property name="shortOption" value="pts" />
+ <property name="longOption" value="reducedProductTypes" />
+ <property name="description" value="Limit query ProductTypes queried
against" />
+ <property name="type" value="java.util.List" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="list-of-product-types" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="reducedMetadataKeys"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+ <property name="shortOption" value="metKeys" />
+ <property name="longOption" value="reducedMetadataKeys" />
+ <property name="description" value="Limit Elements returned by query" />
+ <property name="type" value="java.util.List" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="list-of-elements" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
<!-- Options used for multiple Actions -->
<bean id="productId"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
<property name="shortOption" value="pid" />
@@ -1013,4 +881,192 @@
<bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
</property>
</bean>
+
+ <bean id="sortBy"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+ <property name="shortOption" value="sb" />
+ <property name="longOption" value="sortBy" />
+ <property name="description" value="Metadata field to sort query results
by" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="metadata field" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="outputFormat"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+ <property name="shortOption" value="of" />
+ <property name="longOption" value="outputFormat" />
+ <property name="description" value="Output format string (i.e. Filename =
$Filename)" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="output-format-string" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="delimiter"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+ <property name="shortOption" value="dlmtr" />
+ <property name="longOption" value="delimiter" />
+ <property name="description" value="String to use the separate query
results" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="delimiter-string" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="filter" class="org.apache.oodt.cas.cli.option.GroupCmdLineOption">
+ <property name="shortOption" value="f" />
+ <property name="longOption" value="filter" />
+ <property name="description" value="Query filter" />
+ <property name="hasArgs" value="false" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="subOptions">
+ <list>
+ <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+ p:option-ref="algor" p:required="true" />
+ <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+ p:option-ref="converter" p:required="false" />
+ <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+ p:option-ref="startDateTimeMetKey" p:required="true" />
+ <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+ p:option-ref="endDateTimeMetKey" p:required="true" />
+ <bean class="org.apache.oodt.cas.cli.option.GroupSubOption"
+ p:option-ref="priorityMetKey" p:required="true" />
+ </list>
+ </property>
+ </bean>
+
+ <bean id="algor" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
+ p:isSubOption="true">
+ <property name="shortOption" value="algor" />
+ <property name="longOption" value="algor" />
+ <property name="description" value="FilterAlgor class" />
+ <property name="type"
value="org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="classpath" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="converter"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
+ p:isSubOption="true">
+ <property name="shortOption" value="conv" />
+ <property name="longOption" value="converter" />
+ <property name="description" value="VersionConverter class" />
+ <property name="type"
value="org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="classpath" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="startDateTimeMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
+ p:isSubOption="true">
+ <property name="shortOption" value="sdtMetKey" />
+ <property name="longOption" value="startDateTimeMetKey" />
+ <property name="description" value="Start date time metadata key" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="metadata-key" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="endDateTimeMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
+ p:isSubOption="true">
+ <property name="shortOption" value="edtMetKey" />
+ <property name="longOption" value="endDateTimeMetKey" />
+ <property name="description" value="End date time metadata key" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="metadata-key" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
+
+ <bean id="priorityMetKey"
class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption"
+ p:isSubOption="true">
+ <property name="shortOption" value="prMetKey" />
+ <property name="longOption" value="priorityMetKey" />
+ <property name="description" value="Priority metadata key" />
+ <property name="hasArgs" value="true" />
+ <property name="argsDescription" value="metadata-key" />
+ <property name="requirementRules">
+ <list>
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="SqlQuery" p:relation="OPTIONAL" />
+ <bean
class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+ p:actionName="LuceneQuery" p:relation="OPTIONAL" />
+ </list>
+ </property>
+ <property name="handler">
+ <bean
class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler" />
+ </property>
+ </bean>
</beans>
Modified:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
(original)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/TestFileManagerCli.java
Thu Dec 8 02:12:51 2011
@@ -37,10 +37,14 @@ import org.apache.oodt.cas.filemgr.struc
import org.apache.oodt.cas.filemgr.structs.Reference;
import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
import org.apache.oodt.cas.filemgr.system.MockXmlRpcFileManagerClient;
import
org.apache.oodt.cas.filemgr.system.MockXmlRpcFileManagerClient.MethodCallDetails;
import org.apache.oodt.cas.metadata.Metadata;
+//Google imports
+import com.google.common.collect.Lists;
+
/**
* Tests File Manager Clients Command-line interface.
*
@@ -320,11 +324,34 @@ public class TestFileManagerCli extends
.run(("--url http://localhost:9000 --operation --luceneQuery"
+ " --query " + query).split(" "));
MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
- assertEquals("query", methodCallDetails.getMethodName());
+ assertEquals("complexQuery", methodCallDetails.getMethodName());
assertEquals("ProductId", ((TermQueryCriteria) ((Query) methodCallDetails
.getArgs().get(0)).getCriteria().get(0)).getElementName());
assertEquals("TestProductId",
((TermQueryCriteria) ((Query) methodCallDetails.getArgs().get(0))
.getCriteria().get(0)).getValue());
+
+ String reducedMetadataKeys = "ProductId ProductType";
+ String outputFormat = "$ProductId";
+ String reducedProductTypes = "TestProductType";
+ String sortBy = "ProductId";
+ String delimiter = ",";
+ cmdLineUtility
+ .run(("--url http://localhost:9000 --operation --luceneQuery"
+ + " --query " + query + " --reducedMetadataKeys " +
reducedMetadataKeys
+ + " --outputFormat " + outputFormat
+ + " --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());
}
}
Modified:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
(original)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
Thu Dec 8 02:12:51 2011
@@ -27,12 +27,13 @@ import org.apache.oodt.cas.cli.action.Cm
import org.apache.oodt.cas.cli.exception.CmdLineActionException;
import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.filemgr.structs.ProductType;
import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
-import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+import org.apache.oodt.cas.metadata.Metadata;
//Google imports
import com.google.common.collect.Lists;
@@ -47,7 +48,9 @@ import junit.framework.TestCase;
*/
public class TestLuceneQueryCliAction extends TestCase {
- private Query clientSetQuery;
+ private static final String TEST_FILENAME = "data.dat";
+
+ private ComplexQuery clientSetQuery;
public void testValidation() {
ActionMessagePrinter printer = new ActionMessagePrinter();
@@ -196,19 +199,15 @@ public class TestLuceneQueryCliAction ex
return new XmlRpcFileManagerClient(new URL("http://localhost:9000"),
false) {
@Override
- public List<Product> query(Query query, ProductType pt) {
- clientSetQuery = query;
+ public List<QueryResult> complexQuery(ComplexQuery complexQuery) {
+ clientSetQuery = complexQuery;
Product p = new Product();
p.setProductId("TestProductId");
- p.setProductType(pt);
- return Lists.newArrayList(p);
- }
-
- @Override
- public List<ProductType> getProductTypes() {
- ProductType pt = new ProductType();
- pt.setName("TestProductType");
- return Lists.newArrayList(pt);
+ Metadata m = new Metadata();
+ m.addMetadata("Filename", TEST_FILENAME);
+ QueryResult qr = new QueryResult(p, m);
+ qr.setToStringFormat(complexQuery.getToStringResultFormat());
+ return Lists.newArrayList(qr);
}
};
}
Modified:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
(original)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
Thu Dec 8 02:12:51 2011
@@ -52,8 +52,6 @@ public class TestSqlQueryCliAction exten
private static final String SORT_BY = "Filename";
private static final String OUTPUT_FORMAT = "Filename = $Filename";
private static final String DELIMITER = ",";
- private static final List<String> REDUCED_PRODUCT_TYPES =
Lists.newArrayList("TestProductType");
- private static final List<String> REDUCED_METADATA_KEYS =
Lists.newArrayList("Filename");
private static final FilterAlgor FILTER_ALGOR = new MockFilterAlgor();
private static final String START_DATE_TIME_MET_KEY = "StartDateTime";
private static final String END_DATE_TIME_MET_KEY = "EndDateTime";
@@ -84,7 +82,7 @@ public class TestSqlQueryCliAction exten
cliAction.setEndDateTimeMetKey(END_DATE_TIME_MET_KEY);
cliAction.setPriorityMetKey(PRIORITY_DATE_TIME_MET_KEY);
cliAction.execute(printer); // Should not throw exception.
- cliAction.setConverter(VERSION_CONV);
+ cliAction.setVersionConverter(VERSION_CONV);
cliAction.execute(printer); // Should not throw exception.
}
@@ -95,21 +93,19 @@ public class TestSqlQueryCliAction exten
cliAction.setSortBy(SORT_BY);
cliAction.setOutputFormat(OUTPUT_FORMAT);
cliAction.setDelimiter(DELIMITER);
- cliAction.setReducedProductTypes(REDUCED_PRODUCT_TYPES);
- cliAction.setReducedMetadataKeys(REDUCED_METADATA_KEYS);
cliAction.setFilterAlgor(FILTER_ALGOR);
cliAction.setStartDateTimeMetKey(START_DATE_TIME_MET_KEY);
cliAction.setEndDateTimeMetKey(END_DATE_TIME_MET_KEY);
cliAction.setPriorityMetKey(PRIORITY_DATE_TIME_MET_KEY);
- cliAction.setConverter(VERSION_CONV);
+ cliAction.setVersionConverter(VERSION_CONV);
cliAction.execute(printer);
assertEquals(2, printer.getPrintedMessages().size());
assertEquals("Filename = data.dat", printer.getPrintedMessages().get(0));
assertEquals("\n", printer.getPrintedMessages().get(1));
assertEquals(SORT_BY, clientSetComplexQuery.getSortByMetKey());
assertEquals(OUTPUT_FORMAT,
clientSetComplexQuery.getToStringResultFormat());
- assertEquals(REDUCED_PRODUCT_TYPES,
clientSetComplexQuery.getReducedProductTypeNames());
- assertEquals(REDUCED_METADATA_KEYS,
clientSetComplexQuery.getReducedMetadata());
+ assertNull(clientSetComplexQuery.getReducedProductTypeNames());
+ assertNull(clientSetComplexQuery.getReducedMetadata());
assertEquals(FILTER_ALGOR,
clientSetComplexQuery.getQueryFilter().getFilterAlgor());
assertEquals(START_DATE_TIME_MET_KEY,
clientSetComplexQuery.getQueryFilter().getStartDateTimeMetKey());
assertEquals(END_DATE_TIME_MET_KEY,
clientSetComplexQuery.getQueryFilter().getEndDateTimeMetKey());
Modified:
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java?rev=1211740&r1=1211739&r2=1211740&view=diff
==============================================================================
---
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
(original)
+++
oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
Thu Dec 8 02:12:51 2011
@@ -30,6 +30,8 @@ import org.apache.oodt.cas.filemgr.struc
import org.apache.oodt.cas.filemgr.structs.Query;
import org.apache.oodt.cas.filemgr.structs.Reference;
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
import org.apache.oodt.cas.metadata.Metadata;
//Google imports
@@ -247,9 +249,9 @@ public class MockXmlRpcFileManagerClient
}
@Override
- public List<Product> query(Query query, ProductType type) {
- lastMethodCallDetails = new MethodCallDetails("query",
- Lists.newArrayList((Object) query, type));
+ public List<QueryResult> complexQuery(ComplexQuery query) {
+ lastMethodCallDetails = new MethodCallDetails("complexQuery",
+ Lists.newArrayList((Object) query));
return Lists.newArrayList();
}