Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed problems in native mode not finding resources (email and task form templates and process mgmgt ui), added support to use functions in expressi ons, disabled abort buttons for non active instances in process management ui #95

Merged
merged 4 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ public List<ProcessInstanceDTO> getInstances(@Context UriInfo uriInfo,
Process<?> process = processData.get(processId);

process.instances().values(ProcessInstanceReadMode.READ_ONLY, mapStatus(status), page, size).forEach(pi -> collected
.add(new ProcessInstanceDTO(pi.id(), pi.businessKey(), pi.description(), pi.tags().values(),
pi.errors().isPresent(), processId)));
.add(new ProcessInstanceDTO(pi.id(), pi.businessKey() == null ? "" : pi.businessKey(), pi.description(),
pi.tags().values(),
pi.errors().isPresent(), processId, pi.status())));

return collected;
} finally {
Expand Down Expand Up @@ -226,8 +227,9 @@ public ProcessInstanceDetailsDTO getInstance(@Context UriInfo uriInfo,

details.setId(id);
details.setProcessId(processId);
details.setBusinessKey(pi.businessKey());
details.setBusinessKey(pi.businessKey() == null ? "" : pi.businessKey());
details.setDescription(pi.description());
details.setState(pi.status());
details.setFailed(pi.errors().isPresent());
if (pi.errors().isPresent()) {

Expand All @@ -242,7 +244,7 @@ public ProcessInstanceDetailsDTO getInstance(@Context UriInfo uriInfo,
details.setVariables(pi.variables());
details.setSubprocesses(pi.subprocesses().stream()
.map(spi -> new ProcessInstanceDTO(spi.id(), spi.businessKey(), spi.description(), spi.tags().values(),
spi.errors().isPresent(), spi.process().id()))
spi.errors().isPresent(), spi.process().id(), spi.status()))
.collect(Collectors.toList()));

VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) process).process())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ProcessInstanceDTO {

private String description;

private int state;

private Collection<String> tags;

private boolean failed;
Expand All @@ -21,13 +23,14 @@ public ProcessInstanceDTO() {
}

public ProcessInstanceDTO(String id, String businessKey, String description, Collection<String> tags, boolean failed,
String processId) {
String processId, int state) {
this.id = id;
this.businessKey = businessKey;
this.description = description;
this.tags = tags;
this.failed = failed;
this.processId = processId;
this.state = state;
}

public String getId() {
Expand All @@ -46,6 +49,14 @@ public void setDescription(String description) {
this.description = description;
}

public int getState() {
return state;
}

public void setState(int state) {
this.state = state;
}

public Collection<String> getTags() {
return tags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ProcessInstanceDetailsDTO {

private String description;

private int state;

private Collection<String> tags;

private boolean failed;
Expand Down Expand Up @@ -51,6 +53,14 @@ public void setDescription(String description) {
this.description = description;
}

public int getState() {
return state;
}

public void setState(int state) {
this.state = state;
}

public Collection<String> getTags() {
return tags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,15 @@
'<object id="piImage" data="' + instanceData.image
+ '" height="400" width="90%"></object>');

if (instanceData.state === 1 || instanceData.state === 5) {
$("#piActions-abort").attr('onclick', 'abortInstance(\''
+ instanceData.processId + '\', \''
+ instanceData.id
+ '\')');
$("#piActions-abort").show();
} else {
$("#piActions-abort").hide();
}

let tags = '';
instanceData.tags
Expand Down Expand Up @@ -385,32 +390,35 @@
tags += '<span class="badge badge-light">' + item
+ '</span> &nbsp;';
});
$('#' + divId)
.append(
'<tr'
+ (item.failed ? ' class="bg-danger"' : '')
+ '>'
+ ' <th scope="row">'
+ (++index + ((currentPage - 1) * 10))
+ '</th>'
+ ' <td>'
+ item.id
+ '</td>'
+ ' <td>'
+ item.businessKey
+ '</td>'
+ ' <td>'
+ item.description
+ '</td>'
+ ' <td>'
+ tags
+ '</td>'
+ ' <td><button type="button" class="btn btn-sm btn-light" onclick="loadInstance(\''
+ processId + '\', \'' + item.id
+ '\')"><i class="fa fa-info-circle"></i></button>&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-danger" onclick="abortInstance(\''
+ processId + '\', \'' + item.id
+ '\')"><i class="fa fa-trash"></i></button></td>'
+ '</tr>');

var data = '<tr'
+ (item.failed ? ' class="bg-danger"' : '')
+ '>'
+ ' <th scope="row">'
+ (++index + ((currentPage - 1) * 10))
+ '</th>'
+ ' <td>'
+ item.id
+ '</td>'
+ ' <td>'
+ item.businessKey
+ '</td>'
+ ' <td>'
+ item.description
+ '</td>'
+ ' <td>'
+ tags
+ '</td>'
+ ' <td><button type="button" class="btn btn-sm btn-light" onclick="loadInstance(\''
+ processId + '\', \'' + item.id
+ '\')"><i class="fa fa-info-circle"></i></button>';
if (item.state === 1 || item.state === 5) {
data += '&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-danger" onclick="abortInstance(\''
+ processId + '\', \'' + item.id
+ '\')"><i class="fa fa-trash"></i></button></td>';
}
data += '</td></tr>'
$('#' + divId).append(data);
});

