use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineContentSingleObject.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineContentSingleObject() 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.DeadlineWithNotificationContentSingleObject));
Task task = (Task) TaskFactory.evalTask(reader, vars);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, "'singleobject'", 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);
assertEquals("'singleobject'", unmarshallObject.toString());
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// 1 email with two recipients should now exist
assertEquals(2, getWiser().getMessages().size());
List<String> list = new ArrayList<String>(2);
list.add(getWiser().getMessages().get(0).getEnvelopeReceiver());
list.add(getWiser().getMessages().get(1).getEnvelopeReceiver());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
MimeMessage msg = ((WiserMessage) getWiser().getMessages().get(0)).getMimeMessage();
assertEquals("'singleobject'", msg.getContent());
assertEquals("'singleobject'", msg.getSubject());
assertEquals("from@domain.com", ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals("replyTo@domain.com", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
final Address[] recipients = msg.getRecipients(RecipientType.TO);
assertNotNull(recipients);
assertTrue(recipients.length == 2);
list = new ArrayList<String>(2);
list.add(((InternetAddress) recipients[0]).getAddress());
list.add(((InternetAddress) recipients[1]).getAddress());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method addTask.
public long addTask(Task task, Map<String, Object> params) {
taskEventSupport.fireBeforeTaskAdded(task, context);
persistenceContext.persistTask(task);
resolveTaskDetailsForTaskProperties(task);
if (params != null) {
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, Collections.emptyMap());
resolveTaskDetails(params, task);
ContentData contentData = ContentMarshallerHelper.marshal(task, params, TaskContentRegistry.get().getMarshallerContext(task).getEnvironment());
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(contentData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setDocumentToTask(content, contentData, task);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, params);
}
taskEventSupport.fireAfterTaskAdded(task, context);
return task.getId();
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class RemoveTaskDataCommand 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 contentId = task.getTaskData().getDocumentContentId();
if (!input) {
contentId = task.getTaskData().getOutputContentId();
}
Content outputContent = persistenceContext.findContent(contentId);
Map<String, Object> initialContent = new HashMap<>();
Map<String, Object> mergedContent = new HashMap<>();
if (outputContent != null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(outputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
mergedContent.putAll(((Map<String, Object>) unmarshalledObject));
// set initial content for the sake of listeners
initialContent.putAll(mergedContent);
variableNames.forEach(name -> mergedContent.remove(name));
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, mergedContent, mcontext.getEnvironment());
((InternalContent) outputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(outputContent);
}
if (input) {
taskEventSupport.fireBeforeTaskInputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
taskEventSupport.fireAfterTaskInputVariablesChanged(task, context, mergedContent);
} else {
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, context, initialContent);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(mergedContent);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, context, mergedContent);
}
return null;
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class UpdateTaskCommand 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) && !isOwner(userId, task.getPeopleAssignments().getPotentialOwners(), task.getTaskData().getActualOwner(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin or potential owner of task " + taskId);
}
taskEventSupport.fireBeforeTaskUpdated(task, context);
// process task meta data
if (userTask.getFormName() != null) {
((InternalTask) task).setFormName(userTask.getFormName());
}
if (userTask.getName() != null) {
((InternalTask) task).setName(userTask.getName());
}
if (userTask.getDescription() != null) {
((InternalTask) task).setDescription(userTask.getDescription());
}
if (userTask.getPriority() != null) {
((InternalTask) task).setPriority(userTask.getPriority());
}
if (userTask.getDueDate() != null) {
((InternalTaskData) task.getTaskData()).setExpirationTime(userTask.getDueDate());
}
// process task inputs
long inputContentId = task.getTaskData().getDocumentContentId();
Content inputContent = persistenceContext.findContent(inputContentId);
Map<String, Object> mergedContent = inputs;
if (inputs != null) {
if (inputContent == null) {
ContentMarshallerContext mcontext = context.getTaskContentService().getMarshallerContext(task);
ContentData outputContentData = ContentMarshallerHelper.marshal(task, inputs, 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(inputContent.getContent(), mcontext.getEnvironment(), mcontext.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
((Map<String, Object>) unmarshalledObject).putAll(inputs);
mergedContent = ((Map<String, Object>) unmarshalledObject);
}
ContentData outputContentData = ContentMarshallerHelper.marshal(task, unmarshalledObject, mcontext.getEnvironment());
((InternalContent) inputContent).setContent(outputContentData.getContent());
persistenceContext.persistContent(inputContent);
}
((InternalTaskData) task.getTaskData()).setTaskInputVariables(mergedContent);
}
if (outputs != null) {
// process task outputs
context.getTaskContentService().addOutputContent(taskId, outputs);
}
persistenceContext.updateTask(task);
// finally trigger event support after the updates
taskEventSupport.fireAfterTaskUpdated(task, context);
return null;
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class NonManagedLocalHTWorkItemHandler method executeWorkItem.
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Task task = createTaskBasedOnWorkItemParams(ksession, workItem);
ContentData content = createTaskContentBasedOnWorkItemParams(ksession, workItem);
try {
long taskId = ((InternalTaskService) taskService).addTask(task, content);
if (isAutoClaim(ksession, workItem, task)) {
taskService.claim(taskId, (String) workItem.getParameter("SwimlaneActorId"));
}
} catch (Exception e) {
if (action.equals(OnErrorAction.ABORT)) {
manager.abortWorkItem(workItem.getId());
} else if (action.equals(OnErrorAction.RETHROW)) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
} else if (action.equals(OnErrorAction.LOG)) {
StringBuilder logMsg = new StringBuilder();
logMsg.append(new Date()).append(": Error when creating task on task server for work item id ").append(workItem.getId());
logMsg.append(". Error reported by task server: ").append(e.getMessage());
logger.error(logMsg.toString(), e);
}
}
}
Aggregations