Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 JBoss Inc Licensed 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 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.
 import java.util.List;
 import java.util.Map;
 import  javax.persistence.EntityManagerFactory;
 import  javax.persistence.PersistenceUnit;
 import  org.jbpm.process.audit.AuditLogService;
 import  org.jbpm.process.audit.JPAAuditLogService;
 import  org.jbpm.process.audit.NodeInstanceLog;
 import  org.jbpm.process.audit.ProcessInstanceLog;
 import  org.kie.api.KieBase;
 import  org.kie.api.definition.process.Node;
 import  org.kie.api.definition.process.NodeContainer;
 import  org.kie.api.definition.process.Process;
 import  org.kie.api.definition.process.WorkflowProcess;
This code needs to be finished -- it was pulled from the old jbpm-gwt module and the bpm-console projec. The idea is to use this (and the underlying classes in the .jaxb package) to duplicate the image and image info functions that the old gwt-console had. /gwt-console-server/rs/process/definition/{id}/image /gwt-console-server/rs/process/instance/{id}/activeNodeInfo
 public class GraphViewerPluginImpl {
 	private KieBase kbase;
     //@PersistenceUnit(unitName = "org.jbpm.domain")
 	private EntityManagerFactory emf;
 	public List<ActiveNodeInfogetActiveNodeInfo(String instanceId) {
 	    AuditLogService auditLogService = new JPAAuditLogService();
 		ProcessInstanceLog processInstance = auditLogService.findProcessInstance(new Long(instanceId));
 		if (processInstance == null) {
 			throw new IllegalArgumentException("Could not find process instance " + instanceId);
 		Map<String, NodeInstanceLog> nodeInstances = new HashMap<String, NodeInstanceLog>();
 		for (NodeInstanceLog nodeInstanceauditLogService.findNodeInstances(new Long(instanceId))) {
 			if (nodeInstance.getType() == NodeInstanceLog.TYPE_ENTER) {
 				nodeInstances.put(nodeInstance.getNodeInstanceId(), nodeInstance);
 			} else {
 		if (!nodeInstances.isEmpty()) {
 			for (NodeInstanceLog nodeInstancenodeInstances.values()) {
 				boolean found = false;
 				DiagramInfo diagramInfo = getDiagramInfo(processInstance.getProcessId());
 				if (diagramInfo != null) {
     				for (DiagramNodeInfo nodeInfodiagramInfo.getNodeList()) {
     					if (nodeInfo.getName().equals("id=" + nodeInstance.getNodeId())) {
     						result.add(new ActiveNodeInfo(diagramInfo.getWidth(), diagramInfo.getHeight(), nodeInfo));
     						found = true;
 				} else {
 				    throw new IllegalArgumentException("Could not find info for diagram for process " + processInstance.getProcessId());
 				if (!found) {
 					throw new IllegalArgumentException("Could not find info for node "
 						+ nodeInstance.getNodeId() + " of process " + processInstance.getProcessId());
 			return result;
 		return null;
	public DiagramInfo getDiagramInfo(String processId) {
		Process process = .getProcess(processId);
		if (process == null) {
		    return null;
		DiagramInfo result = new DiagramInfo();
		// TODO: diagram width and height?
		if (process instanceof WorkflowProcess) {
			addNodesInfo(nodeList, ((WorkflowProcess) process).getNodes(), "id=");
		return result;
	private void addNodesInfo(List<DiagramNodeInfonodeInfos, Node[] nodesString prefix) {
		for (Node nodenodes) {
			nodeInfos.add(new DiagramNodeInfo(
				prefix + node.getId(),
			if (node instanceof NodeContainer) {
				addNodesInfo(nodeInfos, ((NodeContainer) node).getNodes(), prefix + node.getId() + ":");
	public byte[] getProcessImage(String processId) {
	    // TODO? 
	    return null;
	private static final int BUFFER_SIZE = 512;
	public static int transfer(InputStream inOutputStream outthrows IOException {
		int total = 0;
		byte[] buffer = new byte[];
		int bytesRead =;
		while (bytesRead != -1) {
			out.write(buffer, 0, bytesRead);
			total += bytesRead;
			bytesRead =;
		return total;
	public URL getDiagramURL(String id) {
	    // TODO
		URL result = GraphViewerPluginImpl.class.getResource("/" + id + ".png");
		if (result != null) {
			return result;
		return null;
			String processDefinitionIdList<Stringactivities) {
		// TODO Auto-generated method stub
		return new ArrayList<ActiveNodeInfo>();
New to GrepCode? Check out our FAQ X