use of org.kie.internal.task.api.model.FaultData in project jbpm by kiegroup.
the class LifeCycleBaseTest method testFailWithContent.
@Test
public void testFailWithContent() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Go straight from Ready to Inprogress
taskService.start(taskId, "Darth Vader");
taskService.getTaskById(taskId);
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
Map<String, Object> faultData = new HashMap<String, Object>();
faultData.put("faultType", "type");
faultData.put("faultName", "faultName");
faultData.put("content", "content");
taskService.fail(taskId, "Darth Vader", faultData);
List<Content> allContent = taskService.getAllContentByTaskId(taskId);
assertNotNull(allContent);
assertEquals(3, allContent.size());
// only input(0) and fault(2) is present
assertNotNull(allContent.get(0));
assertNull(allContent.get(1));
assertNotNull(allContent.get(2));
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Failed, task2.getTaskData().getStatus());
assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getFaultAccessType());
assertEquals("type", task2.getTaskData().getFaultType());
assertEquals("faultName", task2.getTaskData().getFaultName());
long contentId = task2.getTaskData().getFaultContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Map<String, Object> unmarshalledContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("content", unmarshalledContent.get("content"));
xmlRoundTripContent(content);
// update fault
FaultData data = TaskModelProvider.getFactory().newFaultData();
data.setAccessType(AccessType.Inline);
data.setType("type");
data.setFaultName("faultName");
data.setContent("updated content".getBytes());
taskService.setFault(taskId, "Darth Vader", data);
task = taskService.getTaskById(taskId);
contentId = task.getTaskData().getFaultContentId();
content = taskService.getContentById(contentId);
String updated = new String(content.getContent());
assertEquals("updated content", updated);
// delete fault
taskService.deleteFault(taskId, "Darth Vader");
content = taskService.getContentById(contentId);
assertNull(content);
}
use of org.kie.internal.task.api.model.FaultData in project jbpm by kiegroup.
the class ContentMarshallerHelper method marshalFault.
public static FaultData marshalFault(Task task, Map<String, Object> fault, Environment env) {
FaultData content = null;
byte[] toByteArray = marshallContent(task, fault, env);
content = TaskModelProvider.getFactory().newFaultData();
content.setContent(toByteArray);
content.setType(fault.getClass().getCanonicalName());
content.setAccessType(AccessType.Inline);
content.setFaultName((String) fault.get("faultName"));
content.setType((String) fault.get("faultType"));
return content;
}
use of org.kie.internal.task.api.model.FaultData 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.FaultData in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method deleteFault.
public void deleteFault(long taskId, String userId) {
Task task = persistenceContext.findTask(taskId);
long contentId = task.getTaskData().getFaultContentId();
Content content = persistenceContext.findContent(contentId);
FaultData data = TaskModelProvider.getFactory().newFaultData();
persistenceContext.removeContent(content);
persistenceContext.setFaultToTask(null, data, task);
}
Aggregations