You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/01/03 14:09:07 UTC
svn commit: r123962 - /lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
Author: andreas
Date: Mon Jan 3 05:09:05 2005
New Revision: 123962
URL: http://svn.apache.org/viewcvs?view=rev&rev=123962
Log:
added methods to trigger workflow
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java?view=diff&rev=123962&p1=lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java&r1=123961&p2=lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java&r2=123962
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/usecase/DocumentUsecase.java Mon Jan 3 05:09:05 2005
@@ -19,7 +19,11 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.workflow.WorkflowFactory;
+import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
+import org.apache.lenya.workflow.WorkflowException;
+import org.apache.lenya.workflow.WorkflowInstance;
/**
*
@@ -69,7 +73,8 @@
}
/**
- * Returns the document to be redirected to after the usecase has been completed.
+ * Returns the document to be redirected to after the usecase has been
+ * completed.
* @param success If the usecase was successfully completed.
* @return A document.
*/
@@ -84,8 +89,8 @@
}
/**
- * If {@link #setTargetDocument(Document)}was not called, the URL of the source document (
- * {@link #getSourceDocument()}) is returned.
+ * If {@link #setTargetDocument(Document)}was not called, the URL of the
+ * source document ({@link #getSourceDocument()}) is returned.
* @see org.apache.lenya.cms.usecase.Usecase#getTargetURL(boolean)
*/
public String getTargetURL(boolean success) {
@@ -109,4 +114,41 @@
throw new RuntimeException(e);
}
}
+
+ /**
+ * Triggers a workflow event on the source document by calling
+ * {@link #triggerWorkflow(String, Document)}.
+ * @param event the event.
+ */
+ protected void triggerWorkflow(String event) {
+ triggerWorkflow(event, getSourceDocument());
+ }
+
+ /**
+ * Triggers a workflow event on a document.
+ * @param event The event.
+ * @param document The document.
+ */
+ protected void triggerWorkflow(String event, Document document) {
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ try {
+ WorkflowInstance instance = factory.buildInstance(document);
+ Event[] events = instance.getExecutableEvents(getSituation());
+ Event executableEvent = null;
+ for (int i = 0; i < events.length; i++) {
+ if (events[i].getName().equals(event)) {
+ executableEvent = events[i];
+ }
+ }
+
+ if (executableEvent == null) {
+ throw new RuntimeException("The event [" + event
+ + "] is not executable on document [" + document + "]");
+ }
+ instance.invoke(getSituation(), executableEvent);
+ } catch (WorkflowException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org