use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class AddPeopleAssignmentsCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
List<OrganizationalEntity> entityList = Arrays.asList(entities);
AssignmentType assignmentType = null;
switch(type) {
case POT_OWNER:
if (removeExisting) {
task.getPeopleAssignments().getPotentialOwners().clear();
}
task.getPeopleAssignments().getPotentialOwners().addAll(entityList);
assignmentType = AssignmentType.POT_OWNER;
break;
case EXCL_OWNER:
if (removeExisting) {
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().clear();
}
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().addAll(entityList);
assignmentType = AssignmentType.EXCL_OWNER;
break;
case ADMIN:
if (removeExisting) {
task.getPeopleAssignments().getBusinessAdministrators().clear();
}
task.getPeopleAssignments().getBusinessAdministrators().addAll(entityList);
assignmentType = AssignmentType.ADMIN;
break;
default:
break;
}
taskEventSupport.fireBeforeTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
doCallbackOperationForPeopleAssignments(((InternalPeopleAssignments) task.getPeopleAssignments()), context);
taskEventSupport.fireAfterTaskAssignmentsAddedEvent(task, context, assignmentType, entityList);
return null;
}
use of org.jbpm.services.task.commands.TaskContext 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.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class RemovePeopleAssignmentsCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskEventSupport taskEventSupport = context.getTaskEventSupport();
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
// security check
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
List<OrganizationalEntity> entityList = Arrays.asList(entities);
AssignmentType assignmentType = null;
taskEventSupport.fireBeforeTaskUpdated(task, context);
switch(type) {
case POT_OWNER:
assignmentType = AssignmentType.POT_OWNER;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
task.getPeopleAssignments().getPotentialOwners().removeAll(entityList);
break;
case EXCL_OWNER:
assignmentType = AssignmentType.EXCL_OWNER;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().removeAll(entityList);
break;
case ADMIN:
assignmentType = AssignmentType.ADMIN;
taskEventSupport.fireBeforeTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
task.getPeopleAssignments().getBusinessAdministrators().removeAll(entityList);
break;
default:
break;
}
taskEventSupport.fireAfterTaskAssignmentsRemovedEvent(task, context, assignmentType, entityList);
return null;
}
use of org.jbpm.services.task.commands.TaskContext in project jbpm by kiegroup.
the class JaxbTaskSerializationTest method setTaskPropertyCommandTest.
@Test
public void setTaskPropertyCommandTest() throws Exception {
SetTaskPropertyCommand cmd;
int taskId = 1;
String userId = "user";
FaultDataImpl faultData = new FaultDataImpl();
faultData.setAccessType(AccessType.Inline);
faultData.setContent("skinned shins".getBytes());
faultData.setFaultName("Whoops!");
faultData.setType("skates");
List<I18NText> textList = new ArrayList<I18NText>();
I18NText text = new I18NTextImpl("nl-NL", "Stroopwafel!");
textList.add(text);
Object[][] testData = { { FAULT_PROPERTY, faultData }, { OUTPUT_PROPERTY, new Object() }, { PRIORITY_PROPERTY, 23 }, { TASK_NAMES_PROPERTY, textList }, { EXPIRATION_DATE_PROPERTY, new Date() }, { DESCRIPTION_PROPERTY, new ArrayList<I18NText>() }, { SKIPPABLE_PROPERTY, false }, { SUB_TASK_STRATEGY_PROPERTY, SubTasksStrategy.EndParentOnAllSubTasksEnd } };
TaskContext mockContext = mock(TaskContext.class);
TaskInstanceService mockTaskService = mock(TaskInstanceService.class);
UserGroupCallback mockUserGroupCallback = mock(UserGroupCallback.class);
when(mockContext.getTaskInstanceService()).thenReturn(mockTaskService);
when(mockContext.getUserGroupCallback()).thenReturn(mockUserGroupCallback);
when(mockUserGroupCallback.existsUser(anyString())).thenReturn(false);
for (Object[] data : testData) {
int property = (Integer) data[0];
cmd = new SetTaskPropertyCommand(taskId, userId, property, data[1]);
try {
cmd.execute(mockContext);
} catch (IllegalArgumentException e) {
// expected for fault and output
assertTrue(e.getMessage().startsWith("User user was not found in callback "));
}
}
}
Aggregations