Workflow checkpoint.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3399 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-07-25 20:56:42 +00:00
parent 62c0ecf132
commit d8deab68eb
54 changed files with 4718 additions and 3 deletions

View File

@@ -0,0 +1,64 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.List;
import javax.faces.context.FacesContext;
import org.jbpm.scheduler.impl.Scheduler;
public class AdminBean {
String deployUrl;
public void deployProcess() {
}
public void createSchema() {
}
public void dropSchema() {
}
public boolean isSchedulerRunning() {
return getScheduler().isRunning();
}
public List getSchedulerHistoryLogs() {
return getScheduler().getSchedulerHistoryLogs();
}
private Scheduler getScheduler() {
return (Scheduler) FacesContext.getCurrentInstance()
.getExternalContext()
.getApplicationMap()
.get("scheduler");
}
public String getDeployUrl() {
return deployUrl;
}
public void setDeployUrl(String deployUrl) {
this.deployUrl = deployUrl;
}
}

View File

@@ -0,0 +1,22 @@
package org.jbpm.webapp.bean;
import org.alfresco.service.cmr.security.AuthenticationService;
public class AlfrescoUserBean extends UserBean
{
AuthenticationService authService;
public void setAuthenticationService(AuthenticationService authService)
{
this.authService = authService;
}
@Override
public String getUserName()
{
return authService.getCurrentUserName();
}
}

View File

@@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import org.jbpm.context.def.VariableAccess;
public class FormParameter {
private String value = null;
private VariableAccess variableAccess = null;
public FormParameter(String value, VariableAccess variableAccess) {
this.value = value;
this.variableAccess = variableAccess;
}
public String getValue() {
return value;
}
public VariableAccess getVariableAccess() {
return variableAccess;
}
}

View File

@@ -0,0 +1,205 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.db.TaskMgmtSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.def.Transition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.def.Task;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class HomeBean {
UserBean userBean;
TaskBean taskBean;
JbpmConfiguration config;
DataModel taskInstances;
DataModel processDefs;
public HomeBean()
{
}
public void setJbpmConfiguration(JbpmConfiguration config)
{
this.config = config;
}
public List getTaskInstances()
{
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
try
{
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
List<TaskInstance> taskInstances = taskMgmtSession.findTaskInstances(userBean.getUserName());
for (TaskInstance taskInstance : taskInstances)
{
taskInstance.getName();
taskInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getProcessDefinition().getName();
}
return taskInstances;
}
finally
{
if (xjbpmContext == null) jbpmContext.close();
}
}
public DataModel getTaskInstancesModel()
{
if (taskInstances == null)
{
taskInstances = new ListDataModel(getTaskInstances());
}
return taskInstances;
}
public List getLatestProcessDefinitions()
{
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
try
{
GraphSession graphSession = jbpmContext.getGraphSession();
List<ProcessDefinition> procDefs = graphSession.findLatestProcessDefinitions();
for (ProcessDefinition procDef : procDefs)
{
procDef.getName();
Task startTask = procDef.getTaskMgmtDefinition().getStartTask();
if (startTask != null)
{
startTask.getName();
}
}
return procDefs;
}
finally
{
if (xjbpmContext == null) jbpmContext.close();
}
}
public DataModel getLatestProcessDefinitionsModel()
{
if (processDefs == null)
{
processDefs = new ListDataModel(getLatestProcessDefinitions());
}
return processDefs;
}
/**
* selects a task.
*/
public String selectTaskInstance()
{
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
try
{
// Get the task instance id from request parameter
TaskInstance selectedTask = (TaskInstance)taskInstances.getRowData();
long taskInstanceId = selectedTask.getId();
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(taskInstanceId);
taskBean.initialize(taskInstance);
return "task";
}
finally
{
taskInstances = null;
processDefs = null;
if (xjbpmContext == null ) jbpmContext.close();
}
}
/**
* prepares a task form for starting a new process instance.
*/
public String startProcessInstance()
{
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
try
{
jbpmContext.setActorId(AuthenticationUtil.getCurrentUserName());
// Get the task instance id from request parameter
ProcessDefinition selectedProc = (ProcessDefinition)processDefs.getRowData();
long processDefinitionId = selectedProc.getId();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
// create a new process instance to run
ProcessInstance processInstance = new ProcessInstance(processDefinition);
// create a new taskinstance for the start task
Task startTask = processInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getStartTask();
if (startTask != null)
{
TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
taskBean.initialize(taskInstance);
}
// Save the process instance along with the task instance
jbpmContext.save(processInstance);
// Fill the task backing bean with useful information
return (startTask == null) ? "home" : "task";
}
finally
{
if (xjbpmContext == null) jbpmContext.close();
taskInstances = null;
processDefs = null;
}
}
public UserBean getUserBean() {
return userBean;
}
public void setUserBean(UserBean userBean) {
this.userBean = userBean;
}
public TaskBean getTaskBean() {
return taskBean;
}
public void setTaskBean(TaskBean taskBean) {
this.taskBean = taskBean;
}
}

View File

@@ -0,0 +1,61 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class JsfHelper {
public static long getId(String parameterName) {
long value = -1;
String valueText = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(parameterName);
try {
Long id = new Long(valueText);
value = id.longValue();
} catch (NumberFormatException e) {
throw new RuntimeException("couldn't parse '"+parameterName+"'='"+valueText+"' as a long");
}
return value;
}
public static void addMessage(String msg) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg));
}
public static void setSessionAttribute(String key, Object value) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
}
public static Object getSessionAttribute(String key) {
return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key);
}
public static void removeSessionAttribute(String key) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(key);
}
public static String getParameter(String name) {
return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
}
// private static final Log log = LogFactory.getLog(JsfHelper.class);
}

View File

@@ -0,0 +1,228 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
/**
* Monitoring Bean Implementation.
*
* @author David Loiseau
*/
public class MonitoringBean {
long processInstanceId;
String message;
String variableName;
String variableValue;
String variableNameOperator;
String variableValueOperator;
ArrayList processInstances;
public String showProcessDefinitions() {
return "processDefinitions";
}
public List getProcessDefinitions() {
ArrayList processDefinitionsList = new ArrayList();
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
List processDefinitions = jbpmContext.getGraphSession().findAllProcessDefinitions();
if (processDefinitions.isEmpty() == false) {
ListIterator listProcessDefinitions = processDefinitions.listIterator();
while (listProcessDefinitions.hasNext() ) {
ProcessDefinition processDefinition = (ProcessDefinition)listProcessDefinitions.next();
int instancesCount = 0;
try {
Connection connection = jbpmContext.getConnection();
Statement statement = connection.createStatement();
String request = "SELECT COUNT(*) AS instancesCount "
+ "FROM jbpm_processinstance "
+ "WHERE processdefinition_='"
+ processDefinition.getId() + "'";
ResultSet resultSet = statement.executeQuery(request);
resultSet.next();
instancesCount = resultSet.getInt("instancesCount");
}
catch (Exception e) {}
processDefinitionsList.add(
new ProcessDefinitionBean(
processDefinition.getId(),
processDefinition.getName(),
processDefinition.getVersion(),
instancesCount
));
}
}
return(processDefinitionsList);
}
public String inspectInstance() {
try {
ProcessInstanceBean processInstanceBean = new ProcessInstanceBean(this.processInstanceId);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
this.message = "";
return "inspectInstance";
}
catch (Exception exception) {
this.message = "Error for process instance " + this.processInstanceId;
return "";
}
}
public String showSearchInstances() {
return("showSearchInstances");
}
public String searchInstances() {
long count = 0;
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
try {
Connection connection = jbpmContext.getConnection();
Statement statement = connection.createStatement();
statement.setMaxRows(100);
String request = "SELECT DISTINCT processinstance_, name_, stringvalue_ FROM jbpm_variableinstance "
+ "WHERE name_ "
+ this.variableNameOperator + " '"
+ variableName + "' AND stringvalue_ "
+ this.variableValueOperator + " '" + variableValue + "'";
ResultSet resultSet = statement.executeQuery(request);
processInstances = new ArrayList();
while (resultSet.next()) {
processInstances.add(new ProcessInstanceBean(
resultSet.getLong("processinstance_"),
resultSet.getString("name_"),
resultSet.getString("stringvalue_")));
count++;
}
statement.close();
}
catch (Exception e) {
this.message = "Search error " + e.getMessage();
}
if (count == 1) {
ProcessInstanceBean processInstanceBean = (ProcessInstanceBean)processInstances.iterator().next();
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
return("inspectInstance");
}
return "";
}
public List getOperatorsList (){
ArrayList operatorsList = new ArrayList();
SelectItem item = new SelectItem("=", "is equal to");
operatorsList.add(item);
item = new SelectItem("like", "is like");
operatorsList.add(item);
return operatorsList;
}
public long getProcessInstanceId() {
return processInstanceId;
}
public void setProcessInstanceId(long processInstanceId) {
this.processInstanceId = processInstanceId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isShowProcessInstances() {
if (processInstances == null) return false;
if (processInstances.size() == 0) return false;
return true;
}
public ArrayList getProcessInstances() {
return processInstances;
}
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public String getVariableValue() {
return variableValue;
}
public void setVariableValue(String variableValue) {
this.variableValue = variableValue;
}
public String getVariableNameOperator() {
return variableNameOperator;
}
public void setVariableNameOperator(String variableNameOperator) {
this.variableNameOperator = variableNameOperator;
}
public String getVariableValueOperator() {
return variableValueOperator;
}
public void setVariableValueOperator(String variableValueOperator) {
this.variableValueOperator = variableValueOperator;
}
}

View File

@@ -0,0 +1,141 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import javax.faces.context.FacesContext;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
/**
* Process Definition Bean Implementation.
*
* @author David Loiseau
*/
public class ProcessDefinitionBean {
String name;
int version;
long id;
int instancesCount;
public ProcessDefinitionBean() {
}
public ProcessDefinitionBean(long id) {
this.id = id;
initialize();
}
public ProcessDefinitionBean(long id, String name, int version, int instancesCount) {
this.id = id;
this.name = name;
this.version = version;
this.instancesCount = instancesCount;
}
private void initialize() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(id);
this.name = processDefinition.getName();
this.version = processDefinition.getVersion();
this.instancesCount = graphSession.findProcessInstances(this.id).size();
}
public List getProcessInstances() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ArrayList processInstancesList = new ArrayList();
List listProcessInstance = graphSession.findProcessInstances(this.id);
if (listProcessInstance.isEmpty() == false) {
ListIterator listProcessInstances = listProcessInstance.listIterator();
while (listProcessInstances.hasNext()) {
ProcessInstance processInstance = (ProcessInstance) listProcessInstances.next();
processInstancesList.add(new ProcessInstanceBean(processInstance.getId(), processInstance.getStart(), processInstance.getEnd()));
}
}
return processInstancesList;
}
public String showProcessInstances() {
ProcessDefinitionBean processDefinitionBean = new ProcessDefinitionBean();
processDefinitionBean.setId(this.id);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processDefinitionBean", processDefinitionBean);
return ("processInstances");
}
public String startProcessInstance() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(getId());
processDefinition.createInstance();
return showProcessInstances();
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
this.initialize();
}
public int getInstancesCount() {
return instancesCount;
}
public void setInstancesCount(int instancesCount) {
this.instancesCount = instancesCount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}