$('#' + divId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
Expand All @@ -18,6 +19,22 @@
@ApplicationScoped
public class ArchiveService {

/**
* Builds an archive with given files. built archive will be named based on the given
* name so it should include the extension as well.
*
* In case of error a <code>ServiceExecutionError</code> will be thrown with error code set to <code>zipFailure</code>
* so it can be used within workflow definition to handle it
*
* @param name name of the archive
* @param files files to be included in the archive
* @return built archive with given files
*/
@SuppressWarnings("unchecked")
public Archive zip(String name, Collection<File<byte[]>> files) {
return zip(name, files.toArray(File[]::new));
}

/**
* Builds an archive with given files. built archive will be named based on the given
* name so it should include the extension as well.
Expand Down
64 changes: 64 additions & 0 deletions addons/services/automatiko-receive-email-addon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.automatiko.addons.services</groupId>
<artifactId>services</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<groupId>io.automatiko.addons.services</groupId>
<artifactId>automatiko-receive-email-addon</artifactId>

<name>Automatiko Engine :: Add-Ons :: Receive Email Services</name>

<description>Receive Email Services Addon for Automatiko Engine</description>


<properties>
<java.module.name>io.automatiko.addons.services.receiveemail</java.module.name>
</properties>

<dependencies>
<dependency>
<groupId>io.automatiko.engine</groupId>
<artifactId>automatiko-engine-api</artifactId>
</dependency>
<dependency>
<groupId>io.automatiko.engine</groupId>
<artifactId>automatiko-engine-common</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-smallrye-reactive-messaging</artifactId>
<version>${version.org.apache.camel.quarkus}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-mail</artifactId>
<version>${version.org.apache.camel.quarkus}</version>
</dependency>

<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.automatiko.engine.addons.services.receiveemail;

import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.automatiko.engine.api.workflow.files.File;
import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
public class Attachment implements File<byte[]> {

private final String name;

private final byte[] content;

private final Map<String, String> attributes;

public Attachment(String name, byte[] content) {
this.name = name;
this.content = content;
this.attributes = new HashMap<>();
}

@JsonCreator
public Attachment(@JsonProperty("name") String name, @JsonProperty("content") byte[] content,
@JsonProperty("attributes") Map<String, String> attributes) {
this.name = name;
this.content = content;
this.attributes = attributes;
}

public String name() {
return name;
}

public byte[] content() {
return content;
}

@Override
public Map<String, String> attributes() {
return attributes;
}

@Override
public String url() {
return "data:" + type() + ";base64," + Base64.getEncoder().encodeToString(content());
}

@Override
public String toString() {
return "Attachment [name=" + name + ", content (size)=" + content.length + ", attributes=" + attributes + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.automatiko.engine.addons.services.receiveemail;

import java.io.IOException;
import java.util.Map;

import javax.activation.DataHandler;
import javax.enterprise.context.ApplicationScoped;

import org.apache.camel.TypeConversionException;
import org.apache.camel.attachment.Attachment;
import org.apache.camel.component.mail.MailMessage;

import io.automatiko.engine.api.io.InputConverter;
import io.automatiko.engine.api.workflow.files.File;

@SuppressWarnings({ "unchecked", "rawtypes" })
@ApplicationScoped
public class EmailAttachmentInputConverter implements InputConverter<File> {

@Override
public File convert(Object input) {
if (input instanceof MailMessage) {

MailMessage mailMessage = (MailMessage) input;

mailMessage.getMessageId();

Map<String, Attachment> attachments = mailMessage.getExchange().getProperty("CamelAttachmentObjects",
Map.class);
if (attachments != null && attachments.size() > 0) {
for (String name : attachments.keySet()) {
DataHandler dh = attachments.get(name).getDataHandler();
// get the file name
String filename = dh.getName();

// get the content and convert it to byte[]

try {
byte[] data = mailMessage.getExchange().getContext().getTypeConverter()
.convertTo(byte[].class, dh.getInputStream());

return new io.automatiko.engine.addons.services.receiveemail.Attachment(filename, data);
} catch (TypeConversionException | IOException e) {
e.printStackTrace();
}

}
}
}
return null;
}

}
Loading