use of org.jbpm.services.task.rule.TaskServiceRequest in project jbpm by kiegroup.
the class TaskRuleServiceImpl method executeRules.
@Override
public void executeRules(Task task, String userId, Object params, String scope) throws TaskException {
KieBase ruleBase = ruleContextProvider.getKieBase(scope);
if (ruleBase != null) {
KieSession session = ruleBase.newKieSession();
Map<String, Object> globals = ruleContextProvider.getGlobals(scope);
if (globals != null) {
for (Map.Entry<String, Object> entry : globals.entrySet()) {
session.setGlobal(entry.getKey(), entry.getValue());
}
}
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(userId);
TaskServiceRequest request = new TaskServiceRequest(scope, user, null);
session.setGlobal("request", request);
session.insert(task);
if (params != null) {
if (params instanceof ContentData) {
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task);
params = ContentMarshallerHelper.unmarshall(((ContentData) params).getContent(), ctx.getEnvironment(), ctx.getClassloader());
}
session.insert(params);
}
session.fireAllRules();
session.dispose();
if (!request.isAllowed()) {
StringBuilder error = new StringBuilder("Cannot perform operation " + scope + " :\n");
if (request.getReasons() != null) {
for (String reason : request.getReasons()) {
error.append(reason).append('\n');
}
}
throw request.getException(error.toString());
}
}
}
Aggregations