use of org.kie.api.task.model.Content 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.api.task.model.Content in project jbpm by kiegroup.
the class ParentChildMarshallingJpaTest method testProcess.
@Test
public void testProcess() throws Exception {
emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
Application application = new Application();
application.setType("A");
params.put("application", application);
ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
System.out.println("A process instance started : pid = " + pi.getId());
TaskService taskService = runtime.getTaskService();
assertTrue(taskService instanceof CommandBasedTaskService);
assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("john starts a task : taskId = " + taskSummary.getId());
Task task = taskService.getTaskById(taskSummary.getId());
long documentContentId = task.getTaskData().getDocumentContentId();
Content content = taskService.getContentById(documentContentId);
HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
Application outputApplication = (Application) contents.get("input1_application");
Person person = new Person();
person.setFullName("John Doe");
outputApplication.setPerson(person);
Map<String, Object> results = new LinkedHashMap<String, Object>();
results.put("output1_application", outputApplication);
taskService.start(taskSummary.getId(), "john");
taskService.complete(taskSummary.getId(), "john", results);
}
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
for (TaskSummary taskSummary : list) {
System.out.println("mary starts a task : taskId = " + taskSummary.getId());
taskService.start(taskSummary.getId(), "mary");
taskService.complete(taskSummary.getId(), "mary", null);
}
manager.disposeRuntimeEngine(runtime);
// Check!
EntityManager em = emfDomain.createEntityManager();
int size = em.createQuery("select i from Person i").getResultList().size();
assertEquals(1, size);
}
use of org.kie.api.task.model.Content 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);
}
use of org.kie.api.task.model.Content 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.api.task.model.Content in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method getContentMapForUser.
@Override
public Map<String, Object> getContentMapForUser(Long taskId, String userId) {
// check permissions
this.lifeCycleManager.taskOperation(Operation.View, taskId, userId, null, null, toGroups(null));
Task task = this.persistenceContext.findTask(taskId);
if (task.getTaskData() != null && task.getTaskData().getOutputContentId() != null) {
Content content = this.persistenceContext.findContent(task.getTaskData().getOutputContentId());
ContentMarshallerContext mContext = TaskContentRegistry.get().getMarshallerContext(task);
Object outputContent = ContentMarshallerHelper.unmarshall(content.getContent(), mContext.getEnvironment(), mContext.getClassloader());
if (outputContent instanceof Map) {
return (Map<String, Object>) outputContent;
} else {
throw new IllegalStateException("Output content for task " + taskId + " is not a Map<String, Object>!");
}
}
return null;
}
Aggregations