use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskSkipped.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskSkipped() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
((InternalTaskData) task.getTaskData()).setSkipable(true);
InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Administrator");
ba.add(user);
assignments.setBusinessAdministrators(ba);
List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
User user2 = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user2).setId("Administrator");
po.add(user2);
assignments.setPotentialOwners(po);
task.setPeopleAssignments(assignments);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
Map<String, String> params = fillMarshalSubjectAndBodyParams();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
content.setContent(marshalledObject.getContent());
taskService.addContent(taskId, content);
long contentId = content.getId();
content = (InternalContent) taskService.getContentById(contentId);
Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
checkContentSubjectAndBody(unmarshallObject);
taskService.skip(taskId, "Administrator");
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// no email should ne sent as task was completed before deadline was triggered
assertEquals(0, getWiser().getMessages().size());
task = (InternalTask) taskService.getTaskById(taskId);
assertEquals(Status.Obsolete, task.getTaskData().getStatus());
assertEquals(0, task.getDeadlines().getStartDeadlines().size());
assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class TaskRuleServiceImpl method executeRules.
@Override
public void executeRules(Task task, String userId, Object params, String scope) throws TaskException {
KieBase ruleBase = ruleContextProvider.getKieBase(scope);
if (ruleBase != null) {
KieSession session = ruleBase.newKieSession();
Map<String, Object> globals = ruleContextProvider.getGlobals(scope);
if (globals != null) {
for (Map.Entry<String, Object> entry : globals.entrySet()) {
session.setGlobal(entry.getKey(), entry.getValue());
}
}
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(userId);
TaskServiceRequest request = new TaskServiceRequest(scope, user, null);
session.setGlobal("request", request);
session.insert(task);
if (params != null) {
if (params instanceof ContentData) {
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task);
params = ContentMarshallerHelper.unmarshall(((ContentData) params).getContent(), ctx.getEnvironment(), ctx.getClassloader());
}
session.insert(params);
}
session.fireAllRules();
session.dispose();
if (!request.isAllowed()) {
StringBuilder error = new StringBuilder("Cannot perform operation " + scope + " :\n");
if (request.getReasons() != null) {
for (String reason : request.getReasons()) {
error.append(reason).append('\n');
}
}
throw request.getException(error.toString());
}
}
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseReassignment.
protected static List<Reassignment> parseReassignment(String reassignString) {
List<Reassignment> reassignments = new ArrayList<Reassignment>();
Map<String, String> parameters = asMap(reassignString);
if (parameters.containsKey("users") || parameters.containsKey("groups")) {
Reassignment reassignment = TaskModelProvider.getFactory().newReassignment();
List<OrganizationalEntity> reassignmentUsers = new ArrayList<OrganizationalEntity>();
String recipients = parameters.get("users");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(id.trim());
reassignmentUsers.add(user);
}
}
recipients = parameters.get("groups");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(id.trim());
reassignmentUsers.add(group);
}
}
reassignment.setPotentialOwners(reassignmentUsers);
reassignments.add(reassignment);
}
return reassignments;
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseNotifications.
protected static List<Notification> parseNotifications(String notificationString, List<OrganizationalEntity> businessAdministrators) {
List<Notification> notifications = new ArrayList<Notification>();
Map<String, String> parameters = asMap(notificationString);
if (parameters.containsKey("tousers") || parameters.containsKey("togroups")) {
String locale = parameters.get("locale");
if (locale == null) {
locale = "en-UK";
}
EmailNotification emailNotification = TaskModelProvider.getFactory().newEmialNotification();
notifications.add(emailNotification);
emailNotification.setBusinessAdministrators(businessAdministrators);
Map<Language, EmailNotificationHeader> emailHeaders = new HashMap<Language, EmailNotificationHeader>();
List<I18NText> subjects = new ArrayList<I18NText>();
List<I18NText> names = new ArrayList<I18NText>();
List<OrganizationalEntity> notificationRecipients = new ArrayList<OrganizationalEntity>();
EmailNotificationHeader emailHeader = TaskModelProvider.getFactory().newEmailNotificationHeader();
emailHeader.setBody(parameters.get("body"));
emailHeader.setFrom(parameters.get("from"));
emailHeader.setReplyTo(parameters.get("replyto"));
emailHeader.setLanguage(locale);
emailHeader.setSubject(parameters.get("subject"));
Language lang = TaskModelProvider.getFactory().newLanguage();
lang.setMapkey(locale);
emailHeaders.put(lang, emailHeader);
I18NText subject = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) subject).setLanguage(locale);
((InternalI18NText) subject).setText(emailHeader.getSubject());
;
subjects.add(subject);
names.add(subject);
String recipients = parameters.get("tousers");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(id.trim());
notificationRecipients.add(user);
}
}
String groupRecipients = parameters.get("togroups");
if (groupRecipients != null && groupRecipients.trim().length() > 0) {
String[] groupRecipientsIds = groupRecipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : groupRecipientsIds) {
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(id.trim());
notificationRecipients.add(group);
}
}
emailNotification.setEmailHeaders(emailHeaders);
emailNotification.setNames(names);
emailNotification.setRecipients(notificationRecipients);
emailNotification.setSubjects(subjects);
}
return notifications;
}
use of org.kie.internal.task.api.model.InternalOrganizationalEntity in project jbpm by kiegroup.
the class PeopleAssignmentHelper method processPeopleAssignments.
protected void processPeopleAssignments(String peopleAssignmentIds, List<OrganizationalEntity> organizationalEntities, boolean user) {
if (peopleAssignmentIds != null && peopleAssignmentIds.trim().length() > 0) {
String[] ids = peopleAssignmentIds.split(separator);
for (String id : ids) {
id = id.trim();
boolean exists = false;
for (OrganizationalEntity orgEntity : organizationalEntities) {
if (orgEntity.getId().equals(id)) {
exists = true;
}
}
if (!exists) {
OrganizationalEntity organizationalEntity = null;
if (user) {
organizationalEntity = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) organizationalEntity).setId(id);
} else {
organizationalEntity = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) organizationalEntity).setId(id);
}
organizationalEntities.add(organizationalEntity);
}
}
}
}
Aggregations