Search in sources :

Example 1 with HumanTaskWorkItem

use of io.automatiko.engine.api.runtime.process.HumanTaskWorkItem in project automatiko-engine by automatiko-io.

the class ParticipantsAccessPolicy method whenInitiatorNotSetOrAsIdentity.

@SuppressWarnings("unchecked")
protected boolean whenInitiatorNotSetOrAsIdentity(IdentityProvider identityProvider, ProcessInstance<T> instance) {
    if (identityProvider.isAdmin()) {
        return true;
    }
    WorkflowProcessInstance pi = (WorkflowProcessInstance) ((AbstractProcessInstance<?>) instance).processInstance();
    if (pi.getInitiator() == null || pi.getInitiator().isEmpty() || pi.getInitiator().equals(identityProvider.getName())) {
        return true;
    }
    // next check if the user/group is assigned to any of the active user tasks that
    // can make it eligible to access the instance
    boolean result = ((WorkflowProcessInstanceImpl) pi).getNodeInstances(true).stream().filter(ni -> ni instanceof HumanTaskNodeInstance).anyMatch(ni -> {
        HumanTaskWorkItem workitem = (HumanTaskWorkItem) ((HumanTaskNodeInstance) ni).getWorkItem();
        return workitem.enforce(SecurityPolicy.of(identityProvider));
    });
    if (!result) {
        result = instance.subprocesses().stream().anyMatch(spi -> whenInitiatorNotSetOrAsIdentity(identityProvider, (ProcessInstance<T>) spi));
    }
    return result;
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Set(java.util.Set) AccessPolicy(io.automatiko.engine.api.auth.AccessPolicy) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 2 with HumanTaskWorkItem

use of io.automatiko.engine.api.runtime.process.HumanTaskWorkItem in project automatiko-engine by automatiko-io.

the class TestWorkItemHandler method executeWorkItem.

public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    workItems.add(workItem);
    if (workItem instanceof HumanTaskWorkItem) {
        HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
        humanTaskWorkItem.setPhaseId(Active.ID);
        humanTaskWorkItem.setPhaseStatus(Active.STATUS);
    }
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) HumanTaskWorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)

Example 3 with HumanTaskWorkItem

use of io.automatiko.engine.api.runtime.process.HumanTaskWorkItem in project automatiko-engine by automatiko-io.

the class HumanTaskLifeCycleWithEmail method sendEmail.

