1 25 package org.ofbiz.workflow; 26 27 import java.sql.Timestamp ; 28 import java.util.Date ; 29 30 import org.ofbiz.base.util.cache.UtilCache; 31 import org.ofbiz.entity.GenericDelegator; 32 import org.ofbiz.entity.GenericValue; 33 import org.ofbiz.service.DispatchContext; 34 import org.ofbiz.workflow.client.WorkflowClient; 35 import org.ofbiz.workflow.impl.WfActivityImpl; 36 import org.ofbiz.workflow.impl.WfAssignmentImpl; 37 import org.ofbiz.workflow.impl.WfEventAuditImpl; 38 import org.ofbiz.workflow.impl.WfProcessImpl; 39 import org.ofbiz.workflow.impl.WfProcessMgrImpl; 40 import org.ofbiz.workflow.impl.WfRequesterImpl; 41 import org.ofbiz.workflow.impl.WfResourceImpl; 42 43 50 public class WfFactory { 51 52 public static final String module = WfFactory.class.getName(); 53 54 protected static UtilCache wfProcessMgrCache = new UtilCache("workflow.processmgr"); 55 protected static UtilCache wfClientCache = new UtilCache("workflow.client"); 56 57 64 public static WfActivity getWfActivity(GenericValue value, String process) throws WfException { 65 if (value == null) throw new WfException("Activity definition value object cannot be null"); 66 if (process == null) throw new WfException("Parent process WorkEffort key cannot be null"); 67 return new WfActivityImpl(value, process); 68 } 69 70 public static WfActivity getWfActivity(GenericDelegator delegator, String workEffortId) throws WfException { 71 if (delegator == null) throw new WfException("The delegator object cannot be null"); 72 if (workEffortId == null) throw new WfException("The WorkEffort key cannot be null"); 73 return new WfActivityImpl(delegator, workEffortId); 74 } 75 76 81 public static WfAssignment getWfAssignment(WfActivity activity, WfResource resource, Timestamp fromDate, boolean create) throws WfException { 82 if (activity == null) throw new WfException("WfActivity cannot be null"); 83 if (resource == null) throw new WfException("WfResource cannot be null"); 84 if (fromDate == null) fromDate = new Timestamp (new Date ().getTime()); 85 return new WfAssignmentImpl(activity, resource, fromDate, create); 86 } 87 88 public static WfAssignment getWfAssignment(GenericDelegator delegator, String work, String party, String role, Timestamp from) throws WfException { 89 WfActivity act = getWfActivity(delegator, work); 90 WfResource res = getWfResource(delegator, null, null, party, role); 91 return getWfAssignment(act, res, from, false); 92 } 93 94 101 public static WfProcess getWfProcess(GenericValue value, WfProcessMgr mgr) throws WfException { 102 if (value == null) throw new WfException("Process definition value object cannot be null"); 103 if (mgr == null) throw new WfException("WfProcessMgr cannot be null"); 104 return new WfProcessImpl(value, mgr); 105 } 106 107 public static WfProcess getWfProcess(GenericDelegator delegator, String workEffortId) throws WfException { 108 if (delegator == null) throw new WfException("The delegator object cannot be null"); 109 if (workEffortId == null) throw new WfException("The WorkEffort key cannot be null"); 110 WfProcess process = null; 111 try { 112 process = new WfProcessImpl(delegator, workEffortId); 113 } catch (WfException e) { 114 try { 115 WfActivity act = WfFactory.getWfActivity(delegator, workEffortId); 116 if (act != null) { 117 process = act.container(); 118 } else { 119 throw e; 120 } 121 } catch (WfException e2) { 122 throw e; 123 } 124 if (process == null) { 125 throw e; 126 } 127 } 128 if (process == null) { 129 throw new WfException("No process object found"); 130 } 131 return process; 132 } 133 134 144 public static WfProcessMgr getWfProcessMgr(GenericDelegator delegator, String pkg, String pkver, String pid, String pver) throws WfException { 145 if (delegator == null) throw new WfException("Delegator cannot be null"); 146 if (pkg == null) throw new WfException("Workflow package id cannot be null."); 147 if (pid == null) throw new WfException("Workflow process id cannot be null"); 148 149 String key = delegator.getDelegatorName() + ":" + pkg + ":" + pkver + ":" + pid + ":" + pver; 150 if (!wfProcessMgrCache.containsKey(key)) { 151 synchronized (WfFactory.class) { 152 if (!wfProcessMgrCache.containsKey(key)) { 153 wfProcessMgrCache.put(key, new WfProcessMgrImpl(delegator, pkg, pkver, pid, pver)); 154 } 155 } 156 } 157 return (WfProcessMgr) wfProcessMgrCache.get(key); 158 } 159 160 165 public static WfRequester getWfRequester() throws WfException { 166 return new WfRequesterImpl(); 167 } 168 169 175 public static WfResource getWfResource(GenericValue value) throws WfException { 176 if (value == null) throw new WfException("Value object for WfResource definition cannot be null"); 177 return new WfResourceImpl(value); 178 } 179 180 190 public static WfResource getWfResource(GenericDelegator delegator, String key, String name, String party, String role) throws WfException { 191 if (delegator == null) throw new WfException("Delegator cannot be null"); 192 if (party == null) party = "_NA_"; 193 if (role == null) role = "_NA_"; 194 return new WfResourceImpl(delegator, key, name, party, role); 195 } 196 197 202 public static WfEventAudit getWfEventAudit(WfExecutionObject object, String type) throws WfException { 203 return new WfEventAuditImpl(object, type); 204 } 205 206 public static WorkflowClient getClient(DispatchContext dctx) { 207 if (!wfClientCache.containsKey(dctx)) { 208 synchronized (WfFactory.class) { 209 if (!wfClientCache.containsKey(dctx)) 210 wfClientCache.put(dctx, new WorkflowClient(dctx)); 211 } 212 } 213 return (WorkflowClient) wfClientCache.get(dctx); 214 } 215 216 } 217 | Popular Tags |