protected boolean queueContainsUser(CircularQueue<OrganizationalEntity> queue, OrganizationalEntity oe) { return queue.contains(oe); }
/** * Synchronizes the {@code OrganizationalEntity} objects contained in the {@code CircularQueue} and the list of * potential owners * @param queueName The name of the queue to be synchronized. * @param potentialOwners This list of potential owners of the task * @return The CircularQueue that contains all potential owners */ private synchronized CircularQueue<OrganizationalEntity> synchronizedQueue(String queueName, List<OrganizationalEntity> potentialOwners) { CircularQueue<OrganizationalEntity> existingQueue = (queueName == null || queueName.trim().length() == 0) ? null : circularQueueMap.get(queueName); // If the queue does not exist then a new CircularQueue should be created final CircularQueue<OrganizationalEntity> workingQueue = existingQueue != null ? existingQueue : new CircularQueue(); potentialOwners.forEach(po -> { if (!queueContainsUser(workingQueue, po)) { workingQueue.add(po); } }); workingQueue.removeIf(oe -> !potentialOwners.contains(oe)); circularQueueMap.put(queueName, workingQueue); return workingQueue; }
@Override public Assignment apply(Task task, TaskContext taskContext, String excludedUser) { UserInfo userInfo = (UserInfo) ((org.jbpm.services.task.commands.TaskContext) taskContext).get(EnvironmentName.TASK_USER_INFO); List<OrganizationalEntity> excluded = getExcludedEntities(task, userInfo); // Get the the users from the task's the potential owners List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners().stream() .filter(oe -> oe instanceof User && !excluded.contains(oe)) .collect(Collectors.toList()); // Get the users belonging to groups that are potential owners task.getPeopleAssignments().getPotentialOwners().stream().filter(oe -> oe instanceof Group) .forEach(oe -> { Iterator<OrganizationalEntity> groupUsers = userInfo.getMembersForGroup((Group) oe); if (groupUsers != null) { groupUsers.forEachRemaining(user -> { if (user != null && !excluded.contains(user) && !potentialOwners.contains(user)) { potentialOwners.add(user); } }); } }); if (excludedUser != null) { logger.debug("Removing excluded user {} from the list of eligible users", excludedUser); potentialOwners.removeIf(entity -> entity.getId().equals(excludedUser)); } String queueName = getQueueName(task); CircularQueue<OrganizationalEntity> mappedQueue = synchronizedQueue(queueName, potentialOwners); OrganizationalEntity owner = mappedQueue.take(); return new Assignment(owner.getId()); }
@Before public void setUp() throws Exception { System.setProperty("org.jbpm.task.assignment.enabled", "true"); System.setProperty("org.jbpm.task.assignment.strategy", "LoadBalance"); System.setProperty("org.jbpm.task.assignment.loadbalance.calculator","org.jbpm.services.task.assignment.impl.TaskCountLoadCalculator"); System.setProperty("org.jbpm.task.assignment.loadbalance.entry.timetolive", "10"); // this has to be low in order that we update the load balances pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" ); AssignmentServiceProvider.override(new LoadBalanceAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .getTaskService(); this.tasks = ArrayListMultimap.create(); }
@Override public Assignment apply(Task task, TaskContext taskContext, String excludedUser) { UserInfo userInfo = (UserInfo) ((org.jbpm.services.task.commands.TaskContext)taskContext).get(EnvironmentName.TASK_USER_INFO); List<OrganizationalEntity> excluded = (getExcludedEntities(task, userInfo)); // Get the the users from the task's the potential owners, making sure that excluded users are not included List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners().stream() .filter(oe -> oe instanceof User && !excluded.contains(oe) && !oe.getId().equals(excludedUser)) .collect(Collectors.toList()); // Get the users belonging to groups that are potential owners task.getPeopleAssignments().getPotentialOwners().stream().filter(oe -> oe instanceof Group) .forEach(oe -> { Iterator<OrganizationalEntity> groupUsers = userInfo.getMembersForGroup((Group)oe); if (groupUsers != null) { groupUsers.forEachRemaining(user -> { if (user != null && !excluded.contains(user) && !potentialOwners.contains(user) && !user.getId().equals(excludedUser)) { potentialOwners.add(user); } }); } }); logger.debug("Asking the load calculator [{}] for task loads for the users {}",calculator.getIdentifier(),potentialOwners); List<User> users = potentialOwners.stream().map(entityToUser).collect(Collectors.toList()); Collection<UserTaskLoad> loads = calculator.getUserTaskLoads(users, taskContext); UserTaskLoad lightestLoad = loads.stream().min(UserTaskLoad::compareTo).orElse(null); return lightestLoad != null ? new Assignment(lightestLoad.getUser().getId()):null; }
@Before public void setup() { System.setProperty("org.jbpm.task.assignment.enabled", "true"); System.setProperty("org.jbpm.task.assignment.strategy", "BusinessRule"); System.setProperty("org.jbpm.task.assignment.rules.releaseId", GROUP_ID + ":" + ARTIFACT_ID +":" + VERSION); buildKJar(); pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" ); AssignmentServiceProvider.override(new BusinessRuleAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .getTaskService(); }
@Before public void setup() { System.setProperty("org.jbpm.task.assignment.enabled", "true"); pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" ); AssignmentServiceProvider.override(new PotentialOwnerBusynessAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .getTaskService(); }
@Before public void setup() { System.setProperty("org.jbpm.task.assignment.enabled", "true"); pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory("org.jbpm.services.task"); AssignmentServiceProvider.override(new RoundRobinAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .getTaskService(); }
@Before public void setUp() throws Exception { System.setProperty("org.jbpm.task.assignment.enabled", "true"); System.setProperty("org.jbpm.task.assignment.strategy", "LoadBalance"); System.setProperty("org.jbpm.task.assignment.loadbalance.calculator","org.jbpm.services.task.assignment.impl.TotalCompletionTimeLoadCalculator"); System.setProperty("org.jbpm.services.task.assignment.taskduration.timetolive", "1000"); pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" ); AssignmentServiceProvider.override(new LoadBalanceAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .listener(new JPATaskLifeCycleEventListener(true)) .listener(new BAMTaskEventListener(true)) .getTaskService(); taskIds = new Long[100]; // giving ourselves lots of room forceBAMEntries(); }
@Before public void setUp() throws Exception { System.setProperty("org.jbpm.task.assignment.enabled", "true"); System.setProperty("org.jbpm.task.assignment.strategy", "LoadBalance"); System.setProperty("org.jbpm.task.assignment.loadbalance.calculator","org.jbpm.services.task.assignment.impl.TotalCompletionTimeLoadCalculator"); System.setProperty("org.jbpm.services.task.assignment.taskduration.timetolive", "1000"); pds = setupPoolingDataSource(); emf = Persistence.createEntityManagerFactory( "org.jbpm.services.task" ); AssignmentServiceProvider.override(new LoadBalanceAssignmentStrategy()); this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator() .entityManagerFactory(emf) .listener(new JPATaskLifeCycleEventListener(true)) .listener(new BAMTaskEventListener(true)) .getTaskService(); taskIds = new Long[100]; // giving ourselves lots of room forceBAMEntries(); }