private void sendEmail(WorkItem workItem) {
    HumanTaskWorkItem humanTask = (HumanTaskWorkItem) workItem;
    List<String> users = new ArrayList<>();
    if (humanTask.getActualOwner() != null) {
        users.add(humanTask.getActualOwner());
    }
    if (humanTask.getPotentialUsers() != null) {
        users.addAll(humanTask.getPotentialUsers());
    }
    Map<String, String> addresses = emailAddressResolver.resolve(users, humanTask.getPotentialGroups());
    if (addresses.isEmpty()) {
        return;
    }
    String subject = "New task has been assigned to you (" + humanTask.getTaskName() + ")";
    Template template = getTemplate(humanTask.getProcessInstance().getProcess(), humanTask);
    if (template == null) {
        template = engine.getTemplate(DEFAULT_TEMPLATE);
    }
    Mail[] emails = new Mail[addresses.size()];
    Map<String, Object> templateData = new HashMap<>();
    templateData.put("name", humanTask.getTaskName());
    templateData.put("description", humanTask.getTaskDescription());
    templateData.put("taskId", humanTask.getId());
    templateData.put("instanceId", humanTask.getProcessInstanceId());
    templateData.put("processId", humanTask.getProcessInstance().getProcessId());
    templateData.put("inputs", humanTask.getParameters());
    int count = 0;
    for (Entry<String, String> address : addresses.entrySet()) {
        String dedicatedTo = "";
        if (users.contains(address.getKey())) {
            dedicatedTo = address.getKey();
        }
        String parentProcessInstanceId = humanTask.getProcessInstance().getParentProcessInstanceId();
        if (parentProcessInstanceId != null && !parentProcessInstanceId.isEmpty()) {
            parentProcessInstanceId += ":";
        } else {
            parentProcessInstanceId = "";
        }
        String version = version(humanTask.getProcessInstance().getProcess().getVersion());
        String encoded = Base64.getEncoder().encodeToString((humanTask.getProcessInstance().getProcessId() + version + "|" + parentProcessInstanceId + humanTask.getProcessInstance().getId() + "|" + humanTask.getId() + "|" + dedicatedTo).getBytes(StandardCharsets.UTF_8));
        String link = serviceUrl + "/management/tasks/link/" + encoded;
        templateData.put("link", link);
        String body = template.instance().data(templateData).render();
        emails[count] = Mail.withHtml(address.getValue(), subject, body);
        count++;
    }
    // send emails asynchronously
    CompletableFuture.runAsync(() -> {
        for (String to : addresses.values()) {
            mailer.send(emails);
            LOGGER.debug("Email sent to {} with new assigned task {}", to, humanTask.getName());
        }
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Template(io.quarkus.qute.Template) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) Mail(io.quarkus.mailer.Mail)

Example 4 with HumanTaskWorkItem

use of io.automatiko.engine.api.runtime.process.HumanTaskWorkItem in project automatiko-engine by automatiko-io.

the class ProcessInstanceEventBatch method createUserTask.

protected UserTaskInstanceEventBody createUserTask(ProcessWorkItemTransitionEvent workItemTransitionEvent) {
    WorkflowProcessInstance pi = (WorkflowProcessInstance) workItemTransitionEvent.getProcessInstance();
    HumanTaskWorkItem workItem = (HumanTaskWorkItem) workItemTransitionEvent.getWorkItem();
    String parentProcessInstanceId = pi.getParentProcessInstanceId();
    if (parentProcessInstanceId != null && !parentProcessInstanceId.isEmpty()) {
        parentProcessInstanceId += ":";
    } else {
        parentProcessInstanceId = "";
    }
    String version = version(pi.getProcess().getVersion());
    String encoded = Base64.getEncoder().encodeToString((pi.getProcessId() + version + "|" + parentProcessInstanceId + pi.getId() + "|" + workItem.getId() + "|").getBytes(StandardCharsets.UTF_8));
    String link = "/management/tasks/link/" + encoded;
    return UserTaskInstanceEventBody.create().id(workItem.getId()).state(workItem.getPhaseStatus()).taskName(workItem.getTaskName()).taskDescription(workItem.getTaskDescription()).taskPriority(workItem.getTaskPriority()).referenceName(workItem.getReferenceName()).referenceId(workItem.getReferenceId()).formLink(link).actualOwner(workItem.getActualOwner()).startDate(workItem.getStartDate()).completeDate(workItem.getCompleteDate()).adminGroups(workItem.getAdminGroups()).adminUsers(workItem.getAdminUsers()).excludedUsers(workItem.getExcludedUsers()).potentialGroups(workItem.getPotentialGroups()).potentialUsers(workItem.getPotentialUsers()).processInstanceId(pi.getId()).rootProcessInstanceId(pi.getRootProcessInstanceId()).processId(pi.getProcessId()).rootProcessId(pi.getRootProcessId()).inputs(workItem.getParameters()).outputs(workItem.getResults()).instance(workItem).build();
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Example 5 with HumanTaskWorkItem

use of io.automatiko.engine.api.runtime.process.HumanTaskWorkItem in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method getEventDescriptions.

@SuppressWarnings("unchecked")
@Override
public Set<EventDescription<?>> getEventDescriptions() {
    List<NamedDataType> inputs = new ArrayList<>();
    for (ParameterDefinition paramDef : getWorkItemNode().getWork().getParameterDefinitions()) {
        inputs.add(new NamedDataType(paramDef.getName(), paramDef.getType()));
    }
    List<NamedDataType> outputs = new ArrayList<>();
    Map<String, Object> dataOutputs = (Map<String, Object>) getWorkItemNode().getMetaData().getOrDefault("DataOutputs", Collections.emptyMap());
    for (Entry<String, Object> dOut : dataOutputs.entrySet()) {
        outputs.add(new NamedDataType(dOut.getKey(), dOut.getValue()));
    }
    GroupedNamedDataType dataTypes = new GroupedNamedDataType();
    dataTypes.add("Input", inputs);
    dataTypes.add("Output", outputs);
    Map<String, String> properties = new HashMap<>();
    if (getWorkItem() instanceof HumanTaskWorkItem) {
        properties.put("ActualOwner", ((HumanTaskWorkItem) getWorkItem()).getActualOwner());
        properties.put("PotentialUsers", ((HumanTaskWorkItem) getWorkItem()).getPotentialUsers().stream().collect(Collectors.joining(",")));
        properties.put("PotentialGroups", ((HumanTaskWorkItem) getWorkItem()).getPotentialGroups().stream().collect(Collectors.joining(",")));
    }
    // return just the main completion type of an event
    return Collections.singleton(new IOEventDescription("workItemCompleted", getNodeDefinitionId(), getNodeName(), "workItem", getWorkItemId(), getProcessInstance().getId(), dataTypes, properties));
}
Also used : HashMap(java.util.HashMap) GroupedNamedDataType(io.automatiko.engine.api.workflow.GroupedNamedDataType) ArrayList(java.util.ArrayList) IOEventDescription(io.automatiko.engine.api.workflow.IOEventDescription) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) NamedDataType(io.automatiko.engine.api.workflow.NamedDataType) GroupedNamedDataType(io.automatiko.engine.api.workflow.GroupedNamedDataType) Map(java.util.Map) HashMap(java.util.HashMap) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition)

Aggregations

HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)7 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AccessPolicy (io.automatiko.engine.api.auth.AccessPolicy)1 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 GroupedNamedDataType (io.automatiko.engine.api.workflow.GroupedNamedDataType)1 IOEventDescription (io.automatiko.engine.api.workflow.IOEventDescription)1 NamedDataType (io.automatiko.engine.api.workflow.NamedDataType)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)1 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 ParameterDefinition (io.automatiko.engine.workflow.base.core.ParameterDefinition)1 SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)1 HumanTaskWorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)1 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)1 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)1 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)1