public TaskContext( Context context, Environment environment, TaskEventSupport taskEventSupport ) { if (context instanceof org.kie.internal.task.api.TaskContext) { this.delegate = ((org.kie.internal.task.api.TaskContext) context); this.persistenceContext = ((org.kie.internal.task.api.TaskContext) context).getPersistenceContext(); } this.environment = environment; this.taskEventSupport = taskEventSupport; }
protected void addUserIdToContext(TaskCommand<?> command, RequestContext context) { if (context instanceof org.kie.internal.task.api.TaskContext) { org.kie.internal.task.api.TaskContext taskContext = (org.kie.internal.task.api.TaskContext) context; IdentityProvider identityProvider = (IdentityProvider) taskContext.get(EnvironmentName.IDENTITY_PROVIDER); String userId = command.getUserId(); if (command instanceof CompositeCommand) { userId = ((CompositeCommand<?>) command).getMainCommand().getUserId(); } if (userId == null && identityProvider != null) { userId = identityProvider.getName(); command.setUserId(userId); } taskContext.setUserId(userId); } } }
protected boolean doCallbackUserOperation(String userId, TaskContext context, boolean throwExceptionWhenNotFound) { if (userId != null && context.getUserGroupCallback().existsUser(userId)) { addUserFromCallbackOperation(userId, context); return true; } if (throwExceptionWhenNotFound) { throw new IllegalArgumentException("User " + userId + " was not found in callback " + context.getUserGroupCallback()); } return false; }
@SuppressWarnings("unchecked") protected List<String> toGroups(List<String> groups) { if (groups == null) { return (List<String>) context.get("local:groups"); } return groups; }
when(context.getUserId()).thenReturn("john"); Task task = new TaskFluent().setName("This is my task name") .addPotentialGroup("Knights Templer")
public void set(String string, Object o) { if (string.startsWith("local:")) { delegate.set(string, o); return; } if (this.environment.get(string) != null) { throw new IllegalArgumentException("Cannot override value for property " + string); } this.environment.set(string, o); }
public Object get(String string) { if (string.startsWith("local:")) { return delegate.get(string); } return this.environment.get(string); }
when(context.getUserId()).thenReturn("john"); Task task = new TaskFluent().setName("This is my task name") .addPotentialGroup("Knights Templer")
@Override public Void execute(Context context) { TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext(); if( this.taskId != null ) { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("taskId", this.taskId); persistenceContext.executeUpdate("deleteTaskEventsForTask", params); } else { persistenceContext.executeUpdate("deleteAllTaskEvents", null); } return null; }
protected boolean isBusinessAdmin(String userId, List<OrganizationalEntity> businessAdmins, TaskContext context) { List<String> usersGroup = new ArrayList<String>(context.getUserGroupCallback().getGroupsForUser(userId)); usersGroup.add(userId); return businessAdmins.stream().anyMatch(oe -> usersGroup.contains(oe.getId())); }
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 " +
@Override public Void execute(Context context) { TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext(); if( this.taskId != null ) { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("taskId", this.taskId); persistenceContext.executeUpdate("deleteBAMTaskSummariesForTask", params); } else { persistenceContext.executeUpdate("deleteAllBAMTaskSummaries", null); } return null; }
protected boolean doCallbackGroupOperation(String groupId, TaskContext context) { if (groupId != null && context.getUserGroupCallback().existsGroup(groupId) && !restrictedGroups.contains(groupId)) { addGroupFromCallbackOperation(groupId, context); return true; } return false; }
@Override public void afterTaskInputVariableChangedEvent(TaskEvent event, Map<String, Object> variables) { if (variables == null || variables.isEmpty()) { return; } Task task = event.getTask(); TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext)event.getTaskContext()).getPersistenceContext()); indexAndPersistVariables(task, variables, persistenceContext, VariableType.INPUT); }
protected User doCallbackAndReturnUserOperation(String userId, TaskContext context) { if (userId != null && context.getUserGroupCallback().existsUser(userId)) { return addUserFromCallbackOperation(userId, context); } return null; }
protected void persistIfNotExists(final OrganizationalEntity entity, TaskContext context) { TaskPersistenceContext tpc = context.getPersistenceContext(); OrganizationalEntity orgEntity = tpc.findOrgEntity(entity.getId()); if( orgEntity == null || (orgEntity instanceof Group && entity instanceof User) || (orgEntity instanceof User && entity instanceof Group) ) { tpc.persistOrgEntity(entity); } }
List<String> userGroups = filterGroups(context.getUserGroupCallback().getGroupsForUser(userId)); for (String groupId : groupIds) { if (context.getUserGroupCallback().existsGroup(groupId) && userGroups != null && userGroups.contains(groupId)) { addGroupFromCallbackOperation(groupId, context); List<String> userGroups = filterGroups(context.getUserGroupCallback().getGroupsForUser(userId)); if (userGroups != null && userGroups.size() > 0) { for (String group : userGroups) {
@Override public List<TaskSummary> execute(Context context) { TaskContext ctx = (TaskContext) context; TaskPersistenceContext persistenceContext = ctx.getPersistenceContext(); List<TaskSummary> tasks = (List<TaskSummary>) persistenceContext.queryWithParametersInTransaction("TasksByStatusByProcessId", persistenceContext.addParametersToMap("processInstanceId", processInstanceId, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class)); return tasks; }
@Override public List<AuditTask> execute(Context context) { TaskPersistenceContext persistenceContext = ((TaskContext) context).getPersistenceContext(); List<AuditTask> groupTasks = persistenceContext.queryWithParametersInTransaction("getAllAuditTasksByStatus", persistenceContext.addParametersToMap("owner", userId,"statuses", filter.getParams().get("statuses"),"firstResult", filter.getOffset(), "maxResults", filter.getCount()), ClassUtil.<List<AuditTask>>castClass(List.class)); return groupTasks; }
TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext)event.getTaskContext()).getPersistenceContext()); StringBuilder message = new StringBuilder();