Search in sources :

Example 26 with InternalOrganizationalEntity

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());
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 27 with InternalOrganizationalEntity

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());
        }
    }
}
Also used : User(org.kie.api.task.model.User) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) ContentData(org.kie.internal.task.api.model.ContentData) TaskServiceRequest(org.jbpm.services.task.rule.TaskServiceRequest) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 28 with InternalOrganizationalEntity

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;
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) ArrayList(java.util.ArrayList) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Reassignment(org.kie.internal.task.api.model.Reassignment)

Example 29 with InternalOrganizationalEntity

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;
}
Also used : Group(org.kie.api.task.model.Group) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) ArrayList(java.util.ArrayList) EmailNotification(org.kie.internal.task.api.model.EmailNotification) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Language(org.kie.internal.task.api.model.Language)

Example 30 with InternalOrganizationalEntity

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);
            }
        }
    }
}
Also used : InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Aggregations

InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)31 User (org.kie.api.task.model.User)25 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)21 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 InternalTask (org.kie.internal.task.api.model.InternalTask)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)12 InputStreamReader (java.io.InputStreamReader)11 Reader (java.io.Reader)11 Group (org.kie.api.task.model.Group)11 ContentData (org.kie.internal.task.api.model.ContentData)11 HashMap (java.util.HashMap)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10 InternalContent (org.kie.internal.task.api.model.InternalContent)10 Date (java.util.Date)9 Task (org.kie.api.task.model.Task)5 I18NText (org.kie.api.task.model.I18NText)4 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)4 StringReader (java.io.StringReader)3