use of org.jbpm.services.task.exception.CannotAddTaskException in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationBasedOnContentByRule.
@Test
public void testCreateTaskWithDisallowedCreationBasedOnContentByRule() {
// 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('john')],businessAdministrators = [ new User('Administrator') ], }),";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
Map<String, Object> params = new HashMap<String, Object>();
params.put("manager", "John");
try {
taskService.addTask(task, params);
fail("Task should not be created due to rule violation");
} catch (CannotAddTaskException e) {
assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1);
}
}
use of org.jbpm.services.task.exception.CannotAddTaskException in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method doCallbackOperationForPeopleAssignments.
protected void doCallbackOperationForPeopleAssignments(InternalPeopleAssignments assignments, TaskContext context) {
List<OrganizationalEntity> nonExistingEntities = new ArrayList<OrganizationalEntity>();
if (assignments != null) {
List<? extends OrganizationalEntity> businessAdmins = assignments.getBusinessAdministrators();
if (businessAdmins != null) {
for (OrganizationalEntity admin : businessAdmins) {
if (admin instanceof User) {
boolean userExists = doCallbackUserOperation(admin.getId(), context);
if (!userExists) {
nonExistingEntities.add(admin);
}
}
if (admin instanceof Group) {
boolean groupExists = doCallbackGroupOperation(admin.getId(), context);
if (!groupExists) {
nonExistingEntities.add(admin);
}
}
}
if (!nonExistingEntities.isEmpty()) {
businessAdmins.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
if (businessAdmins == null || businessAdmins.isEmpty()) {
// throw an exception as it should not be allowed to create task without administrator
throw new CannotAddTaskException("There are no known Business Administrators, task cannot be created according to WS-HT specification");
}
List<? extends OrganizationalEntity> potentialOwners = assignments.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity powner : potentialOwners) {
if (powner instanceof User) {
boolean userExists = doCallbackUserOperation(powner.getId(), context);
if (!userExists) {
nonExistingEntities.add(powner);
}
}
if (powner instanceof Group) {
boolean groupExists = doCallbackGroupOperation(powner.getId(), context);
if (!groupExists) {
nonExistingEntities.add(powner);
}
}
}
if (!nonExistingEntities.isEmpty()) {
potentialOwners.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
if (assignments.getTaskInitiator() != null && assignments.getTaskInitiator().getId() != null) {
doCallbackUserOperation(assignments.getTaskInitiator().getId(), context);
}
List<? extends OrganizationalEntity> excludedOwners = assignments.getExcludedOwners();
if (excludedOwners != null) {
for (OrganizationalEntity exowner : excludedOwners) {
if (exowner instanceof User) {
boolean userExists = doCallbackUserOperation(exowner.getId(), context);
if (!userExists) {
nonExistingEntities.add(exowner);
}
}
if (exowner instanceof Group) {
boolean groupExists = doCallbackGroupOperation(exowner.getId(), context);
if (!groupExists) {
nonExistingEntities.add(exowner);
}
}
}
if (!nonExistingEntities.isEmpty()) {
excludedOwners.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
List<? extends OrganizationalEntity> recipients = assignments.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
boolean userExists = doCallbackUserOperation(recipient.getId(), context);
if (!userExists) {
nonExistingEntities.add(recipient);
}
}
if (recipient instanceof Group) {
boolean groupExists = doCallbackGroupOperation(recipient.getId(), context);
if (!groupExists) {
nonExistingEntities.add(recipient);
}
}
}
if (!nonExistingEntities.isEmpty()) {
recipients.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
List<? extends OrganizationalEntity> stakeholders = assignments.getTaskStakeholders();
if (stakeholders != null) {
for (OrganizationalEntity stakeholder : stakeholders) {
if (stakeholder instanceof User) {
boolean userExists = doCallbackUserOperation(stakeholder.getId(), context);
if (!userExists) {
nonExistingEntities.add(stakeholder);
}
}
if (stakeholder instanceof Group) {
boolean groupExists = doCallbackGroupOperation(stakeholder.getId(), context);
if (!groupExists) {
nonExistingEntities.add(stakeholder);
}
}
}
if (!nonExistingEntities.isEmpty()) {
stakeholders.removeAll(nonExistingEntities);
nonExistingEntities.clear();
}
}
}
}
use of org.jbpm.services.task.exception.CannotAddTaskException in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData.
@Test
public void testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData() {
// 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('john')],businessAdministrators = [ new User('Administrator') ], }),";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
Map<String, Object> params = new HashMap<String, Object>();
params.put("manager", "John");
ContentData data = ContentMarshallerHelper.marshal(task, params, null);
try {
taskService.addTask(task, data);
fail("Task should not be created due to rule violation");
} catch (CannotAddTaskException e) {
assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1);
}
}
use of org.jbpm.services.task.exception.CannotAddTaskException in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationByRule.
@Test
public void testCreateTaskWithDisallowedCreationByRule() {
// 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('peter')],businessAdministrators = [ new User('Administrator') ], }),";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
try {
taskService.addTask(task, new HashMap<String, Object>());
fail("Task should not be created due to rule violation");
} catch (CannotAddTaskException e) {
assertTrue(e.getMessage().indexOf("peter does not work here any more") != -1);
}
}
Aggregations