use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskSkipped.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskSkipped() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
((InternalTaskData) task.getTaskData()).setSkipable(true);
InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Administrator");
ba.add(user);
assignments.setBusinessAdministrators(ba);
List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
User user2 = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user2).setId("Administrator");
po.add(user2);
assignments.setPotentialOwners(po);
task.setPeopleAssignments(assignments);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
Map<String, String> params = fillMarshalSubjectAndBodyParams();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
content.setContent(marshalledObject.getContent());
taskService.addContent(taskId, content);
long contentId = content.getId();
content = (InternalContent) taskService.getContentById(contentId);
Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
checkContentSubjectAndBody(unmarshallObject);
taskService.skip(taskId, "Administrator");
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// no email should ne sent as task was completed before deadline was triggered
assertEquals(0, getWiser().getMessages().size());
task = (InternalTask) taskService.getTaskById(taskId);
assertEquals(Status.Obsolete, task.getTaskData().getStatus());
assertEquals(0, task.getDeadlines().getStartDeadlines().size());
assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class TaskContentServiceImpl method addOutputContent.
@SuppressWarnings("unchecked")
public long addOutputContent(long taskId, Map<String, Object> params) {
Task task = persistenceContext.findTask(taskId);
loadTaskVariables(task);
long outputContentId = task.getTaskData().getOutputContentId();
Content outputContent = persistenceContext.findContent(outputContentId);
Map<String, Object> initialContent = new HashMap<>();
long contentId = -1;
if (outputContent == null) {
ContentMarshallerContext context = getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, params, context.getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(outputContentData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setOutputToTask(content, outputContentData, task);
contentId = content.getId();
} else {
// I need to merge it if it already exist
ContentMarshallerContext context = getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), context.getEnvironment(), context.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content before updating with this params
initialContent.putAll((Map<String, Object>) unmarshalledObject);
((Map<String, Object>) unmarshalledObject).putAll(params);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, context.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
contentId = outputContentId;
}
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(params);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, params);
persistenceContext.updateTask(task);
return contentId;
}
use of org.kie.internal.task.api.model.ContentData 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());
}
}
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class AddTaskInputsCommand method execute.
@SuppressWarnings("unchecked")
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
Task task = persistenceContext.findTask(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
long inputContentId = task.getTaskData().getDocumentContentId();
Content outputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> initialContent = new HashMap<String, Object>();
Map<String, Object> mergedContent = values;
if (outputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, values, mcontext.getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(outputContentData.getContent());
persistenceContext.persistContent(content);
((InternalTaskData) task.getTaskData()).setOutput(content.getId(), outputContentData);
} else {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content with data from storage before being altered by this values
initialContent.putAll((Map<String, Object>) unmarshalledObject);
((Map<String, Object>) unmarshalledObject).putAll(values);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
return null;
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class AbstractHTWorkItemHandler method createTaskContentBasedOnWorkItemParams.
protected ContentData createTaskContentBasedOnWorkItemParams(KieSession session, WorkItem workItem) {
ContentData content = null;
Object contentObject = workItem.getParameter("Content");
if (contentObject == null) {
contentObject = new HashMap<String, Object>(workItem.getParameters());
}
if (contentObject != null) {
Environment env = null;
if (session != null) {
env = session.getEnvironment();
}
content = ContentMarshallerHelper.marshal(null, contentObject, env);
}
return content;
}
Aggregations