View File

@@ -0,0 +1,420 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.faces.context.FacesContext;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.db.TaskMgmtSession;
import org.jbpm.graph.def.Transition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
/**
* Process Instance Bean Implementation.
*
* @author David Loiseau
*/
public class ProcessInstanceBean {
long id;
String processDefinitionLabel;
long processDefinitionId;
Date start;
Date end;
ArrayList tokens;
ArrayList variables;
ArrayList tasks;
ArrayList transitions;
String variableName;
String variableValue;
long tokenInstanceId;
long taskInstanceId;
public ProcessInstanceBean(long id, Date start, Date end) {
this.id = id;
this.start = start;
this.end = end;
}
public ProcessInstanceBean(long id) {
this.id = id;
this.initialize();
}
public ProcessInstanceBean(long id, String variableName, String variableValue) {
this.id = id;
this.variableName = variableName;
this.variableValue = variableValue;
this.initialize();
}
public String inspectProcessInstance() {
ProcessInstanceBean processInstanceBean = new ProcessInstanceBean(this.id);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
return ("inspectInstance");
}
public String deleteProcessInstance() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
graphSession.deleteProcessInstance(this.id);
return ("deleteInstance");
}
private void initialize() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessInstance processInstance = graphSession.loadProcessInstance(this.id);
this.start = processInstance.getStart();
this.end = processInstance.getEnd();
this.processDefinitionId = processInstance.getProcessDefinition().getId();
this.processDefinitionLabel = processInstance.getProcessDefinition().getName() + " (version " + processInstance.getProcessDefinition().getVersion() + ")";
initializeVariablesList(processInstance);
initializeTokensList(processInstance);
initializeTasksList(processInstance);
}
private void initializeAvailableTransitions(TaskInstance taskInstance) {
transitions = new ArrayList();
if (taskInstance.getAvailableTransitions().isEmpty() == false) {
Iterator availableTransitionsIterator = taskInstance.getAvailableTransitions().iterator();
while (availableTransitionsIterator.hasNext()) {
Transition transition = (Transition) availableTransitionsIterator.next();
transitions.add(transition);
}
}
}
private void initializeAvailableTransitions(Token token) {
transitions = new ArrayList();
if (token.getNode().getLeavingTransitions().isEmpty() == false) {
Iterator availableTransitionsIterator = token.getNode().getLeavingTransitions().iterator();
while (availableTransitionsIterator.hasNext()) {
Transition transition = (Transition) availableTransitionsIterator.next();
transitions.add(transition);
}
}
}
private void initializeVariablesList(ProcessInstance processInstance) {
// Variables list
variables = new ArrayList();
if (processInstance.getContextInstance().getVariables() != null && !processInstance.getContextInstance().getVariables().values().isEmpty()) {
int mapsize = processInstance.getContextInstance().getVariables().size();
Iterator variablesIterator = processInstance.getContextInstance().getVariables().entrySet().iterator();
for (int i = 0; i < mapsize; i++) {
Entry entry = (Entry) variablesIterator.next();
variables.add(new VariableBean((String) entry.getKey(), entry.getValue()));
}
}
}
private void initializeTasksList(ProcessInstance processInstance) {
// Tasks list
tasks = new ArrayList();
if (processInstance.getTaskMgmtInstance().getTaskInstances().isEmpty() == false) {
Iterator tasksIterator = processInstance.getTaskMgmtInstance().getTaskInstances().iterator();
while (tasksIterator.hasNext()) {
TaskInstance taskInstance = (TaskInstance) tasksIterator.next();
tasks.add(new TaskBean(taskInstance.getId(), taskInstance.getName(), taskInstance.getActorId(), taskInstance.getEnd()));
}
}
}
private void initializeTokensList(ProcessInstance processInstance) {
// Tokens list
Token rootToken = processInstance.getRootToken();
tokens = new ArrayList();
this.tokenInstanceId = rootToken.getId();
this.taskInstanceId = 0;
tokens.add(new TokenBean(rootToken.getId(), "Root", rootToken.getNode().getName(), rootToken.getNode().getClass().getName(), rootToken.getStart(),
rootToken.getEnd(), 1));
try {
if (rootToken.getChildren().isEmpty() == false) {
AddChildrenTokensToTokensList(this.tokens, rootToken, 2);
}
} catch (Exception exception) {
}
}
/**
*
* Add token childs to the current token beans list
*
* @param tokensList
* Current token list to update
* @param token
* Token where are the token childs
* @param level
* Level where is the token: 1 for the root token, 2 for the childs
* of the root token, ...
*/
private void AddChildrenTokensToTokensList(ArrayList tokensList, Token token, long level) {
Iterator childrenIterator = token.getChildren().values().iterator();
while (childrenIterator.hasNext()) {
Token childToken = (Token) childrenIterator.next();
tokensList.add(new TokenBean(childToken.getId(), childToken.getName(), childToken.getNode().getName(), childToken.getNode().getClass().getName(),
childToken.getStart(), childToken.getEnd(), level));
try {
if (childToken.getChildren().isEmpty() == false) {
AddChildrenTokensToTokensList(tokensList, childToken, level + 1);
}
} catch (Exception exception) {
}
}
}
public String updateVariable() {
if (this.variableName != null) {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessInstance processInstance = graphSession.loadProcessInstance(this.id);
if (this.variableValue != null) {
processInstance.getContextInstance().setVariable(this.variableName, this.variableValue);
} else {
processInstance.getContextInstance().deleteVariable(this.variableName);
}
initializeVariablesList(processInstance);
}
return "inspectInstance";
}
public String selectToken() {
this.taskInstanceId = 0;
this.tokenInstanceId = JsfHelper.getId("tokenInstanceId");
return "";
}
public String selectTask() {
this.tokenInstanceId = 0;
this.taskInstanceId = JsfHelper.getId("taskInstanceId");
return "";
}
public String signal() {
selectToken();
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
Token token = graphSession.loadToken(this.tokenInstanceId);
if (token.getNode().getLeavingTransitions().size() > 1) {
initializeAvailableTransitions(token);
return "showTransitions";
}
token.signal();
this.initializeTokensList(token.getProcessInstance());
return "inspectInstance";
}
public String selectTransition() {
String transitionName;
transitionName = JsfHelper.getParameter("transitionName");
ProcessInstance processInstance = null;
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (this.taskInstanceId > 0) {
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(this.taskInstanceId);
if (transitionName.equals("")) {
taskInstance.end();
} else {
taskInstance.end(transitionName);
}
processInstance = taskInstance.getToken().getProcessInstance();
} else if (this.tokenInstanceId > 0) {
GraphSession graphSession = jbpmContext.getGraphSession();
Token token = graphSession.loadToken(this.tokenInstanceId);
if (transitionName.equals("")) {
token.signal();
} else {
token.signal(transitionName);
}
processInstance = token.getProcessInstance();
}
jbpmContext.save(processInstance);
this.initializeTasksList(processInstance);
this.initializeTokensList(processInstance);
return "inspectInstance";
}
public String endTask() {
selectTask();
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(this.taskInstanceId);
if (taskInstance.getAvailableTransitions().size() > 1) {
initializeAvailableTransitions(taskInstance);
return "showTransitions";
}
taskInstance.end();
ProcessInstance processInstance = taskInstance.getToken().getProcessInstance();
jbpmContext.save(processInstance);
this.initializeTasksList(processInstance);
this.initializeTokensList(processInstance);
return "inspectInstance";
}
// Show all the process instances for a given process definition ID
public String showProcessInstances() {
ProcessDefinitionBean processDefinitionBean = new ProcessDefinitionBean(this.processDefinitionId);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processDefinitionBean", processDefinitionBean);
return ("processInstances");
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Date getStart() {
return start;
}
public void setStart(Date start) {
this.start = start;
}
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
public ArrayList getTokens() {
return tokens;
}
public void setTokens(ArrayList tokens) {
this.tokens = tokens;
}
public String getProcessDefinitionLabel() {
return processDefinitionLabel;
}
public void setProcessDefinitionLabel(String processDefinitionLabel) {
this.processDefinitionLabel = processDefinitionLabel;
}
public ArrayList getVariables() {
return variables;
}
public ArrayList getTasks() {
return tasks;
}
public ArrayList getTransitions() {
return transitions;
}
public void setVariables(ArrayList variables) {
this.variables = variables;
}
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public String getVariableValue() {
return variableValue;
}
public void setVariableValue(String variableValue) {
this.variableValue = variableValue;
}
public long getTokenInstanceId() {
return tokenInstanceId;
}
public void setTokenInstanceId(long tokenInstanceId) {
this.taskInstanceId = 0;
this.tokenInstanceId = tokenInstanceId;
}
public long getTaskInstanceId() {
return taskInstanceId;
}
public void setTaskInstanceId(long taskInstanceId) {
this.tokenInstanceId = 0;
this.taskInstanceId = taskInstanceId;
}
}

View File

@@ -0,0 +1,269 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmContext;
import org.jbpm.context.def.VariableAccess;
import org.jbpm.graph.def.Transition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.logging.exe.LoggingInstance;
import org.jbpm.taskmgmt.def.TaskController;
import org.jbpm.taskmgmt.exe.TaskInstance;
import org.jbpm.taskmgmt.log.TaskAssignLog;
public class TaskBean {
UserBean userBean = null;
List taskFormParameters;
List availableTransitions;
List availableTransitionItems;
TaskInstance taskInstance;
long taskInstanceId;
DataModel transitions;
// JbpmContext jbpmContext;
// GraphSession graphSession;
// TaskMgmtSession taskMgmtSession;
// For monitoring purposes
String name;
String actorId;
Date end;
public TaskBean() {
// this.jbpmContext = JbpmContext.getCurrentJbpmContext();
// this.graphSession = jbpmContext.getGraphSession();
// this.taskMgmtSession = jbpmContext.getTaskMgmtSession();
// get the parameters from the session
// this.taskFormParameters = (List) JsfHelper.getSessionAttribute("taskFormParameters");
}
public TaskBean(long taskInstanceId, String name, String actorId, Date end) {
this.taskInstanceId = taskInstanceId;
this.name = name;
this.actorId = actorId;
this.end = end;
}
public void initialize(TaskInstance taskInstance) {
this.taskInstance = taskInstance;
this.taskInstanceId = taskInstance.getId();
// set the parameters
this.taskFormParameters = new ArrayList();
TaskController taskController = taskInstance.getTask().getTaskController();
if (taskController!=null) {
List variableAccesses = taskController.getVariableAccesses();
Iterator iter = variableAccesses.iterator();
while (iter.hasNext()) {
VariableAccess variableAccess = (VariableAccess) iter.next();
String mappedName = variableAccess.getMappedName();
Object value = taskInstance.getVariable(mappedName);
TaskFormParameter tfp = new TaskFormParameter(variableAccess, value);
taskFormParameters.add(tfp);
}
}
// store the parameters in the session
//JsfHelper.setSessionAttribute("taskFormParameters", taskFormParameters);
// get the available transitions
availableTransitions = null;
availableTransitions = taskInstance.getAvailableTransitions();
if ((availableTransitions != null) && (availableTransitions.size() <= 1)) {
transitions = null;
availableTransitions = null;
availableTransitionItems = null;
} else {
transitions = new ListDataModel(availableTransitions);
availableTransitionItems = new ArrayList();
Iterator iter = availableTransitions.iterator();
while (iter.hasNext()) {
Transition transition = (Transition) iter.next();
SelectItem transitionItem = new SelectItem();
transitionItem.setValue(transition.getName());
transitionItem.setLabel(transition.getName());
transitionItem.setDisabled(false);
availableTransitionItems.add(transitionItem);
}
}
log.debug("initialized availableTransitions " + availableTransitions);
}
public String save() {
log.debug("saving the task parameters " + taskFormParameters);
// submit the parameters in the jbpm task controller
TaskInstance taskInstance = JbpmContext.getCurrentJbpmContext().getTaskMgmtSession().loadTaskInstance(taskInstanceId);
// collect the parameter values from the values that were updated in the
// parameters by jsf.
Iterator iter = taskFormParameters.iterator();
while (iter.hasNext()) {
TaskFormParameter taskFormParameter = (TaskFormParameter) iter.next();
if ((taskFormParameter.isWritable()) && (taskFormParameter.getValue() != null)) {
log.debug("submitting [" + taskFormParameter.getLabel() + "]=" + taskFormParameter.getValue());
taskInstance.setVariable(taskFormParameter.getLabel(), taskFormParameter.getValue());
} else {
log.debug("ignoring unwritable [" + taskFormParameter.getLabel() + "]");
}
}
// save the process instance and hence the updated task instance variables
JbpmContext.getCurrentJbpmContext().save(taskInstance);
// remove the parameters from the session
//JsfHelper.removeSessionAttribute("taskFormParameters");
return "home";
}
public String saveAndClose() {
// save
save();
TaskInstance taskInstance = JbpmContext.getCurrentJbpmContext().getTaskMgmtSession().loadTaskInstance(taskInstanceId);
// close the task instance
if (transitions == null)
{
taskInstance.end();
}
else
{
Transition selectedTransition = (Transition)transitions.getRowData();
taskInstance.end(selectedTransition.getName());
}
ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
if (processInstance.hasEnded()) {
JsfHelper.addMessage("The process has finished.");
}
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
List assignmentLogs = loggingInstance.getLogs(TaskAssignLog.class);
log.debug("assignmentlogs: " + assignmentLogs);
if (assignmentLogs.size() == 1) {
TaskAssignLog taskAssignLog = (TaskAssignLog) assignmentLogs.get(0);
JsfHelper.addMessage("A new task has been assigned to '" + taskAssignLog.getTaskNewActorId() + "'");
} else if (assignmentLogs.size() > 1) {
String msg = "New tasks have been assigned to: ";
Iterator iter = assignmentLogs.iterator();
while (iter.hasNext()) {
TaskAssignLog taskAssignLog = (TaskAssignLog) iter.next();
msg += taskAssignLog.getActorId();
if (iter.hasNext())
msg += ", ";
}
msg += ".";
JsfHelper.addMessage(msg);
}
JbpmContext.getCurrentJbpmContext().save(taskInstance);
return "home";
}
public long getTaskInstanceId() {
return taskInstanceId;
}
public void setTaskInstanceId(long taskInstanceId) {
this.taskInstanceId = taskInstanceId;
}
public UserBean getUserBean() {
return userBean;
}
public void setUserBean(UserBean userBean) {
this.userBean = userBean;
}
public List getTaskFormParameters() {
return taskFormParameters;
}
public DataModel getTransitions()
{
return transitions;
}
public List getAvailableTransitions() {
return availableTransitions;
}
public void setAvailableTransitions(List availableTransitions) {
this.availableTransitions = availableTransitions;
}
public List getAvailableTransitionItems() {
return availableTransitionItems;
}
public TaskInstance getTaskInstance() {
return taskInstance;
}
private static final Log log = LogFactory.getLog(TaskBean.class);
public String getActorId() {
return actorId;
}
public void setActorId(String actorId) {
this.actorId = actorId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
public boolean isEnded() {
if (end == null)
return true;
return false;
}
}

View File

@@ -0,0 +1,109 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.io.Serializable;
import org.hibernate.Session;
import org.jbpm.context.def.VariableAccess;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class TaskFormParameter implements Serializable {
private static final long serialVersionUID = 1L;
protected String label = null;
protected String description = null;
protected Object value = null;
protected boolean isReadable = true;
protected boolean isWritable = true;
protected boolean isRequired = true;
public TaskFormParameter() {
}
public TaskFormParameter(VariableAccess variableAccess, Object value) {
this.label = variableAccess.getMappedName();
this.value = value;
this.isReadable = variableAccess.isReadable();
this.isWritable = variableAccess.isWritable();
this.isRequired = variableAccess.isRequired();
}
public TaskFormParameter(TaskFormParameter other) {
this.label = other.label;
this.description = other.description;
this.value = other.value;
this.isReadable = other.isReadable;
this.isWritable = other.isWritable;
this.isRequired = other.isRequired;
}
public static TaskFormParameter create(TaskInstance instance, String name, Object value, Session session) {
TaskFormParameter taskFormParameter = null;
return taskFormParameter;
}
public String toString() {
return "("+label+","+value+")";
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isReadable() {
return isReadable;
}
public void setReadable(boolean isReadable) {
this.isReadable = isReadable;
}
public boolean isRequired() {
return isRequired;
}
public void setRequired(boolean isRequired) {
this.isRequired = isRequired;
}
public boolean isWritable() {
return isWritable;
}
public boolean isReadOnly() {
return !isWritable;
}
public void setWritable(boolean isWritable) {
this.isWritable = isWritable;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}

View File

@@ -0,0 +1,125 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.Date;
/**
* Token Bean Implementation.
*
* @author David Loiseau
*/
public class TokenBean {
long id;
String name;
String nodeName;
String nodeClassName;
Date start;
Date end;
long level;
public TokenBean(long id, String name, String nodeName, String nodeClassName, Date start, Date end, long level) {
this.id = id;
this.name = name;
this.nodeName = nodeName;
this.nodeClassName = nodeClassName;
this.start = start;
this.end = end;
this.level = level;
}
private String getTypeNameFromClassName(String className) {
String typeName = "";
if (className.indexOf(".") > 0) {
typeName = className.substring(className.lastIndexOf(".") + 1);
}
return typeName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLabel() {
String label = "";
int i = 1;
while (i < this.level) {
label = label + "---";
i++;
}
if (i > 1)
label = label + " ";
label = label + this.name;
return label;
}
public String getNodeName() {
return nodeName;
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
public Date getStart() {
return start;
}
public void setStart(Date start) {
this.start = start;
}
public String getNodeType() {
return getTypeNameFromClassName(this.nodeClassName);
}
public boolean isSignal() {
if (this.end == null)
return true;
return false;
}
}

View File

@@ -0,0 +1,77 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.model.SelectItem;
import org.hibernate.Session;
import org.jbpm.JbpmContext;
import org.jbpm.identity.User;
import org.jbpm.identity.hibernate.IdentitySession;
public class UserBean {
String userName;
public String getUserName() {
return userName;
}
public void setUserName(String name) {
this.userName = name;
}
public String login() {
JbpmContext.getCurrentJbpmContext().setActorId(userName);
return "home";
}
public List getUsers() {
Session session = JbpmContext.getCurrentJbpmContext().getSession();
IdentitySession identitySession = new IdentitySession(session);
return identitySession.getUsers();
}
public List getUserSelectItems() {
List userSelectItems = new ArrayList();
Iterator iter = getUsers().iterator();
while (iter.hasNext()) {
User user = (User) iter.next();
userSelectItems.add(new UserSelectItem(user));
}
return userSelectItems;
}
public static class UserSelectItem extends SelectItem {
private static final long serialVersionUID = 1L;
public UserSelectItem(User user) {
setValue(user.getName());
setLabel(user.getName());
}
}
}

View File

@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.bean;
/**
* Variable Bean Implementation.
*
* @author David Loiseau
*/
public class VariableBean {
String name;
Object value;
public VariableBean(String name, Object value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}

View File

@@ -0,0 +1,44 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.context;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class BpmContext {
ProcessDefinition processDefinition;
TaskInstance taskInstance;
public ProcessDefinition getProcessDefinition() {
return processDefinition;
}
public void setProcessDefinition(ProcessDefinition processDefinition) {
this.processDefinition = processDefinition;
}
public TaskInstance getTaskInstance() {
return taskInstance;
}
public void setTaskInstance(TaskInstance taskInstance) {
this.taskInstance = taskInstance;
}
}

View File

@@ -0,0 +1,60 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.context;
import java.util.HashMap;
import java.util.Map;
public class Context {
static ThreadLocal contextsThreadLocal = new ThreadLocal();
public static void create() {
contextsThreadLocal.set(new HashMap());
}
public static void destroy() {
contextsThreadLocal.set(null);
}
public static Object getContext(Class clazz) {
Map contexts = (Map) contextsThreadLocal.get();
Object context = contexts.get(clazz);
if (context==null) {
try {
context = clazz.newInstance();
contexts.put(clazz, context);
} catch (Exception e) {
throw new RuntimeException("couldn't instantiate context '"+clazz.getName()+"'");
}
}
return context;
}
public static PersistenceContext getPersistenceContext() {
return (PersistenceContext) getContext(PersistenceContext.class);
}
public static BpmContext getBpmContext() {
return (BpmContext) getContext(BpmContext.class);
}
}

View File

@@ -0,0 +1,83 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.jbpm.db.JbpmSession;
import org.jbpm.db.JbpmSessionFactory;
import org.jbpm.identity.hibernate.IdentitySession;
public class PersistenceContext {
static String jndiName = "java:/jbpm/SessionFactory";
static JbpmSessionFactory jbpmSessionFactory = null;
static {
try {
InitialContext initialContext = new InitialContext();
Object o = initialContext.lookup(jndiName);
SessionFactory sessionFactory = (SessionFactory) PortableRemoteObject.narrow(o, SessionFactory.class);
jbpmSessionFactory = new JbpmSessionFactory(null, sessionFactory);
} catch (Exception e) {
throw new RuntimeException("couldn't get the hibernate session factory from jndi entry '"+jndiName+"'", e);
}
}
boolean isRollbackOnly;
JbpmSession jbpmSession;
IdentitySession identitySession;
public void beginTransaction() {
isRollbackOnly = false;
log.debug("beginning transaction");
jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction();
identitySession = new IdentitySession(jbpmSession.getSession());
}
public void endTransaction() {
if (isRollbackOnly) {
log.debug("rolling back transaction");
jbpmSession.rollbackTransactionAndClose();
} else {
log.debug("committing transaction");
jbpmSession.commitTransactionAndClose();
}
}
public void setRollbackOnly() {
isRollbackOnly = true;
}
public IdentitySession getIdentitySession() {
return identitySession;
}
public JbpmSession getJbpmSession() {
return jbpmSession;
}
private static final Log log = LogFactory.getLog(PersistenceContext.class);
}

View File

@@ -0,0 +1,60 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.jbpm.JbpmContext;
import org.jbpm.webapp.bean.UserBean;
public class AuthenticationFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession();
UserBean userBean = null;
if (session!=null) {
userBean = (UserBean) session.getAttribute("userBean");
}
if (userBean!=null) {
String actorId = userBean.getUserName();
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
jbpmContext.setActorId(actorId);
}
filterChain.doFilter(servletRequest, servletResponse);
}
public void destroy() {
}
}

View File

@@ -0,0 +1,88 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.filter;
import java.io.IOException;
import java.io.Serializable;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.service.transaction.TransactionService;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class JbpmContextFilter implements Filter, Serializable
{
private static final long serialVersionUID = 1L;
private ServletContext context;
public void init(FilterConfig filterConfig) throws ServletException
{
this.context = filterConfig.getServletContext();
}
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain)
throws IOException, ServletException
{
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
final JbpmConfiguration jbpmConfig = (JbpmConfiguration) wc.getBean("jbpm_configuration");
TransactionService trx = (TransactionService) wc.getBean("TransactionService");
TransactionUtil.executeInUserTransaction(trx, new TransactionUtil.TransactionWork<Object>()
{
public Object doWork() throws Exception
{
JbpmContext jbpmContext = jbpmConfig.createJbpmContext();
try
{
String actorId = AuthenticationUtil.getCurrentUserName();
if (actorId != null)
{
jbpmContext.setActorId(actorId);
}
filterChain.doFilter(servletRequest, servletResponse);
}
finally
{
jbpmContext.close();
}
return null;
}
});
}
public void destroy()
{
}
}

View File

@@ -0,0 +1,69 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.filter;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LogFilter implements Filter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
log.debug("request "+request.getRequestURL());
Enumeration enumeration = request.getParameterNames();
while (enumeration.hasMoreElements()) {
String paramName = (String) enumeration.nextElement();
log.debug("request parameter ["+paramName+"]="+request.getParameter(paramName));
}
HttpSession session = request.getSession();
enumeration = session.getAttributeNames();
while (enumeration.hasMoreElements()) {
String attributeName = (String) enumeration.nextElement();
log.debug("session parameter ["+attributeName+"]="+session.getAttribute(attributeName));
}
filterChain.doFilter(servletRequest, servletResponse);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
public void destroy() {
}
private static final Log log = LogFactory.getLog(LogFilter.class);
}

View File

@@ -0,0 +1,68 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.zip.ZipInputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
/**
* servlet to be used by the process designer to deploy processes.
*/
public class DeployServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String archive = request.getParameter("archive");
log.debug("deploying archive "+archive);
PrintWriter writer = response.getWriter();
try {
URL archiveUrl = new URL(archive);
ZipInputStream zis = new ZipInputStream(archiveUrl.openStream());
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zis);
jbpmContext.deployProcessDefinition(processDefinition);
zis.close();
writer.write("Deployed archive "+archive+" successfully");
} catch (Exception e) {
e.printStackTrace();
writer.write("Deploying archive "+archive+" failed");
}
}
private static Log log = LogFactory.getLog(DeployServlet.class);
}

