📄 wfactivityimpl.java
字号:
validStatus = UtilMisc.toList("CAL_COMPLETED", "CAL_DELEGATED");
else
throw new WfException("Invalid status type");
boolean foundOne = false;
List assignList = this.getAllAssignments();
Iterator i = assignList.iterator();
while (i.hasNext()) {
GenericValue value = (GenericValue) i.next();
String party = value.getString("partyId");
String role = value.getString("roleTypeId");
String status = value.getString("statusId");
java.sql.Timestamp from = value.getTimestamp("fromDate");
WfAssignment a = WfFactory.getWfAssignment(getDelegator(), runtimeKey(), party, role, from);
if (validStatus.contains(a.status())) {
// if we find one set this to true
foundOne = true;
} else {
// if we must completeAll / assignAll and this one fails return false
if ((type == CHECK_COMPLETE && completeAll) || (type == CHECK_ASSIGN && acceptAll))
return false;
}
}
// we are here only if all are done, or complete/assign is false; so if not false we are done
if ((type == CHECK_COMPLETE && completeAll) || (type == CHECK_ASSIGN && acceptAll)) {
return true;
} else {
// if not all done, we don't require all, so use that foundOne stored above
Debug.logVerbose("[checkAssignStatus] : need only one assignment to pass", module);
if (foundOne)
return true;
Debug.logVerbose("[checkAssignStatus] : found no assignment(s)", module);
return false;
}
}
// Starts or activates this automatic activity
private void startActivity() throws WfException, CannotStart {
try {
changeState("open.running");
} catch (InvalidState is) {
throw new CannotStart(is.getMessage(), is);
} catch (TransitionNotAllowed tna) {
throw new CannotStart(tna.getMessage(), tna);
}
// check the limit service
boolean limitAfterStart = getDefinitionObject().getBoolean("limitAfterStart").booleanValue();
if (limitAfterStart
&& getDefinitionObject().get("limitService") != null
&& !getDefinitionObject().getString("limitService").equals("")) {
Debug.logVerbose("[WfActivity.init]: limit service is after start, setting up now.", module);
setLimitService();
}
// set the new previousActivity
Map context = processContext();
context.put("previousActivity", workEffortId);
this.setProcessContext(context);
// set the actualStartDate
try {
GenericValue v = getRuntimeObject();
v.set("actualStartDate", UtilDateTime.nowTimestamp());
v.store();
} catch (GenericEntityException e) {
Debug.logWarning("Could not set 'actualStartDate'.", module);
e.printStackTrace();
}
// get the type of this activity
String type = getDefinitionObject().getString("activityTypeEnumId");
if (type == null)
throw new WfException("Illegal activity type");
WfActivityAbstractImplementation executor = WfActivityImplementationFact.getConcretImplementation(type, this);
executor.run();
this.setResult(executor.getResult());
if (executor.isComplete())
this.checkComplete();
}
// schedule the limit service to run
private void setLimitService() throws WfException {
LocalDispatcher dispatcher = getDispatcher();
DispatchContext dctx = dispatcher.getDispatchContext();
String limitService = getDefinitionObject().getString("limitService");
ModelService service = null;
try {
service = dctx.getModelService(limitService);
Debug.logVerbose("[WfActivity.setLimitService] : Found service model.", module);
} catch (GenericServiceException e) {
Debug.logError(e, "[WfActivity.setLimitService] : Cannot get service model.", module);
}
if (service == null) {
Debug.logWarning("[WfActivity.setLimitService] : Cannot determine limit service, ignoring.", module);
return;
}
// make the limit service context
List inList = new ArrayList(service.getInParamNames());
String inParams = StringUtil.join(inList, ",");
Map serviceContext = actualContext(inParams, null, null, true);
Debug.logVerbose("Setting limit service with context: " + serviceContext, module);
Double timeLimit = null;
if (getDefinitionObject().get("timeLimit") != null)
timeLimit = getDefinitionObject().getDouble("timeLimit");
if (timeLimit == null)
return;
String durationUOM = null;
if (container().getDefinitionObject().getString("durationUomId") != null)
durationUOM = container().getDefinitionObject().getString("durationUomId");
if (durationUOM == null)
return;
char durChar = durationUOM.charAt(0);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
switch (durChar) {
case 'Y' :
cal.add(Calendar.YEAR, timeLimit.intValue());
break;
case 'M' :
cal.add(Calendar.MONTH, timeLimit.intValue());
break;
case 'D' :
cal.add(Calendar.DATE, timeLimit.intValue());
break;
case 'h' :
cal.add(Calendar.HOUR, timeLimit.intValue());
break;
case 'm' :
cal.add(Calendar.MINUTE, timeLimit.intValue());
break;
case 's' :
cal.add(Calendar.SECOND, timeLimit.intValue());
break;
default :
throw new WfException("Invalid duration unit");
}
long startTime = cal.getTime().getTime();
Map context = new HashMap();
context.put("serviceName", limitService);
context.put("serviceContext", serviceContext);
context.put("workEffortId", runtimeKey());
try {
dispatcher.schedule("wfLimitInvoker", context, startTime); // yes we are hard coded!
} catch (GenericServiceException e) {
throw new WfException(e.getMessage(), e);
}
if (Debug.verboseOn()) {
Debug.logVerbose("[WfActivity.setLimitService]: Set limit service (" + limitService + " ) to run at " + startTime, module);
}
}
Map actualContext(String actualParameters, String extendedAttr, List serviceSignature, boolean ignoreUnknown) throws WfException {
Map actualContext = new HashMap();
Map context = processContext();
// extended attributes take priority over context attributes
Map extendedAttributes = StringUtil.strToMap(extendedAttr);
if (extendedAttributes != null && extendedAttributes.size() > 0) {
context.putAll(extendedAttributes);
}
// setup some internal buffer parameters
GenericValue userLogin = null;
if (context.containsKey("runAsUser")) {
userLogin = getUserLogin((String) context.get("runAsUser"));
actualContext.put("userLogin", userLogin);
} else if (context.containsKey("workflowOwnerId")) {
userLogin = getUserLogin((String) context.get("workflowOwnerId"));
}
// some static context values
context.put("userLogin", userLogin);
context.put("workEffortId", runtimeKey());
if (howManyAssignment() == 1) {
Debug.logVerbose("Single assignment; getting assignment info.", module);
List assignments = getAssignments();
WfAssignment assign = (WfAssignment) assignments.iterator().next();
WfResource res = assign.assignee();
context.put("assignedPartyId", res.resourcePartyId());
context.put("assignedRoleTypeId", res.resourceRoleId());
}
// first we will pull out the values from the context for the actual parameters
if (actualParameters != null) {
List params = StringUtil.split(actualParameters, ",");
Iterator i = params.iterator();
while (i.hasNext()) {
Object key = i.next();
String keyStr = (String) key;
if (keyStr != null && keyStr.trim().toLowerCase().startsWith("expr:")) {
// check for bsh expressions; this does not place values into the context
try {
BshUtil.eval(keyStr.trim().substring(5).trim(), context);
} catch (bsh.EvalError e) {
throw new WfException("Bsh evaluation error.", e);
}
} else if (keyStr != null && keyStr.trim().toLowerCase().startsWith("name:")) {
// name mapping of context values
List couple = StringUtil.split(keyStr.trim().substring(5).trim(), "=");
String mName = (String) couple.get(0); // mapped name
String cName = (String) couple.get(1); // context name
// trim out blank space
if (mName != null) mName = mName.trim();
if (cName != null) cName = cName.trim();
if (mName != null && cName != null && context.containsKey(cName)) {
actualContext.put(mName, context.get(cName));
}
} else if (context.containsKey(key)) {
// direct assignment from context
actualContext.put(key, context.get(key));
} else if (!actualContext.containsKey(key) && !ignoreUnknown) {
throw new WfException("Context does not contain the key: '" + (String) key + "'");
}
}
}
// the serviceSignature should not limit which parameters are in the actualContext
// so instead we will use this signature to pull out values so they do not all have to be defined
if (serviceSignature != null) {
Iterator si = serviceSignature.iterator();
while (si.hasNext()) {
Object key = si.next();
String keyStr = (String) key;
if (!actualContext.containsKey(key) && context.containsKey(key)) {
actualContext.put(keyStr, context.get(keyStr));
}
}
}
return actualContext;
}
// Gets a UserLogin object for service invocation
// This allows a workflow to invoke a service as a specific user
private GenericValue getUserLogin(String userId) throws WfException {
GenericValue userLogin = null;
try {
userLogin = getDelegator().findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userId));
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
return userLogin;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -