List<GenericValue> tools = null;
String allParams = "";
try {
tools = getActivity().getDefinitionObject().getRelated("WorkflowActivityTool");
} catch (GenericEntityException e) {
throw new WfException(e.getMessage(), e);
}
if (tools == null) {
setComplete(true);
return; // Null tools mean nothing to do (same as route?)
}
if (Debug.verboseOn())
Debug.logVerbose("[WfActivity.runTool] : Running tools (" + tools.size() + ").", module);
List<GenericResultWaiter> waiters = new ArrayList<GenericResultWaiter>();
for (GenericValue thisTool : tools) {
String serviceName = null;
String toolId = thisTool.getString("toolId");
String params = thisTool.getString("actualParameters");
String toolTypeEnumId = thisTool.getString("toolTypeEnumId");
allParams = allParams + "," + params;
String extend = thisTool.getString("extendedAttributes");
Map<String, String> extendedAttr = StringUtil.strToMap(extend);
if (extendedAttr != null && extendedAttr.containsKey("serviceName")) {
serviceName = extendedAttr.get("serviceName");
}
serviceName = serviceName != null ? serviceName : (toolTypeEnumId.equals("WTT_APPLICATION") ? "wfActivateApplication" : toolId);
waiters.add(runService(serviceName, params, extend));
}
while (waiters.size() > 0) {
List<GenericResultWaiter> remove = new ArrayList<GenericResultWaiter>();
for (GenericResultWaiter thw : waiters) {
if (thw.isCompleted()) {
Map<String, Object> thwResult = null;
if (thw.status() == GenericResultWaiter.SERVICE_FINISHED) {
thwResult = thw.getResult();
Debug.logVerbose("Service finished.", module);
} else if (thw.status() == GenericResultWaiter.SERVICE_FAILED) {
Debug.logError(thw.getThrowable(), "Service failed", module);
}
if (thwResult != null && thwResult.containsKey(ModelService.RESPONSE_MESSAGE)) {
if (thwResult.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) {
String errorMsg = (String) thwResult.remove(ModelService.ERROR_MESSAGE);
Debug.logError("Service Error: " + errorMsg, module);
}
thwResult.remove(ModelService.RESPONSE_MESSAGE);
}
try {
if (thwResult != null)
this.setResult(thwResult, allParams);
} catch (IllegalStateException e) {
throw new WfException("Unknown error", e);
}
remove.add(thw);
}
}
waiters.removeAll(remove);