View File

@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.servlet;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
public class ProcessImageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
ProcessDefinition processDefinition = jbpmContext.getGraphSession().loadProcessDefinition(processDefinitionId);
byte[] bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
OutputStream out = response.getOutputStream();
out.write(bytes);
out.flush();
// leave this in. it is in case we want to set the mime type later.
// get the mime type
// String contentType = URLConnection.getFileNameMap().getContentTypeFor( fileName );
// set the content type (=mime type)
// response.setContentType( contentType );
}
}

View File

@@ -0,0 +1,119 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.ParameterParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
public class UploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private class GPDUpload extends DiskFileUpload
{
@Override
protected byte[] getBoundary(String contentType)
{
return super.getBoundary(contentType.replace(",", ";"));
}
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html");
response.getWriter().println(handleRequest(request));
}
public void printInput(HttpServletRequest request) throws IOException {
InputStream inputStream = request.getInputStream();
StringBuffer buffer = new StringBuffer();
int read;
while ((read = inputStream.read()) != -1) {
buffer.append((char)read);
}
log.debug(buffer.toString());
}
private String handleRequest(HttpServletRequest request) {
if (!FileUpload.isMultipartContent(request)) {
log.debug("Not a multipart request");
return "Not a multipart request";
}
try {
GPDUpload fileUpload = new GPDUpload();
List list = fileUpload.parseRequest(request);
Iterator iterator = list.iterator();
if (!iterator.hasNext()) {
log.debug("No process file in the request");
return "No process file in the request";
}
FileItem fileItem = (FileItem)iterator.next();
if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1) {
log.debug("Not a process archive");
return "Not a process archive";
}
return doDeployment(fileItem);
} catch (FileUploadException e) {
e.printStackTrace();
return "FileUploadException";
}
}
private String doDeployment(FileItem fileItem) {
try {
ZipInputStream zipInputStream = new ZipInputStream(fileItem.getInputStream());
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
log.debug("Created a processdefinition : " + processDefinition.getName() );
jbpmContext.deployProcessDefinition(processDefinition);
zipInputStream.close();
return "Deployed archive " + processDefinition.getName() + " successfully";
} catch (IOException e) {
return "IOException";
}
}
private static Log log = LogFactory.getLog(UploadServlet.class);
}

View File

@@ -0,0 +1,244 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.webapp.tag;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.XPath;
import org.dom4j.xpath.DefaultXPath;
import org.jbpm.JbpmContext;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.Token;
import org.jbpm.taskmgmt.exe.TaskInstance;
public class ProcessImageTag extends TagSupport {
private static final long serialVersionUID = 1L;
private long taskInstanceId = -1;
private long tokenInstanceId = -1;
private byte[] gpdBytes = null;
private byte[] imageBytes = null;
private Token currentToken = null;
private ProcessDefinition processDefinition = null;
static String currentTokenColor = "red";
static String childTokenColor = "blue";
static String tokenNameColor = "blue";
public void release() {
taskInstanceId = -1;
gpdBytes = null;
imageBytes = null;
currentToken = null;
}
public int doEndTag() throws JspException {
try {
initialize();
retrieveByteArrays();
if (gpdBytes != null && imageBytes != null) {
writeTable();
}
} catch (IOException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
} catch (DocumentException e) {
e.printStackTrace();
throw new JspException("table couldn't be displayed", e);
}
release();
return EVAL_PAGE;
}
private void retrieveByteArrays() {
try {
FileDefinition fileDefinition = processDefinition.getFileDefinition();
gpdBytes = fileDefinition.getBytes("gpd.xml");
imageBytes = fileDefinition.getBytes("processimage.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeTable() throws IOException, DocumentException {
int borderWidth = 4;
Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
int[] boxConstraint;
int[] imageDimension = extractImageDimension(rootDiagramElement);
String imageLink = "/alfresco/processimage?definitionId=" + processDefinition.getId();
JspWriter jspOut = pageContext.getOut();
if (tokenInstanceId > 0) {
List allTokens = new ArrayList();
walkTokens(currentToken, allTokens);
jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>");
for (int i = 0; i < allTokens.size(); i++)
{
Token token = (Token) allTokens.get(i);
//check how many tokens are on teh same level (= having the same parent)
int offset = i;
if(i > 0) {
while(offset > 0 && ((Token) allTokens.get(offset - 1)).getParent().equals(token.getParent())) {
offset--;
}
}
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
//Adjust for borders
//boxConstraint[2]-=borderWidth*2;
//boxConstraint[3]-=borderWidth*2;
jspOut.println("<div style='position:absolute; left: "+ boxConstraint[0] +"px; top: "+ boxConstraint[1] +"px; ");
if (i == (allTokens.size() - 1)) {
jspOut.println("border: " + currentTokenColor);
}
else {
jspOut.println("border: " + childTokenColor);
}
jspOut.println(" " + borderWidth + "px groove; "+
"width: "+ boxConstraint[2] +"px; height: "+ boxConstraint[3] +"px;'>");
if(token.getName()!=null)
{
jspOut.println("<span style='color:" + tokenNameColor + ";font-style:italic;position:absolute;left:"+ (boxConstraint[2] + 10) +"px;top:" +((i - offset) * 20) +";'>&nbsp;" + token.getName() +"</span>");
}
jspOut.println("</div>");
}
jspOut.println("</div>");
}
else
{
boxConstraint = extractBoxConstraint(rootDiagramElement);
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height=" + imageDimension[1] + ">");
jspOut.println(" <tr>");
jspOut.println(" <td width=" + imageDimension[0] + " height=" + imageDimension[1] + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
jspOut.println(" <table border=0 cellspacing=0 cellpadding=0>");
jspOut.println(" <tr>");
jspOut.println(" <td width=" + (boxConstraint[0] - borderWidth) + " height=" + (boxConstraint[1] - borderWidth)
+ " style=\"background-color:transparent;\"></td>");
jspOut.println(" </tr>");
jspOut.println(" <tr>");
jspOut.println(" <td style=\"background-color:transparent;\"></td>");
jspOut.println(" <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth + "px; border-style:groove; background-color:transparent;\" width="
+ boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + ">&nbsp;</td>");
jspOut.println(" </tr>");
jspOut.println(" </table>");
jspOut.println(" </td>");
jspOut.println(" </tr>");
jspOut.println("</table>");
}
}
private int[] extractBoxConstraint(Element root) {
int[] result = new int[4];
String nodeName = currentToken.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
return result;
}
private int[] extractBoxConstraint(Element root, Token token) {
int[] result = new int[4];
String nodeName = token.getNode().getName();
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
Element node = (Element) xPath.selectSingleNode(root);
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
return result;
}
private int[] extractImageDimension(Element root) {
int[] result = new int[2];
result[0] = Integer.valueOf(root.attribute("width").getValue()).intValue();
result[1] = Integer.valueOf(root.attribute("height").getValue()).intValue();
return result;
}
private void initialize() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (this.taskInstanceId > 0) {
TaskInstance taskInstance = jbpmContext.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
currentToken = taskInstance.getToken();
}
else
{
if (this.tokenInstanceId > 0)
currentToken = jbpmContext.getGraphSession().loadToken(this.tokenInstanceId);
}
processDefinition = currentToken.getProcessInstance().getProcessDefinition();
}
private void walkTokens(Token parent, List allTokens)
{
Map children = parent.getChildren();
if(children != null && children.size() > 0)
{
Collection childTokens = children.values();
for (Iterator iterator = childTokens.iterator(); iterator.hasNext();)
{
Token child = (Token) iterator.next();
walkTokens(child, allTokens);
}
}
allTokens.add(parent);
}
public void setTask(long id) {
this.taskInstanceId = id;
}
public void setToken(long id) {
this.tokenInstanceId = id;
}
}