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;
}
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);
}
}
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());
}
});
}
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();
}
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));
}
Aggregations