Author: jeff.yuchang
Date: 2011-03-17 04:23:42 -0400 (Thu, 17 Mar 2011)
New Revision: 1321
Added:
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java
trunk/console/integration/src/main/resources/META-INF/services/org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin
Modified:
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceEndAdapter.java
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceStartAdapter.java
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceTerminationAdapter.java
trunk/console/integration/pom.xml
Log:
*RIFTSAW-259, added BPAFService and ProcessHistoryPluginImpl.
Modified:
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceEndAdapter.java
===================================================================
---
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceEndAdapter.java 2011-03-16
14:08:17 UTC (rev 1320)
+++
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceEndAdapter.java 2011-03-17
08:23:42 UTC (rev 1321)
@@ -18,6 +18,7 @@
import org.apache.ode.bpel.evt.ProcessCompletionEvent;
import org.jboss.bpm.monitor.model.bpaf.Event;
import org.jboss.bpm.monitor.model.bpaf.State;
+import org.jboss.bpm.monitor.model.bpaf.Tuple;
/**
* @author: Heiko Braun <hbraun(a)redhat.com>
@@ -37,6 +38,12 @@
InstanceStartAdapter.mapDefault(target, source);
+ Tuple endTime = new Tuple();
+ endTime.setName("process-end-time");
+ endTime.setValue(String.valueOf(source.getTimestamp().getTime()));
+
+ target.addData(endTime);
+
return target;
}
}
Modified:
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceStartAdapter.java
===================================================================
---
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceStartAdapter.java 2011-03-16
14:08:17 UTC (rev 1320)
+++
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceStartAdapter.java 2011-03-17
08:23:42 UTC (rev 1321)
@@ -19,6 +19,7 @@
import org.apache.ode.bpel.evt.ProcessInstanceStartedEvent;
import org.jboss.bpm.monitor.model.bpaf.Event;
import org.jboss.bpm.monitor.model.bpaf.State;
+import org.jboss.bpm.monitor.model.bpaf.Tuple;
/**
* @author: Heiko Braun <hbraun(a)redhat.com>
@@ -26,14 +27,22 @@
*/
public final class InstanceStartAdapter
implements EventAdapter.EventDetailMapping<ProcessInstanceStartedEvent> {
-
+
+
+
public Event adoptDetails(Event target, ProcessInstanceStartedEvent source) {
Event.EventDetails details = target.getEventDetails();
details.setCurrentState(State.Open_Running);
mapDefault(target, source);
-
+
+ Tuple startTime = new Tuple();
+ startTime.setName("process-start-time");
+ startTime.setValue(String.valueOf(source.getTimestamp().getTime()));
+
+ target.addData(startTime);
+
return target;
}
Modified:
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceTerminationAdapter.java
===================================================================
---
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceTerminationAdapter.java 2011-03-16
14:08:17 UTC (rev 1320)
+++
trunk/console/bpaf/src/main/java/org/jboss/soa/bpel/console/bpaf/InstanceTerminationAdapter.java 2011-03-17
08:23:42 UTC (rev 1321)
@@ -18,6 +18,7 @@
import org.apache.ode.bpel.evt.ProcessTerminationEvent;
import org.jboss.bpm.monitor.model.bpaf.Event;
import org.jboss.bpm.monitor.model.bpaf.State;
+import org.jboss.bpm.monitor.model.bpaf.Tuple;
/**
* @author: Heiko Braun <hbraun(a)redhat.com>
@@ -30,7 +31,13 @@
details.setCurrentState(State.Closed_Cancelled_Terminated);
InstanceStartAdapter.mapDefault(target, source);
-
+
+ Tuple endTime = new Tuple();
+ endTime.setName("process-end-time");
+ endTime.setValue(String.valueOf(source.getTimestamp().getTime()));
+
+ target.addData(endTime);
+
return target;
}
}
Modified: trunk/console/integration/pom.xml
===================================================================
--- trunk/console/integration/pom.xml 2011-03-16 14:08:17 UTC (rev 1320)
+++ trunk/console/integration/pom.xml 2011-03-17 08:23:42 UTC (rev 1321)
@@ -152,6 +152,12 @@
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.bpm</groupId>
+ <artifactId>activity-monitor-model</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
Added:
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java
===================================================================
---
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java
(rev 0)
+++
trunk/console/integration/src/main/java/org/jboss/soa/bpel/console/ProcessHistoryPluginImpl.java 2011-03-17
08:23:42 UTC (rev 1321)
@@ -0,0 +1,120 @@
+/**
+ *
+ */
+package org.jboss.soa.bpel.console;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.bpm.console.client.model.HistoryProcessInstanceRef;
+import org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin;
+import org.jboss.bpm.monitor.model.BPAFDataSource;
+import org.jboss.bpm.monitor.model.DefaultBPAFDataSource;
+import org.jboss.bpm.monitor.model.bpaf.Event;
+import org.jboss.bpm.monitor.model.bpaf.State;
+import org.jboss.bpm.monitor.model.bpaf.Tuple;
+import org.jboss.bpm.monitor.model.metric.Timespan;
+
+/**
+ * @author Jeff Yu
+ * @date: Mar 17, 2011
+ */
+public class ProcessHistoryPluginImpl implements ProcessHistoryPlugin {
+
+ private BPAFDataSource ds = null;
+
+ public ProcessHistoryPluginImpl() {
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ EntityManagerFactory emf =
(EntityManagerFactory)ctx.lookup("bpel/EntityManagerFactory");
+ if (null == emf) {
+ throw new IllegalStateException("EntityManagerFactory is null");
+ }
+ ds = new DefaultBPAFDataSource(emf);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Failed to initialize BPAF datasource");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin#getHistoryProcessInstances(java.lang.String,
java.lang.String, long, long, java.lang.String)
+ */
+ public List<HistoryProcessInstanceRef> getHistoryProcessInstances(
+ String definitionkey, String status, long starttime, long endtime,
+ String correlationkey) {
+
+ List<Event> events = ds.getInstanceEvents(definitionkey, new Timespan(starttime,
endtime, "Custom"), getStatus(status));
+ List<String> instanceIds = null;
+ if (correlationkey != null ) {
+ instanceIds = ds.getProcessInstances(definitionkey, "correlation-key",
correlationkey);
+ }
+
+ Map<String, HistoryProcessInstanceRef> hisInstances = new HashMap<String,
HistoryProcessInstanceRef>();
+
+ for(Event e : events)
+ {
+ if(instanceIds == null || instanceIds.contains(e.getProcessInstanceID())) {
+ if (e.getEventDetails().getCurrentState().equals(getStatus(status))) {
+ HistoryProcessInstanceRef hi = createHistoryInstance(status, hisInstances, e);
+ hisInstances.put(e.getProcessInstanceID(), hi);
+ }
+ }
+ }
+
+ List<HistoryProcessInstanceRef> ref = new
ArrayList<HistoryProcessInstanceRef>();
+ for (HistoryProcessInstanceRef hp : hisInstances.values()) {
+ ref.add(hp);
+ }
+
+ return ref;
+ }
+
+ private State getStatus(String status) {
+ if ("COMPLETED".equalsIgnoreCase(status)) {
+ return State.Closed_Completed;
+ }
+ if ("FAILED".equalsIgnoreCase(status)) {
+ return State.Closed_Completed_Failed;
+ }
+ if ("TERMINATED".equalsIgnoreCase(status)) {
+ return State.Closed_Cancelled_Terminated;
+ }
+ return null;
+ }
+
+
+
+ private HistoryProcessInstanceRef createHistoryInstance(String status, Map<String,
HistoryProcessInstanceRef> hisInstances, Event e) {
+ HistoryProcessInstanceRef hi = null;
+ if (!hisInstances.containsKey(e.getProcessInstanceID())) {
+ hi = new HistoryProcessInstanceRef();
+ } else {
+ hi = hisInstances.get(e.getProcessInstanceID());
+ }
+ hi.setProcessDefinitionId(e.getProcessInstanceID());
+ hi.setState(status);
+ for (Tuple tuple : e.getDataElement()) {
+ if ("correlation-key".equals(tuple.getName())) {
+ hi.setKey(tuple.getValue());
+ }
+ if ("process-start-time".equals(tuple.getName())) {
+ hi.setStartTime(new Date(new Long(tuple.getValue())));
+ }
+ if ("process-end-time".equals(tuple.getName())) {
+ hi.setEndTime(new Date(new Long(tuple.getValue())));
+ }
+ }
+ return hi;
+ }
+
+}
Added:
trunk/console/integration/src/main/resources/META-INF/services/org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin
===================================================================
---
trunk/console/integration/src/main/resources/META-INF/services/org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin
(rev 0)
+++
trunk/console/integration/src/main/resources/META-INF/services/org.jboss.bpm.console.server.plugin.ProcessHistoryPlugin 2011-03-17
08:23:42 UTC (rev 1321)
@@ -0,0 +1 @@
+org.jboss.soa.bpel.console.ProcessHistoryPluginImpl
\ No newline at end of file