use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadline.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadline() 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));
Task task = (Task) TaskFactory.evalTask(reader, vars);
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);
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
for (WiserMessage msg : getWiser().getMessages()) {
logger.info(msg.getEnvelopeReceiver());
}
// 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(myBody, msg.getContent());
assertEquals(mySubject, 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.InternalContent in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() 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.start(taskId, "Administrator");
taskService.fail(taskId, "Administrator", null);
// 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.Failed, task.getTaskData().getStatus());
assertEquals(0, task.getDeadlines().getStartDeadlines().size());
assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
use of org.kie.internal.task.api.model.InternalContent 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.InternalContent in project jbpm by kiegroup.
the class MVELLifeCycleManager method taskOperation.
public void taskOperation(final Operation operation, final long taskId, final String userId, final String targetEntityId, final Map<String, Object> data, List<String> groupIds, OrganizationalEntity... entities) throws TaskException {
try {
final List<OperationCommand> commands = operations.get(operation);
Task task = persistenceContext.findTask(taskId);
if (task == null) {
String errorMessage = "Task '" + taskId + "' not found";
throw new PermissionDeniedException(errorMessage);
}
String deploymentId = (String) context.get(EnvironmentName.DEPLOYMENT_ID);
if (deploymentId != null && !deploymentId.equals(task.getTaskData().getDeploymentId())) {
throw new IllegalStateException("Task instance " + task.getId() + " is owned by another deployment expected " + task.getTaskData().getDeploymentId() + " found " + deploymentId);
}
// automatically load task variables on each operation if the event manager is activated
if (EventManagerProvider.getInstance().isActive()) {
taskContentService.loadTaskVariables(task);
}
User user = persistenceContext.findUser(userId);
OrganizationalEntity targetEntity = null;
if (targetEntityId != null && !targetEntityId.equals("")) {
targetEntity = persistenceContext.findOrgEntity(targetEntityId);
}
getExecutionErrorHandler().processing(task);
switch(operation) {
case Activate:
{
taskEventSupport.fireBeforeTaskActivated(task, context);
break;
}
case Claim:
{
taskEventSupport.fireBeforeTaskClaimed(task, context);
break;
}
case Complete:
{
taskEventSupport.fireBeforeTaskCompleted(task, context);
break;
}
case Delegate:
{
taskEventSupport.fireBeforeTaskDelegated(task, context);
break;
}
case Exit:
{
taskEventSupport.fireBeforeTaskExited(task, context);
break;
}
case Fail:
{
if (data != null) {
FaultData faultData = ContentMarshallerHelper.marshalFault(task, data, null);
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(faultData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setFaultToTask(content, faultData, task);
}
taskEventSupport.fireBeforeTaskFailed(task, context);
break;
}
case Forward:
{
taskEventSupport.fireBeforeTaskForwarded(task, context);
break;
}
case Nominate:
{
taskEventSupport.fireBeforeTaskNominated(task, context);
break;
}
case Release:
{
taskEventSupport.fireBeforeTaskReleased(task, context);
break;
}
case Resume:
{
taskEventSupport.fireBeforeTaskResumed(task, context);
break;
}
case Skip:
{
taskEventSupport.fireBeforeTaskSkipped(task, context);
break;
}
case Start:
{
taskEventSupport.fireBeforeTaskStarted(task, context);
break;
}
case Stop:
{
taskEventSupport.fireBeforeTaskStopped(task, context);
break;
}
case Suspend:
{
taskEventSupport.fireBeforeTaskSuspended(task, context);
break;
}
}
evalCommand(operation, commands, task, user, targetEntity, groupIds, entities);
persistenceContext.updateTask(task);
switch(operation) {
case Activate:
{
taskEventSupport.fireAfterTaskActivated(task, context);
break;
}
case Claim:
{
taskEventSupport.fireAfterTaskClaimed(task, context);
break;
}
case Complete:
{
if (data != null) {
taskContentService.addOutputContent(taskId, data);
}
taskEventSupport.fireAfterTaskCompleted(task, context);
break;
}
case Delegate:
{
// This is a really bad hack to execut the correct behavior
((InternalTaskData) task.getTaskData()).setStatus(Status.Reserved);
taskEventSupport.fireAfterTaskDelegated(task, context);
break;
}
case Exit:
{
taskEventSupport.fireAfterTaskExited(task, context);
break;
}
case Fail:
{
taskEventSupport.fireAfterTaskFailed(task, context);
break;
}
case Forward:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskForwarded(task, context);
break;
}
case Nominate:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskNominated(task, context);
break;
}
case Release:
{
invokeAssignmentService(task, context, userId);
taskEventSupport.fireAfterTaskReleased(task, context);
break;
}
case Resume:
{
taskEventSupport.fireAfterTaskResumed(task, context);
break;
}
case Start:
{
taskEventSupport.fireAfterTaskStarted(task, context);
break;
}
case Skip:
{
taskEventSupport.fireAfterTaskSkipped(task, context);
break;
}
case Stop:
{
taskEventSupport.fireAfterTaskStopped(task, context);
break;
}
case Suspend:
{
taskEventSupport.fireAfterTaskSuspended(task, context);
break;
}
}
getExecutionErrorHandler().processed(task);
} catch (RuntimeException re) {
throw re;
}
}
use of org.kie.internal.task.api.model.InternalContent 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();
}
Aggregations