use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleBaseTest method testFailWithIncorrectUser.
@Test
public void testFailWithIncorrectUser() {
// 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");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Should not fail as wrong user
PermissionDeniedException denied = null;
try {
taskService.fail(taskId, "Bobba Fet", null);
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCompleteTaskWithCheckByRule.
@Test
public void testCompleteTaskWithCheckByRule() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('mary')],businessAdministrators = [ new User('Administrator') ], }),";
str += "description = 'This is my description', ";
str += "subject = 'This is my subject', ";
str += "name = 'This is my task name' })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
List<TaskSummary> tasks = taskService.getTasksOwned("mary", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "mary");
Map<String, Object> data = new HashMap<String, Object>();
data.put("approved", "false");
try {
taskService.complete(taskId, "mary", data);
fail("Task should not be created due to rule violation");
} catch (PermissionDeniedException e) {
assertTrue(e.getMessage().indexOf("Mary is not allowed to complete task with approved false") != -1);
}
}
use of org.jbpm.services.task.exception.PermissionDeniedException 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.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class CompleteTaskCommand method execute.
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
doCallbackUserOperation(userId, context, true);
groupIds = doUserGroupCallbackOperation(userId, null, context);
context.set("local:groups", groupIds);
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (task == null) {
throw new PermissionDeniedException("Task '" + taskId + "' not found");
}
context.loadTaskVariables(task);
Map<String, Object> outputdata = task.getTaskData().getTaskOutputVariables();
if (outputdata != null) {
// if there are data given with completion, merged them into existing outputs
if (data != null) {
outputdata.putAll(data);
}
// since output data was non null make it the actual data
data = outputdata;
}
context.getTaskRuleService().executeRules(task, userId, data, TaskRuleService.COMPLETE_TASK_SCOPE);
((InternalTaskData) task.getTaskData()).setTaskOutputVariables(data);
TaskInstanceService instanceService = context.getTaskInstanceService();
instanceService.complete(taskId, userId, data);
return null;
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class ListTaskNotificationsCommand method execute.
@Override
public List<TaskNotification> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Language lang = factory.newLanguage();
lang.setMapkey("en-UK");
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
Deadlines deadlines = ((InternalTask) task).getDeadlines();
List<TaskNotification> notificationsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> notificationsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> result = new ArrayList<>();
result.addAll(notificationsNotStarted);
result.addAll(notificationsNotCompleted);
if (activeOnly) {
logger.debug("Removing already completed deadlines from the result");
result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
}
return result;
}
Aggregations