[Yanel-commits] rev 57431 - public/yanel/trunk/src/resources/workflow-dashboard/src/java/org/wyona/yanel/impl/resources/dashboard
michi at wyona.com
michi at wyona.com
Tue Mar 22 16:14:46 CET 2011
Author: michi
Date: 2011-03-22 16:14:46 +0100 (Tue, 22 Mar 2011)
New Revision: 57431
Modified:
public/yanel/trunk/src/resources/workflow-dashboard/src/java/org/wyona/yanel/impl/resources/dashboard/WorkflowDashboardResource.java
Log:
display mime types and workflow states
Modified: public/yanel/trunk/src/resources/workflow-dashboard/src/java/org/wyona/yanel/impl/resources/dashboard/WorkflowDashboardResource.java
===================================================================
--- public/yanel/trunk/src/resources/workflow-dashboard/src/java/org/wyona/yanel/impl/resources/dashboard/WorkflowDashboardResource.java 2011-03-22 14:50:03 UTC (rev 57430)
+++ public/yanel/trunk/src/resources/workflow-dashboard/src/java/org/wyona/yanel/impl/resources/dashboard/WorkflowDashboardResource.java 2011-03-22 15:14:46 UTC (rev 57431)
@@ -1,11 +1,12 @@
/*
* Copyright 2011 Wyona
*/
-
package org.wyona.yanel.impl.resources.dashboard;
import org.wyona.yanel.impl.resources.BasicXMLResource;
+import org.wyona.yanel.core.workflow.Workflow;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -26,17 +27,74 @@
log.debug("requested viewId: " + viewId);
}
- // TODO: Get list of workflow states from workflow definition (referenced by resource configuration)
String workflowState = "draft";
if (getEnvironment().getRequest().getParameter("workflow-state") != null) {
workflowState = getEnvironment().getRequest().getParameter("workflow-state");
}
- org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().searchProperty("workflow-state", workflowState, "/");
+ String queryText = "workflow-state:" + workflowState;
+ if (getEnvironment().getRequest().getParameter("mime-type") != null) {
+ queryText = queryText + " AND " + "yarep_mimeType:" + getEnvironment().getRequest().getParameter("mime-type");
+ }
+/*
+ if (org.wyona.commons.clazz.ClazzUtil.implementsInterface(getRealm().getRepository(), "org.wyona.yarep.core.attributes.LuceneSearchableV1")) {
+ log.warn("DEBUG: Repo is lucene searchable ...");
+ org.apache.lucene.search.Searcher searcher = ((org.wyona.yarep.core.attributes.LuceneSearchableV1)getRealm().getRepository()).getLuceneSearcher();
+
+ String defaultField = "_FULLTEXT";
+ org.apache.lucene.queryParser.QueryParser queryParser = new org.apache.lucene.queryParser.QueryParser(defaultField, new org.apache.lucene.analysis.standard.StandardAnalyzer());
+ log.warn("DEBUG: Default field: " + defaultField);
+ org.apache.lucene.search.Query query = queryParser.parse(queryText);
+
+ // How to use StandardAnalyzer with TermQuery? http://stackoverflow.com/questions/1390088/how-do-i-use-standardanalyzer-with-termquery, http://today.java.net/pub/a/today/2003/07/30/LuceneIntro.html
+ // What about MultiFieldQueryParser?
+ //org.apache.lucene.search.Query queryF1 = new org.apache.lucene.search.TermQuery(new org.apache.lucene.index.Term("_FULLTEXT", "sugus"));
+//org.apache.lucene.search.Query queryF1 = new org.apache.lucene.search.TermQuery(new org.apache.lucene.index.Term("workflow-state", workflowState));
+ //org.apache.lucene.search.BooleanQuery query = new org.apache.lucene.search.BooleanQuery();
+ //query.add(queryF1, org.apache.lucene.search.BooleanClause.Occur.MUST);
+
+ //org.apache.lucene.search.Query query = new org.apache.lucene.queryParser.QueryParser("_FULLTEXT", (org.apache.lucene.analysis.Analyzer) Class.forName("org.apache.lucene.analysis.standard.StandardAnalyzer").newInstance()).parse("Sugus");
+
+ log.warn("DEBUG: Query: " + query);
+ org.apache.lucene.search.Hits hits = searcher.search(query);
+ for (int i = 0; i < hits.length(); i++) {
+ log.warn("DEBUG: Hit _PATH: " + hits.doc(i).getField("_PATH").stringValue());
+ }
+ }
+*/
+
+ //org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().searchProperty("workflow-state", workflowState, "/meetings");
+ //org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().searchProperty("workflow-state", workflowState, "/");
+ org.wyona.yarep.core.Node[] nodes = getRealm().getRepository().getSearcher().searchProperty("workflow-state", queryText, "/");
+
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
- sb.append("<workflow-dashboard>");
- if (nodes.length > 0) {
+ sb.append("<workflow-dashboard query=\"" + queryText + "\">");
+
+ String[] mimeTypes = getMimeTypes();
+ if (mimeTypes != null) {
+ sb.append("<mime-types>");
+ for(int i = 0; i < mimeTypes.length; i++) {
+ sb.append("<mime-type>" + mimeTypes[i] + "</mime-type>");
+ }
+ sb.append("</mime-types>");
+ } else {
+ sb.append("<no-mime-types/>");
+ }
+
+ Workflow workflow = getWorkflow();
+ if (workflow != null) {
+ sb.append("<workflow-states>");
+ String[] states = workflow.getStates();
+ for(int i = 0; i < states.length; i++) {
+ sb.append("<state>" + states[i] + "</state>");
+ }
+ sb.append("</workflow-states>");
+ } else {
+ sb.append("<no-workflow-states/>");
+ }
+
+ if (nodes != null && nodes.length > 0) {
for (int i = 0; i < nodes.length; i++) {
sb.append("<node path=\"" + nodes[i].getPath() + "\">");
if (nodes[i] instanceof org.wyona.yarep.core.Revision) { // INFO: This only makes sense if revisions are being indexed actually
@@ -52,4 +110,30 @@
sb.append("</workflow-dashboard>");
return new ByteArrayInputStream(sb.toString().getBytes());
}
+
+ /**
+ * Get one particular workflow
+ */
+ private Workflow getWorkflow() throws Exception {
+ String workflowPath = getResourceConfigProperty("one-particular-workflow-path");
+ if (workflowPath != null && getRealm().getRepository().existsNode(workflowPath)) {
+ return new org.wyona.yanel.core.workflow.WorkflowBuilder().buildWorkflow(getRealm().getRepository().getNode(workflowPath).getInputStream());
+ }
+ return null;
+ }
+
+ /**
+ * Get list of mime types
+ */
+ private String[] getMimeTypes() throws Exception {
+ String mimeTypesCSV = getResourceConfigProperty("mime-types");
+ if (mimeTypesCSV != null) {
+ String[] mimeTypes = mimeTypesCSV.split(",");
+ for (int i = 0; i < mimeTypes.length; i++) {
+ mimeTypes[i] = mimeTypes[i].trim();
+ }
+ return mimeTypes;
+ }
+ return null;
+ }
}
More information about the Yanel-commits
mailing list