Search in sources :

Example 6 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class AssignmentService method assignTask.

public void assignTask(Task task) {
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    potentialOwners.clear();
    Group group = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) group).setId("Crusaders");
    potentialOwners.add(group);
}
Also used : Group(org.kie.api.task.model.Group) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Example 7 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class JaxbTask method copyOrganizationalEntityList.

private List<OrganizationalEntity> copyOrganizationalEntityList(List<OrganizationalEntity> jaxbOrgEntList) {
    if (jaxbOrgEntList == null) {
        return null;
    }
    List<OrganizationalEntity> orgEntList = new ArrayList<OrganizationalEntity>(jaxbOrgEntList.size());
    for (OrganizationalEntity jaxbOrgEnt : jaxbOrgEntList) {
        if (jaxbOrgEnt instanceof User) {
            User user = createUser(jaxbOrgEnt.getId());
            orgEntList.add(user);
        } else if (jaxbOrgEnt instanceof Group) {
            Group group = createGroup(jaxbOrgEnt.getId());
            orgEntList.add(group);
        }
    }
    return orgEntList;
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Example 8 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class TaskIdentityServiceImpl method removeGroup.

public void removeGroup(String groupId) {
    Group group = persistenceContext.findGroup(groupId);
    persistenceContext.remove(group);
}
Also used : Group(org.kie.api.task.model.Group)

Example 9 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class MvelUserGroupCallbackImpl method getGroupsForUser.

public List<String> getGroupsForUser(String userId) {
    Iterator<User> iter = userGroupMapping.keySet().iterator();
    while (iter.hasNext()) {
        User u = iter.next();
        if (u.getId().equals(userId)) {
            List<String> groupList = new ArrayList<String>();
            List<Group> userGroupList = userGroupMapping.get(u);
            for (Group g : userGroupList) {
                groupList.add(g.getId());
            }
            return groupList;
        }
    }
    return new ArrayList<String>(0);
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) ArrayList(java.util.ArrayList)

Example 10 with Group

use of org.kie.api.task.model.Group in project jbpm by kiegroup.

the class EmailNotificationListener method onNotification.

@Override
public void onNotification(NotificationEvent event, UserInfo userInfo) {
    if (userInfo == null || mailSession == null) {
        logger.info("Missing mail session or userinfo - skipping email notification listener processing");
        return;
    }
    if (event.getNotification() instanceof EmailNotification) {
        EmailNotification notification = (EmailNotification) event.getNotification();
        Task task = event.getTask();
        // group users into languages
        Map<String, List<User>> users = new HashMap<String, List<User>>();
        for (OrganizationalEntity entity : notification.getBusinessAdministrators()) {
            if (entity instanceof Group) {
                buildMapByLanguage(users, (Group) entity, userInfo);
            } else {
                buildMapByLanguage(users, (User) entity, userInfo);
            }
        }
        for (OrganizationalEntity entity : notification.getRecipients()) {
            if (entity instanceof Group) {
                buildMapByLanguage(users, (Group) entity, userInfo);
            } else {
                buildMapByLanguage(users, (User) entity, userInfo);
            }
        }
        Map<String, Object> variables = event.getContent();
        Map<? extends Language, ? extends EmailNotificationHeader> headers = notification.getEmailHeaders();
        for (Iterator<Map.Entry<String, List<User>>> it = users.entrySet().iterator(); it.hasNext(); ) {
            try {
                Map.Entry<String, List<User>> entry = it.next();
                Language lang = TaskModelProvider.getFactory().newLanguage();
                lang.setMapkey(entry.getKey());
                EmailNotificationHeader header = headers.get(lang);
                Message msg = new MimeMessage(mailSession);
                Set<String> toAddresses = new HashSet<String>();
                for (User user : entry.getValue()) {
                    String emailAddress = userInfo.getEmailForEntity(user);
                    if (emailAddress != null && !toAddresses.contains(emailAddress)) {
                        msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(emailAddress, false));
                        toAddresses.add(emailAddress);
                    } else {
                        logger.warn("Email address not found for user {}", user.getId());
                    }
                }
                if (header.getFrom() != null && header.getFrom().trim().length() > 0) {
                    User user = TaskModelProvider.getFactory().newUser();
                    ((InternalOrganizationalEntity) user).setId(header.getFrom());
                    msg.setFrom(new InternetAddress(userInfo.getEmailForEntity(user)));
                } else {
                    msg.setFrom(new InternetAddress(mailSession.getProperty("mail.from")));
                }
                if (header.getReplyTo() != null && header.getReplyTo().trim().length() > 0) {
                    User user = TaskModelProvider.getFactory().newUser();
                    ((InternalOrganizationalEntity) user).setId(header.getReplyTo());
                    msg.setReplyTo(new InternetAddress[] { new InternetAddress(userInfo.getEmailForEntity(user)) });
                } else if (mailSession.getProperty("mail.replyto") != null) {
                    msg.setReplyTo(new InternetAddress[] { new InternetAddress(mailSession.getProperty("mail.replyto")) });
                }
                Map<String, Object> vars = new HashMap<String, Object>();
                vars.put("doc", variables);
                // add internal items to be able to reference them in templates
                vars.put("processInstanceId", task.getTaskData().getProcessInstanceId());
                vars.put("processSessionId", task.getTaskData().getProcessSessionId());
                vars.put("workItemId", task.getTaskData().getWorkItemId());
                vars.put("expirationTime", task.getTaskData().getExpirationTime());
                vars.put("taskId", task.getId());
                if (task.getPeopleAssignments() != null) {
                    vars.put("owners", task.getPeopleAssignments().getPotentialOwners());
                }
                String subject = (String) TemplateRuntime.eval(header.getSubject(), vars);
                String body = (String) TemplateRuntime.eval(header.getBody(), vars);
                if (variables.containsKey("attachments")) {
                    Multipart multipart = new MimeMultipart();
                    // prepare body as first mime body part
                    MimeBodyPart messageBodyPart = new MimeBodyPart();
                    messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(body, "text/html")));
                    multipart.addBodyPart(messageBodyPart);
                    List<String> attachments = getAttachements(variables.get("attachments"));
                    for (String attachment : attachments) {
                        MimeBodyPart attachementBodyPart = new MimeBodyPart();
                        URL attachmentUrl = getAttachemntURL(attachment);
                        String contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(attachmentUrl.getFile());
                        attachementBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(attachmentUrl.openStream(), contentType)));
                        String fileName = new File(attachmentUrl.getFile()).getName();
                        attachementBodyPart.setFileName(fileName);
                        attachementBodyPart.setContentID("<" + fileName + ">");
                        multipart.addBodyPart(attachementBodyPart);
                    }
                    // Put parts in message
                    msg.setContent(multipart);
                } else {
                    msg.setDataHandler(new DataHandler(new ByteArrayDataSource(body, "text/html")));
                }
                msg.setSubject(subject);
                msg.setHeader("X-Mailer", "jbpm human task service");
                msg.setSentDate(new Date());
                Transport.send(msg);
            } catch (Exception e) {
                logger.error("Unable to send email notification due to {}", e.getMessage());
                logger.debug("Stacktrace:", e);
            }
        }
    }
}
Also used : Group(org.kie.api.task.model.Group) Task(org.kie.api.task.model.Task) InternetAddress(javax.mail.internet.InternetAddress) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) User(org.kie.api.task.model.User) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) HashMap(java.util.HashMap) DataHandler(javax.activation.DataHandler) EmailNotification(org.kie.internal.task.api.model.EmailNotification) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) URL(java.net.URL) Language(org.kie.internal.task.api.model.Language) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) HashSet(java.util.HashSet) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) MalformedURLException(java.net.MalformedURLException) MimeBodyPart(javax.mail.internet.MimeBodyPart) HashMap(java.util.HashMap) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) Map(java.util.Map) File(java.io.File)

Aggregations

Group (org.kie.api.task.model.Group)38 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)29 User (org.kie.api.task.model.User)27 ArrayList (java.util.ArrayList)17 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Task (org.kie.api.task.model.Task)11 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)9 Test (org.junit.Test)8 List (java.util.List)6 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)5 InternalTask (org.kie.internal.task.api.model.InternalTask)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 WorkItem (org.drools.core.process.instance.WorkItem)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 PeopleAssignments (org.kie.api.task.model.PeopleAssignments)4 Iterator (java.util.Iterator)3