0001: package org.obe.worklist;
0002:
0003: import org.apache.commons.logging.Log;
0004: import org.apache.commons.logging.LogFactory;
0005: import org.apache.myfaces.custom.fileupload.UploadedFile;
0006: import org.obe.client.api.WMClient;
0007: import org.obe.client.api.WMClientFactory;
0008: import org.obe.client.api.model.*;
0009: import org.obe.client.api.tool.Parameter;
0010: import org.obe.client.api.tool.ToolAgent;
0011: import org.obe.client.api.tool.ToolInvocation;
0012: import org.obe.util.WorkflowUtilities;
0013: import org.obe.util.DateUtilities;
0014: import org.obe.xpdl.model.activity.Activity;
0015: import org.obe.xpdl.model.data.BasicType;
0016: import org.obe.xpdl.model.data.FormalParameter;
0017: import org.obe.xpdl.model.data.ParameterMode;
0018: import org.obe.xpdl.model.data.Type;
0019: import org.obe.xpdl.model.participant.Participant;
0020: import org.obe.xpdl.model.pkg.ExternalPackage;
0021: import org.obe.xpdl.model.pkg.XPDLPackage;
0022: import org.obe.xpdl.model.workflow.WorkflowProcess;
0023: import org.wfmc.audit.*;
0024: import org.wfmc.wapi.*;
0025:
0026: import javax.faces.context.ExternalContext;
0027: import javax.faces.context.FacesContext;
0028: import javax.faces.model.SelectItem;
0029: import javax.servlet.ServletContext;
0030: import javax.servlet.http.HttpServletRequest;
0031: import javax.servlet.http.HttpSession;
0032: import java.io.IOException;
0033: import java.io.Serializable;
0034: import java.io.StringWriter;
0035: import java.io.Writer;
0036: import java.security.Principal;
0037: import java.util.*;
0038:
0039: /**
0040: * Provides access to the workflow service.
0041: *
0042: * @author Adrian Price
0043: */
0044: public class WorklistController implements Serializable {
0045: private static final long serialVersionUID = 1560276364597565193L;
0046: private static final Log _logger = LogFactory
0047: .getLog(WorklistController.class);
0048: private static final WMFilter PROC_DEF_FILTER = null;
0049: // new WMFilter("state", WMFilter.EQ, WMProcessDefinitionState.ENABLED_INT);
0050:
0051: private transient WMClient _client;
0052:
0053: private Boolean _administrator;
0054: private Boolean _author;
0055: private Boolean _designer;
0056: private Boolean _manager;
0057: private Boolean _user;
0058: private String _procDefId;
0059: private String _procInstId;
0060: private String _actDefId;
0061: private String _actInstId;
0062: private String _parentProcInstId;
0063: private String _parentActInstId;
0064: private String _workItemId;
0065: private SummaryBean _summary;
0066: private WMProcessDefinition _procDef;
0067: private WorkflowProcess _workflow;
0068: private Activity _activity;
0069: private ProcessInstanceBean _procInst;
0070: private ActivityInstanceBean _actInst;
0071: private WorkItemBean _workItem;
0072: private WorkItemBean _workItemToExecute;
0073: private WMAAuditEntry _auditEntry;
0074: private List _actualParms;
0075: private String _workItemsKey;
0076: private String _workItemsValue;
0077: private String _auditEntriesKey;
0078: private String _auditEntriesValue;
0079: private Map _parms = new HashMap(); // Parameter[], key=workItemId-toolIndex
0080:
0081: private static FacesContext getFacesContext() {
0082: return FacesContext.getCurrentInstance();
0083: }
0084:
0085: private static ExternalContext getExternalContext() {
0086: return getFacesContext().getExternalContext();
0087: }
0088:
0089: private static ServletContext getServletContext() {
0090: return (ServletContext) getExternalContext().getContext();
0091: }
0092:
0093: private static Map getRequestMap() {
0094: return getExternalContext().getRequestMap();
0095: }
0096:
0097: private static void add(Collection c, Object[] a) {
0098: if (c != null && a != null) {
0099: for (int i = 0; i < a.length; i++)
0100: c.add(a[i]);
0101: }
0102: }
0103:
0104: public WorklistController() {
0105: }
0106:
0107: protected void finalize() throws Throwable {
0108: try {
0109: if (_client != null)
0110: _client.disconnect();
0111: } catch (Exception e) {
0112: // We don't care about exceptions on disconnect.
0113: }
0114: super .finalize();
0115: }
0116:
0117: public String getPlatformDetails() {
0118: return System.getProperty("os.name") + '-'
0119: + System.getProperty("os.version") + " ("
0120: + System.getProperty("os.arch") + ") + JVM-"
0121: + System.getProperty("java.version") + " + "
0122: + getServletContext().getServerInfo();
0123: }
0124:
0125: public SelectItem[] getPerformers() throws WMWorkflowException {
0126: // Merge all defined participants into a single collection.
0127: List performers = new ArrayList();
0128: WorkflowProcess workflow = getWorkflowProcess();
0129: add(performers, workflow.getParticipant());
0130: addParticipants(performers, workflow.getPackage());
0131:
0132: // Convert participants into list items.
0133: SelectItem[] items = new SelectItem[performers.size()];
0134: Participant p;
0135: SelectItem item;
0136: for (int i = 0, n = performers.size(); i < n; i++) {
0137: p = (Participant) performers.get(i);
0138: item = new SelectItem();
0139:
0140: // Set item fields individually because ctor throws NPEs.
0141: item.setValue(p.getId());
0142: item
0143: .setLabel(p.getName() != null ? p.getName() : p
0144: .getId());
0145: item.setDescription(p.getDescription());
0146: items[i] = item;
0147: }
0148:
0149: return items;
0150: }
0151:
0152: private void addParticipants(Collection performers, XPDLPackage pkg) {
0153: add(performers, pkg.getParticipant());
0154: ExternalPackage[] extPkgs = pkg.getExternalPackage();
0155: for (int i = 0; i < extPkgs.length; i++)
0156: addParticipants(performers, extPkgs[i].getPackage());
0157: }
0158:
0159: public Throwable getRootCause() {
0160: Throwable t = (Throwable) getRequestMap().get(
0161: "javax.servlet.error.exception");
0162: while (t != null && t.getCause() != null)
0163: t = t.getCause();
0164: return t;
0165: }
0166:
0167: public String getRemoteUser() {
0168: return getExternalContext().getRemoteUser();
0169: }
0170:
0171: public Principal getUserPrincipal() {
0172: return getExternalContext().getUserPrincipal();
0173: }
0174:
0175: private Boolean isUserInRole(String role) {
0176: return Boolean.valueOf(getExternalContext().isUserInRole(role));
0177: }
0178:
0179: public boolean isAdministrator() {
0180: if (_administrator == null)
0181: _administrator = isUserInRole("administrator");
0182: return _administrator.booleanValue();
0183: }
0184:
0185: public boolean isAuthor() {
0186: if (_author == null)
0187: _author = isUserInRole("author");
0188: return _author.booleanValue();
0189: }
0190:
0191: public boolean isDesigner() {
0192: if (_designer == null)
0193: _designer = isUserInRole("designer");
0194: return _designer.booleanValue();
0195: }
0196:
0197: public boolean isManager() {
0198: if (_manager == null)
0199: _manager = isUserInRole("manager");
0200: return _manager.booleanValue();
0201: }
0202:
0203: public boolean isUser() {
0204: if (_user == null)
0205: _user = isUserInRole("user");
0206: return _user.booleanValue();
0207: }
0208:
0209: private void setProcessDefinitionId(String procDefId) {
0210: if (procDefId == null || !procDefId.equals(_procDefId))
0211: _procDef = null;
0212: _procDefId = procDefId;
0213: }
0214:
0215: private void setProcessInstanceId(String procInstId) {
0216: if (procInstId == null || !procInstId.equals(_procInstId)) {
0217: _procInst = null;
0218: _actualParms = null;
0219: }
0220: _procInstId = procInstId;
0221: }
0222:
0223: private void setActivityDefinitionId(String actDefId) {
0224: if (actDefId == null || !actDefId.equals(_actDefId))
0225: _activity = null;
0226: _actDefId = actDefId;
0227: }
0228:
0229: private void setActivityInstanceId(String actInstId) {
0230: if (actInstId == null || !actInstId.equals(_actInstId))
0231: _actInst = null;
0232: _actInstId = actInstId;
0233: }
0234:
0235: private void setWorkItemId(String workItemId) {
0236: if (workItemId == null || !workItemId.equals(_workItemId))
0237: _workItem = null;
0238: _workItemId = workItemId;
0239: }
0240:
0241: private void setProcessDefinition(WMProcessDefinition procDef) {
0242: _procDef = procDef;
0243: if (procDef != null)
0244: _procDefId = procDef.getId();
0245: }
0246:
0247: private void setActivityDefinition(Activity actDef) {
0248: _activity = actDef;
0249: if (actDef != null)
0250: _actDefId = actDef.getId();
0251: }
0252:
0253: private void setProcessInstance(ProcessInstanceBean procInst) {
0254: _procInst = procInst;
0255: _actualParms = null;
0256: if (procInst != null) {
0257: _procInstId = procInst.getId();
0258: _parentProcInstId = procInst.getParentProcessInstanceId();
0259: _parentActInstId = procInst.getParentActivityInstanceId();
0260: setProcessDefinitionId(procInst.getProcessDefinitionId());
0261: }
0262: }
0263:
0264: private void setActivityInstance(ActivityInstanceBean actInst) {
0265: _actInst = actInst;
0266: if (actInst != null) {
0267: _actInstId = actInst.getId();
0268: setProcessInstanceId(actInst.getProcessInstanceId());
0269: setActivityDefinitionId(actInst.getActivityDefinitionId());
0270: setProcessDefinitionId(actInst.getProcessDefinitionId());
0271: }
0272: }
0273:
0274: private void setWorkItem(WorkItemBean workItem) {
0275: _workItem = workItem;
0276: if (workItem != null) {
0277: _workItemId = workItem.getId();
0278: setActivityInstanceId(workItem.getActivityInstanceId());
0279: setProcessInstanceId(workItem.getProcessInstanceId());
0280: setActivityDefinitionId(workItem.getActivityDefinitionId());
0281: setProcessDefinitionId(workItem.getProcessDefinitionId());
0282: }
0283: }
0284:
0285: private void setAuditEntry(WMAAuditEntry auditEntry) {
0286: _auditEntry = auditEntry;
0287: }
0288:
0289: private void clearIds() {
0290: setProcessDefinitionId(null);
0291: setProcessInstanceId(null);
0292: setActivityDefinitionId(null);
0293: setActivityInstanceId(null);
0294: setWorkItemId(null);
0295: _summary = null;
0296: _actualParms = null;
0297: }
0298:
0299: private void clearObjects() {
0300: setProcessDefinition(null);
0301: setProcessInstance(null);
0302: setActivityDefinition(null);
0303: setActivityInstance(null);
0304: setWorkItem(null);
0305: _summary = null;
0306: _actualParms = null;
0307: }
0308:
0309: public String getDateFormat() {
0310: // return DateUtilities.DEFAULT_DATE_FORMAT;
0311: return "yyyy-MM-dd HH:mm:ss";
0312: }
0313:
0314: public SummaryBean getSummary() throws WMWorkflowException {
0315: if (_summary == null) {
0316: List workItems = getWorklist();
0317: int openCount = 0;
0318: int suspendedCount = 0;
0319: int undefinedCount = 0;
0320: int normalCount = 0;
0321: int warningCount = 0;
0322: int overdueCount = 0;
0323: for (int i = 0; i < workItems.size(); i++) {
0324: WorkItemBean workItem = (WorkItemBean) workItems.get(i);
0325: WMWorkItemState state = workItem.getState();
0326: if (state.isOpen()) {
0327: openCount++;
0328: if (state == WMWorkItemState.OPEN_SUSPENDED)
0329: suspendedCount++;
0330: switch (workItem.getTemporalStatus().value()) {
0331: case TemporalStatus.UNDEFINED_INT:
0332: undefinedCount++;
0333: break;
0334: case TemporalStatus.NORMAL_INT:
0335: normalCount++;
0336: break;
0337: case TemporalStatus.WARNING_INT:
0338: warningCount++;
0339: break;
0340: case TemporalStatus.OVERDUE_INT:
0341: overdueCount++;
0342: break;
0343: }
0344: }
0345: }
0346: _summary = new SummaryBean(openCount, suspendedCount,
0347: undefinedCount, normalCount, warningCount,
0348: overdueCount);
0349: }
0350: return _summary;
0351: }
0352:
0353: public List getProcessDefinitions() throws WMWorkflowException {
0354: WMProcessDefinitionIterator i = getClient()
0355: .listProcessDefinitions(PROC_DEF_FILTER, false);
0356: return WorklistUtils.iteratorToList(i);
0357: }
0358:
0359: public WMProcessDefinition getProcessDefinition()
0360: throws WMWorkflowException {
0361:
0362: if (_procDef == null && _procDefId != null) {
0363: WMProcessDefinitionIterator i = getClient()
0364: .listProcessDefinitions(
0365: new WMFilter("processDefinitionId",
0366: WMFilter.EQ, _procDefId), false);
0367: if (i.hasNext())
0368: _procDef = i.tsNext();
0369: }
0370: return _procDef;
0371: }
0372:
0373: public List getActivityDefinitions() {
0374: // TODO: retrieve activity definitions.
0375: return null;
0376: }
0377:
0378: public WorkflowProcess getWorkflowProcess()
0379: throws WMWorkflowException {
0380:
0381: if (_workflow == null && _procDefId != null) {
0382: String pkgId = getProcessDefinition().getPackageId();
0383: XPDLPackage pkg = getClient().getPackage(pkgId);
0384: _workflow = WorkflowUtilities.findWorkflowProcess(pkg,
0385: _procDefId);
0386: }
0387: return _workflow;
0388: }
0389:
0390: public Activity getActivityDefinition() throws WMWorkflowException {
0391: if (_activity == null && _actDefId != null) {
0392: WorkflowProcess workflow = getWorkflowProcess();
0393: _activity = WorkflowUtilities.findActivity(workflow,
0394: _actDefId);
0395: }
0396: return _activity;
0397: }
0398:
0399: public List getProcessInstances() throws WMWorkflowException {
0400: WMProcessInstanceIterator i = getClient()
0401: .listProcessInstances(
0402: new WMFilter(
0403: ProcessInstanceAttributes.PROCESS_DEFINITION_ID,
0404: WMFilter.EQ, _procDefId), false);
0405: List processes = new ArrayList(i.getCount());
0406: while (i.hasNext())
0407: processes.add(new ProcessInstanceBean(
0408: (OBEProcessInstance) i.next()));
0409: return processes;
0410: }
0411:
0412: public ProcessInstanceBean getProcessInstance()
0413: throws WMWorkflowException {
0414: if (_procInst == null) {
0415: _procInst = (ProcessInstanceBean) getRequestMap().get(
0416: "procInst");
0417: if (_procInst == null && _procInstId != null) {
0418: _procInst = new ProcessInstanceBean(
0419: (OBEProcessInstance) getClient()
0420: .getProcessInstance(_procInstId));
0421: }
0422: }
0423: return _procInst;
0424: }
0425:
0426: public List getProcessInstanceAttributes()
0427: throws WMWorkflowException {
0428: WMAttributeIterator i = getClient()
0429: .listProcessInstanceAttributes(_procInstId, null, false);
0430: return WorklistUtils.iteratorToList(i);
0431: }
0432:
0433: public List getActivityInstances() throws WMWorkflowException {
0434: WMActivityInstanceIterator i = getClient()
0435: .listActivityInstances(
0436: new WMFilter(
0437: ActivityInstanceAttributes.PROCESS_INSTANCE_ID,
0438: WMFilter.EQ, _procInstId), false);
0439: List activities = new ArrayList(i.getCount());
0440: while (i.hasNext())
0441: activities.add(new ActivityInstanceBean(
0442: (OBEActivityInstance) i.next()));
0443: return activities;
0444: }
0445:
0446: public ActivityInstanceBean getActivityInstance()
0447: throws WMWorkflowException {
0448: if (_actInst == null) {
0449: _actInst = (ActivityInstanceBean) getRequestMap().get(
0450: "actInst");
0451: if (_actInst == null && _actInstId != null) {
0452: _actInst = new ActivityInstanceBean(
0453: (OBEActivityInstance) getClient()
0454: .getActivityInstance(_procInstId,
0455: _actInstId));
0456: }
0457: }
0458: return _actInst;
0459: }
0460:
0461: public List getWorkItems() throws WMWorkflowException {
0462: WMWorkItemIterator i = getClient().listWorkItems(
0463: new WMFilter(_workItemsKey, WMFilter.EQ,
0464: _workItemsValue), false);
0465: List workItems = new ArrayList(i.getCount());
0466: while (i.hasNext())
0467: workItems.add(new WorkItemBean((OBEWorkItem) i.next()));
0468: return workItems;
0469: }
0470:
0471: public WorkItemBean getWorkItem() throws WMWorkflowException {
0472: if (_workItem == null) {
0473: _workItem = (WorkItemBean) getRequestMap().get("workItem");
0474: if (_workItem == null && _workItemId != null) {
0475: _workItem = new WorkItemBean((OBEWorkItem) getClient()
0476: .getWorkItem(_procInstId, _workItemId));
0477: }
0478: }
0479: return _workItem;
0480: }
0481:
0482: public List getAuditEntries() throws WMWorkflowException {
0483: WMAAuditEntryIterator iter = getClient().listAuditEntries(
0484: new OBEFilter(_auditEntriesKey, WMFilter.EQ,
0485: _auditEntriesValue, "auditEntryId", 0, 0));
0486: return WorklistUtils.iteratorToList(iter);
0487: }
0488:
0489: public WMAAuditEntry getAuditEntry() {
0490: return _auditEntry;
0491: }
0492:
0493: public String getAuditEntryClass() {
0494: return "WMAAuditEntry";
0495: }
0496:
0497: public boolean isRenderWMAAuditBase() {
0498: return getAuditEntry() instanceof WMAAuditBase;
0499: }
0500:
0501: public boolean isRenderWMAAuditEntry() {
0502: return getAuditEntry() != null;
0503: }
0504:
0505: public boolean isRenderWMAAssignProcessInstanceAttributeData() {
0506: return getAuditEntry() instanceof WMAAssignProcessInstanceAttributeData;
0507: }
0508:
0509: public boolean isRenderWMAAssignActivityInstanceAttributesData() {
0510: return getAuditEntry() instanceof WMAAssignActivityInstanceAttributesData;
0511: }
0512:
0513: public boolean isRenderWMAAssignWorkItemAttributeData() {
0514: return getAuditEntry() instanceof WMAAssignWorkItemAttributeData;
0515: }
0516:
0517: public boolean isRenderWMAChangeActivityInstanceStateData() {
0518: return getAuditEntry() instanceof WMAChangeActivityInstanceStateData;
0519: }
0520:
0521: public boolean isRenderWMAChangeProcessDefinitionState() {
0522: return getAuditEntry() instanceof WMAChangeProcessDefinitionState;
0523: }
0524:
0525: public boolean isRenderWMAChangeProcessInstanceStateData() {
0526: return getAuditEntry() instanceof WMAChangeProcessInstanceStateData;
0527: }
0528:
0529: public boolean isRenderWMAChangeWorkItemStateData() {
0530: return getAuditEntry() instanceof WMAChangeWorkItemStateData;
0531: }
0532:
0533: public boolean isRenderWMAAssignWorkItemData() {
0534: return getAuditEntry() instanceof WMAAssignWorkItemData;
0535: }
0536:
0537: public boolean isRenderWMACreateProcessInstanceData() {
0538: return getAuditEntry() instanceof WMACreateProcessInstanceData;
0539: }
0540:
0541: public boolean isRenderWMADiscretionaryAuditData() {
0542: return getAuditEntry() instanceof WMADiscretionaryAuditData;
0543: }
0544:
0545: public boolean isRenderWMAPrivateAuditData() {
0546: return getAuditEntry() instanceof WMAPrivateAuditData;
0547: }
0548:
0549: public boolean isRenderWMASessionManagementAuditData() {
0550: return getAuditEntry() instanceof WMASessionManagementAuditData;
0551: }
0552:
0553: public List getWorklist() throws WMWorkflowException {
0554: WMWorkItemIterator i = getClient().listWorkItems(
0555: new WMFilter(WorkItemAttributes.PARTICIPANT,
0556: WMFilter.EQ, getRemoteUser()), false);
0557: List workItems = new ArrayList(i.getCount());
0558: while (i.hasNext())
0559: workItems.add(new WorkItemBean((OBEWorkItem) i.next()));
0560: return workItems;
0561: }
0562:
0563: public String getLaunchScript() throws IOException,
0564: WMWorkflowException {
0565:
0566: String script;
0567: WorkItemBean workItem = _workItemToExecute;
0568: if (workItem != null) {
0569: _workItemToExecute = null;
0570: ToolInvocation[] invocations = getClient().executeWorkItem(
0571: workItem.getProcessInstanceId(), workItem.getId());
0572: Writer writer = new StringWriter();
0573: for (int i = 0; i < invocations.length; i++) {
0574: ToolInvocation ti = invocations[i];
0575: ti.renderInvocationScript(getClient(), writer);
0576:
0577: // Store the tool invocation parameters for later use.
0578: _parms.put(_workItemId + '-' + i, ti.parameters);
0579: }
0580: writer.close();
0581: script = writer.toString();
0582: } else {
0583: script = null;
0584: }
0585: return script;
0586: }
0587:
0588: public List getActualParameters() throws WMWorkflowException {
0589: if (_actualParms == null) {
0590: _actualParms = new ArrayList();
0591: WMProcessDefinition procDef = getProcessDefinition();
0592: XPDLPackage pkg = getClient().getPackage(
0593: procDef.getPackageId());
0594: WorkflowProcess workflow = pkg
0595: .getWorkflowProcess(_procDefId);
0596: if (workflow == null) {
0597: _logger.error("Process definition '" + _procDefId
0598: + "' not found");
0599: } else {
0600: // Include the 'Name' system attribute.
0601: List attrs = getProcessInstanceAttributes();
0602: int nAttrs = attrs.size();
0603: for (int i = 0; i < nAttrs; i++) {
0604: WMAttribute attr = (WMAttribute) attrs.get(i);
0605: if (attr.getName().equals(
0606: ProcessInstanceAttributes.NAME)) {
0607: _actualParms.add(new AttributeBean(
0608: ProcessInstanceAttributes.NAME,
0609: "The name of the process instance",
0610: BasicType.valueOf(attr.getType()), attr
0611: .getLength(), attr.getValue()));
0612: break;
0613: }
0614: }
0615: // Append the attributes corresponding to the formal parameters.
0616: FormalParameter[] formalParms = workflow
0617: .getFormalParameter();
0618: for (int i = 0, n = formalParms.length; i < n; i++) {
0619: FormalParameter fp = formalParms[i];
0620: if (fp.getMode() != ParameterMode.OUT) {
0621: String id = fp.getId();
0622: for (int j = 0; j < nAttrs; j++) {
0623: WMAttribute attr = (WMAttribute) attrs
0624: .get(j);
0625: if (id.equals(attr.getName())) {
0626: Object attrValue = fp.getDataType()
0627: .getType().getImpliedType()
0628: .value() == Type.SCHEMA_TYPE ? null
0629: : attr.getValue();
0630: _actualParms.add(new AttributeBean(fp
0631: .getId(), fp.getDescription(),
0632: fp.getDataType().getType(),
0633: attr.getLength(), attrValue));
0634: break;
0635: }
0636: }
0637: }
0638: }
0639: }
0640: }
0641: return _actualParms;
0642: }
0643:
0644: public String showSelectedProcessDefinition() {
0645: setProcessDefinition((WMProcessDefinition) getRequestMap().get(
0646: "procDef"));
0647: if (_logger.isDebugEnabled())
0648: _logger.debug(this + ".showSelectedProcessDefinition()");
0649: return "processDefinition";
0650: }
0651:
0652: public String showSelectedActivityDefinition()
0653: throws WMWorkflowException {
0654: setActivityDefinition((Activity) getRequestMap().get("actDef"));
0655: if (_logger.isDebugEnabled())
0656: _logger.debug(this + ".showSelectedActivityDefinition()");
0657: return "activityDefinition";
0658: }
0659:
0660: public String showSelectedProcessInstance()
0661: throws WMWorkflowException {
0662: setProcessInstance((ProcessInstanceBean) getRequestMap().get(
0663: "procInst"));
0664: // setProcessInstance(getProcessInstance());
0665: if (_logger.isDebugEnabled())
0666: _logger.debug(this + ".showSelectedProcessInstance()");
0667: return getProcessInstance().getState() == WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED ? "newProcessInstance"
0668: : "processInstance";
0669: }
0670:
0671: public String showSelectedActivityInstance()
0672: throws WMWorkflowException {
0673: setActivityInstance((ActivityInstanceBean) getRequestMap().get(
0674: "actInst"));
0675: // setActivityInstance(getActivityInstance());
0676: if (_logger.isDebugEnabled())
0677: _logger.debug(this + ".showSelectedActivityInstance()");
0678: return "activityInstance";
0679: }
0680:
0681: public String showSelectedWorkItem() throws WMWorkflowException {
0682: setWorkItem((WorkItemBean) getRequestMap().get("workItem"));
0683: // setWorkItem(getWorkItem());
0684: if (_logger.isDebugEnabled())
0685: _logger.debug(this + ".showSelectedWorkItem()");
0686: return "workItem";
0687: }
0688:
0689: public String showSelectedAuditEntry() throws WMWorkflowException {
0690: setAuditEntry((WMAAuditEntry) getRequestMap().get("auditEntry"));
0691: if (_logger.isDebugEnabled())
0692: _logger.debug(this + ".showSelectedAuditEntry()");
0693: return "auditEntry";
0694: }
0695:
0696: public String showSummary() {
0697: _summary = null;
0698: if (_logger.isDebugEnabled())
0699: _logger.debug(this + ".showSummary()");
0700: return "summary";
0701: }
0702:
0703: public String showProcessDefinition() {
0704: if (_logger.isDebugEnabled())
0705: _logger.debug(this + ".showProcessDefinition()");
0706: return "processDefinition";
0707: }
0708:
0709: public String showActivityDefinition() throws WMWorkflowException {
0710: if (_logger.isDebugEnabled())
0711: _logger.debug(this + ".showActivityDefinition()");
0712: return "activityDefinition";
0713: }
0714:
0715: public String showProcessInstances() {
0716: if (_logger.isDebugEnabled())
0717: _logger.debug(this + ".showProcessInstances()");
0718: return "processInstances";
0719: }
0720:
0721: public String showProcessInstance() throws WMWorkflowException {
0722: if (_logger.isDebugEnabled())
0723: _logger.debug(this + ".showProcessInstance()");
0724: return getProcessInstance().getState() == WMProcessInstanceState.OPEN_NOTRUNNING_NOTSTARTED ? "newProcessInstance"
0725: : "processInstance";
0726: }
0727:
0728: public String showParentProcessInstance() {
0729: setProcessInstanceId(_parentProcInstId);
0730: if (_logger.isDebugEnabled())
0731: _logger.debug(this + ".showParentProcessInstance()");
0732: return "processInstance";
0733: }
0734:
0735: public String showActivityInstances() throws WMWorkflowException {
0736: if (_logger.isDebugEnabled())
0737: _logger.debug(this + ".showActivityInstances()");
0738: return "activityInstances";
0739: }
0740:
0741: public String showActivityInstance() throws WMWorkflowException {
0742: if (_logger.isDebugEnabled())
0743: _logger.debug(this + ".showActivityInstance()");
0744: return "activityInstance";
0745: }
0746:
0747: public String showParentActivityInstance()
0748: throws WMWorkflowException {
0749: setActivityInstanceId(_parentActInstId);
0750: if (_logger.isDebugEnabled())
0751: _logger.debug(this + ".showParentActivityInstance()");
0752: return "activityInstance";
0753: }
0754:
0755: public String showWorkItemsForProcess() {
0756: _workItemsKey = WorkItemAttributes.PROCESS_INSTANCE_ID;
0757: _workItemsValue = _procInstId;
0758: if (_logger.isDebugEnabled())
0759: _logger.debug(this + ".showWorkItemsForProcess()");
0760: return "workItems";
0761: }
0762:
0763: public String showWorkItemsForActivity() {
0764: _workItemsKey = WorkItemAttributes.ACTIVITY_INSTANCE_ID;
0765: _workItemsValue = _actInstId;
0766: if (_logger.isDebugEnabled())
0767: _logger.debug(this + ".showWorkItemsForActivity()");
0768: return "workItems";
0769: }
0770:
0771: public String showWorkItem() throws WMWorkflowException {
0772: if (_logger.isDebugEnabled())
0773: _logger.debug(this + ".showWorkItem()");
0774: return "workItem";
0775: }
0776:
0777: public String showAuditEntriesForProcess() {
0778: _auditEntriesKey = "currentProcessInstanceId";
0779: _auditEntriesValue = _procInstId;
0780: if (_logger.isDebugEnabled())
0781: _logger.debug(this + ".showAuditEntriesForProcess()");
0782: return "auditEntries";
0783: }
0784:
0785: public String showAuditEntriesForActivity() {
0786: _auditEntriesKey = "activityInstanceId";
0787: _auditEntriesValue = _actInstId;
0788: if (_logger.isDebugEnabled())
0789: _logger.debug(this + ".showAuditEntriesForActivity()");
0790: return "auditEntries";
0791: }
0792:
0793: public String showAuditEntriesForWorkItem() {
0794: _auditEntriesKey = "workItemId";
0795: _auditEntriesValue = _workItemId;
0796: if (_logger.isDebugEnabled())
0797: _logger.debug(this + ".showAuditEntriesForWorkItem()");
0798: return "auditEntries";
0799: }
0800:
0801: public void enableProcessDefinition() throws WMWorkflowException {
0802: changeProcessDefinitionState(WMProcessDefinitionState.ENABLED,
0803: "enableProcessDefinition");
0804: }
0805:
0806: public void disableProcessDefinition() throws WMWorkflowException {
0807: changeProcessDefinitionState(WMProcessDefinitionState.DISABLED,
0808: "disableProcessDefinition");
0809: }
0810:
0811: private void changeProcessDefinitionState(
0812: WMProcessDefinitionState state, String debugMsg)
0813: throws WMWorkflowException {
0814:
0815: getClient().changeProcessDefinitionState(_procDefId, state);
0816: setProcessDefinition(null);
0817: if (_logger.isDebugEnabled())
0818: _logger.debug(this + debugMsg);
0819: }
0820:
0821: public String instantiateProcess() throws WMWorkflowException {
0822: String procInstId = getClient().createProcessInstance(
0823: _procDefId, null);
0824: setProcessInstanceId(procInstId);
0825: if (_logger.isDebugEnabled())
0826: _logger.debug(this + ".instantiateProcess()");
0827: return "newProcessInstance";
0828: }
0829:
0830: public String saveProcessWithParameters() throws IOException,
0831: WMWorkflowException {
0832:
0833: if (_logger.isDebugEnabled())
0834: _logger.debug(this + ".saveProcessWithParameters()");
0835: saveProcessParameters();
0836: return "newProcessInstance";
0837: }
0838:
0839: public String startProcessWithParameters() throws IOException,
0840: WMWorkflowException {
0841:
0842: if (_logger.isDebugEnabled())
0843: _logger.debug(this + ".startProcessWithParameters()");
0844: saveProcessParameters();
0845: getClient().startProcess(_procInstId);
0846: setProcessInstance(null);
0847: return "processInstance";
0848: }
0849:
0850: private void saveProcessParameters() throws WMWorkflowException {
0851: // getClient().assignProcessInstanceAttribute(_procInstId,
0852: // ProcessInstanceAttributes.NAME, getProcessInstance().getName());
0853: List actualParms = getActualParameters();
0854: for (int i = 0, n = actualParms.size(); i < n; i++) {
0855: AttributeBean attr = (AttributeBean) actualParms.get(i);
0856: if (attr.getType().getImpliedType().value() == Type.SCHEMA_TYPE
0857: && attr.getValue() != null) {
0858:
0859: try {
0860: attr.setValue(((UploadedFile) attr.getValue())
0861: .getBytes());
0862: } catch (IOException e) {
0863: throw new WMWorkflowException(e);
0864: }
0865: }
0866: getClient().assignProcessInstanceAttribute(_procInstId,
0867: attr.getId(), attr.getValue());
0868: }
0869: }
0870:
0871: private String changeProcessInstanceState(
0872: WMProcessInstanceState state, String debugMsg)
0873: throws WMWorkflowException {
0874:
0875: getClient().changeProcessInstanceState(_procInstId, state);
0876: clearObjects();
0877: if (_logger.isDebugEnabled())
0878: _logger.debug(this + debugMsg);
0879: return null;
0880: }
0881:
0882: private String changeActivityInstanceState(
0883: WMActivityInstanceState state, String debugMsg)
0884: throws WMWorkflowException {
0885:
0886: getClient().changeActivityInstanceState(_procInstId,
0887: _actInstId, state);
0888: clearObjects();
0889: if (_logger.isDebugEnabled())
0890: _logger.debug(this + debugMsg);
0891: return null;
0892: }
0893:
0894: private String changeWorkItemState(WMWorkItemState state,
0895: String debugMsg) throws WMWorkflowException {
0896:
0897: getClient()
0898: .changeWorkItemState(_procInstId, _workItemId, state);
0899: clearObjects();
0900: if (_logger.isDebugEnabled())
0901: _logger.debug(this + debugMsg);
0902: return null;
0903: }
0904:
0905: public String startProcessInstance() throws WMWorkflowException {
0906: return changeProcessInstanceState(
0907: WMProcessInstanceState.OPEN_RUNNING,
0908: ".startProcessInstance()");
0909: }
0910:
0911: public String suspendProcessInstance() throws WMWorkflowException {
0912: return changeProcessInstanceState(
0913: WMProcessInstanceState.OPEN_NOTRUNNING_SUSPENDED,
0914: ".suspendProcessInstance()");
0915: }
0916:
0917: public String resumeProcessInstance() throws WMWorkflowException {
0918: return changeProcessInstanceState(
0919: WMProcessInstanceState.OPEN_RUNNING,
0920: ".resumeProcessInstance()");
0921: }
0922:
0923: public String terminateProcessInstance() throws WMWorkflowException {
0924: return changeProcessInstanceState(
0925: WMProcessInstanceState.CLOSED_TERMINATED,
0926: ".terminateProcessInstance()");
0927: }
0928:
0929: public String abortProcessInstance() throws WMWorkflowException {
0930: return changeProcessInstanceState(
0931: WMProcessInstanceState.CLOSED_ABORTED,
0932: ".abortProcessInstance");
0933: }
0934:
0935: public String startActivity() throws WMWorkflowException {
0936: return changeActivityInstanceState(
0937: WMActivityInstanceState.OPEN_RUNNING,
0938: ".startActivity()");
0939: }
0940:
0941: public String completeActivity() throws WMWorkflowException {
0942: return changeActivityInstanceState(
0943: WMActivityInstanceState.CLOSED_COMPLETED,
0944: ".completeActivity()");
0945: }
0946:
0947: public String suspendActivity() throws WMWorkflowException {
0948: return changeActivityInstanceState(
0949: WMActivityInstanceState.OPEN_SUSPENDED,
0950: ".suspendActivity()");
0951: }
0952:
0953: public String resumeActivity() throws WMWorkflowException {
0954: return changeActivityInstanceState(
0955: WMActivityInstanceState.OPEN_RUNNING,
0956: ".resumeActivity()");
0957: }
0958:
0959: public String terminateActivity() throws WMWorkflowException {
0960: return changeActivityInstanceState(
0961: WMActivityInstanceState.CLOSED_TERMINATED,
0962: ".terminateActivity()");
0963: }
0964:
0965: public String abortActivity() throws WMWorkflowException {
0966: return changeActivityInstanceState(
0967: WMActivityInstanceState.CLOSED_ABORTED,
0968: ".abortActivity()");
0969: }
0970:
0971: public String startWorkItem() throws WMWorkflowException {
0972: return changeWorkItemState(WMWorkItemState.OPEN_RUNNING,
0973: ".startWorkItem()");
0974: }
0975:
0976: public String completeWorkItem() throws WMWorkflowException {
0977: return changeWorkItemState(WMWorkItemState.CLOSED_COMPLETED,
0978: ".completeWorkItem()");
0979: }
0980:
0981: public String suspendWorkItem() throws WMWorkflowException {
0982: return changeWorkItemState(WMWorkItemState.OPEN_SUSPENDED,
0983: ".suspendWorkItem()");
0984: }
0985:
0986: public String resumeWorkItem() throws WMWorkflowException {
0987: return changeWorkItemState(WMWorkItemState.OPEN_RUNNING,
0988: ".resumeWorkItem()");
0989: }
0990:
0991: public String terminateWorkItem() throws WMWorkflowException {
0992: return changeWorkItemState(WMWorkItemState.CLOSED_TERMINATED,
0993: ".terminateWorkItem()");
0994: }
0995:
0996: public String abortWorkItem() throws WMWorkflowException {
0997: return changeWorkItemState(WMWorkItemState.CLOSED_ABORTED,
0998: ".abortWorkItem()");
0999: }
1000:
1001: public String executeWorkItem() throws WMWorkflowException {
1002: if (_logger.isDebugEnabled())
1003: _logger.debug(this + ".executeWorkItem()");
1004: _parms.clear();
1005: _workItemToExecute = getWorkItem();
1006: setWorkItem(null);
1007: return null;
1008: }
1009:
1010: public String reassignWorkItem() throws WMWorkflowException {
1011: getClient().reassignWorkItem(
1012: _workItem.getParticipant().getName(), getParticipant(),
1013: _procInstId, _workItemId);
1014: setWorkItem(null);
1015: if (_logger.isDebugEnabled())
1016: _logger.debug(this + ".reassignWorkItem()");
1017: return null;
1018: }
1019:
1020: public Parameter[] getToolInvocationParameters() {
1021: Map parms = getExternalContext().getRequestParameterMap();
1022: String workItemId = (String) parms
1023: .get("updProcAttrs:workItemId");
1024: String toolIndex = (String) parms.get("updProcAttrs:toolIndex");
1025: String key = workItemId + '-' + toolIndex;
1026: return (Parameter[]) _parms.get(key);
1027: }
1028:
1029: public String getToolIndex() {
1030: Map parms = getExternalContext().getRequestParameterMap();
1031: return (String) parms.get("updProcAttrs:toolIndex");
1032: }
1033:
1034: public void setToolIndex(String toolIndex) {
1035: }
1036:
1037: public String updateProcessAttributes() throws WMWorkflowException {
1038: // Retrieve the parameters using keys from the request context.
1039: Map rpm = getExternalContext().getRequestParameterMap();
1040: String procInstId = (String) rpm.get("updProcAttrs:procInstId");
1041: String workItemId = (String) rpm.get("updProcAttrs:workItemId");
1042: String toolIndex = (String) rpm.get("updProcAttrs:toolIndex");
1043: String key = workItemId + '-' + toolIndex;
1044: Parameter[] parms = (Parameter[]) _parms.remove(key);
1045:
1046: // Convert any uploaded files into byte arrays.
1047: for (int i = 0; i < parms.length; i++) {
1048: Parameter parm = parms[i];
1049: if (parm.getDataType().getType().getImpliedType().value() == Type.SCHEMA_TYPE
1050: && parm.getValue() != null) {
1051:
1052: try {
1053: parm.setValue(((UploadedFile) parm.getValue())
1054: .getBytes());
1055: } catch (IOException e) {
1056: throw new WMWorkflowException(e);
1057: }
1058: }
1059: }
1060:
1061: // Inform the workflow engine that the tool has finished.
1062: getClient().toolFinished(procInstId, workItemId,
1063: ToolAgent.FINISHED, parms);
1064:
1065: setWorkItem(null);
1066: if (_logger.isDebugEnabled())
1067: _logger.debug(this + ".updateProcessAttributes()");
1068: return null;
1069: }
1070:
1071: public String logout() {
1072: if (_client != null) {
1073: try {
1074: _client.disconnect();
1075: } catch (Exception e) {
1076: // We don't care about exceptions on disconnect.
1077: }
1078: _client = null;
1079: }
1080: clearIds();
1081: HttpServletRequest request = (HttpServletRequest) getExternalContext()
1082: .getRequest();
1083: HttpSession session = request.getSession(false);
1084: session.invalidate();
1085: // session = request.getSession(true);
1086: if (_logger.isDebugEnabled())
1087: _logger.debug(this + ".logout()");
1088: return "logout";
1089: }
1090:
1091: private String getParticipant() {
1092: return null;
1093: }
1094:
1095: private WMClient getClient() throws WMWorkflowException {
1096: // Need to connect lazily, since the constructor may be called from an
1097: // unauthenticated context.
1098: if (_client == null) {
1099: _client = WMClientFactory
1100: .createClient(WMClientFactory.J2EE_LOCAL);
1101: try {
1102: _client.connect(null);
1103: } catch (WMWorkflowException e) {
1104: _client = null;
1105: throw e;
1106: }
1107: if (_logger.isDebugEnabled())
1108: _logger.debug(this + ".getClient()");
1109: }
1110:
1111: return _client;
1112: }
1113:
1114: public String toString() {
1115: return "WorklistController[_procDefId=" + _procDefId
1116: + ", _procInstId=" + _procInstId + ", _actDefId="
1117: + _actDefId + ", _actInstId=" + _actInstId
1118: + ", _workItemId=" + _workItemId + ']';
1119: }
1120: }
|