use of org.jbpm.services.task.exception.PermissionDeniedException 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.exception.PermissionDeniedException 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.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LocalHTWorkItemHandler method abortWorkItem.
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
RuntimeEngine runtime = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId()));
Task task = runtime.getTaskService().getTaskByWorkItemId(workItem.getId());
if (task != null) {
try {
String adminUser = ADMIN_USER;
List<OrganizationalEntity> businessAdmins = task.getPeopleAssignments().getBusinessAdministrators();
for (OrganizationalEntity admin : businessAdmins) {
if (admin instanceof Group) {
continue;
}
if (!admin.getId().equals(ADMIN_USER)) {
adminUser = admin.getId();
break;
}
}
logger.debug("Task {} is going to be exited by {} who is business admin", task.getId(), adminUser);
runtime.getTaskService().exit(task.getId(), adminUser);
} catch (PermissionDeniedException e) {
logger.info(e.getMessage());
}
}
}
Aggregations