Skip to content

Commit

Permalink
Zip element template (#83)
Browse files Browse the repository at this point in the history
Zip element template
  • Loading branch information
pierre-yves-monnet authored Dec 21, 2022
1 parent f255a31 commit 857699d
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 279 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.camunda.community</groupId>
<artifactId>zeebe-cherry-framework</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>

<properties>
<java.version>17</java.version>
Expand Down
464 changes: 244 additions & 220 deletions src/main/java/io/camunda/cherry/admin/RunnerRestController.java

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions src/main/java/io/camunda/cherry/admin/ZipOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.camunda.cherry.admin;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipOperation {

ByteArrayOutputStream zipContent;
ZipOutputStream zipOut;
String fileName;

public ZipOperation(String zipFileName) {
zipContent = new ByteArrayOutputStream();
zipOut = new ZipOutputStream(zipContent);
fileName = zipFileName;
}

/**
* Add a file in the Zip
* @param fileName file name
* @param content content to add
* @throws IOException in case of error
*/
public void addZipContent(String fileName, String content) throws IOException {
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
byte[] contentByte = content.getBytes(StandardCharsets.UTF_8);

zipOut.write(contentByte, 0, contentByte.length);
}

public void close() throws IOException {
zipOut.close();
}

public InputStream getInputStream() {
return new ByteArrayInputStream(zipContent.toByteArray());
}

public byte[] getBytes() {
return zipContent.toByteArray();
}

public String getFileName() {
return fileName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
/* ******************************************************************** */
package io.camunda.cherry.files;

import io.camunda.cherry.definition.AbstractWorker;
import io.camunda.cherry.definition.BpmnError;
import io.camunda.cherry.definition.IntFrameworkRunner;
import io.camunda.cherry.definition.RunnerParameter;
import io.camunda.file.storage.FileVariable;
import io.camunda.file.storage.StorageDefinition;
import io.camunda.file.storage.cmis.CmisParameters;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.spring.client.exception.ZeebeBpmnError;
import io.camunda.cherry.definition.AbstractWorker;
import io.camunda.cherry.definition.BpmnError;
import io.camunda.cherry.definition.IntFrameworkRunner;
import io.camunda.cherry.definition.RunnerParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -146,7 +144,7 @@ public boolean isFrameworkRunner() {

@Override
public String getName() {
return "CherryLoadFileFromDisk";
return "FileStorageLoadFileFromDisk";
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/io/camunda/cherry/files/PurgeFileWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
/* ******************************************************************** */
package io.camunda.cherry.files;

import io.camunda.cherry.definition.AbstractWorker;
import io.camunda.cherry.definition.BpmnError;
import io.camunda.cherry.definition.IntFrameworkRunner;
import io.camunda.cherry.definition.RunnerParameter;
import io.camunda.file.storage.FileRepoFactory;
import io.camunda.file.storage.FileVariableReference;
import io.camunda.file.storage.StorageDefinition;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.spring.client.exception.ZeebeBpmnError;
import io.camunda.cherry.definition.AbstractWorker;
import io.camunda.cherry.definition.BpmnError;
import io.camunda.cherry.definition.IntFrameworkRunner;
import io.camunda.cherry.definition.RunnerParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collections;

@Component
public class PurgeFileWorker extends AbstractWorker implements IntFrameworkRunner {
Expand All @@ -31,20 +31,20 @@ public class PurgeFileWorker extends AbstractWorker implements IntFrameworkRunne

public PurgeFileWorker() {
super("c-files-purge",
Arrays.asList(
Collections.singletonList(
RunnerParameter.getInstance(INPUT_SOURCE_FILE, "Source file", Object.class, RunnerParameter.Level.REQUIRED, "FileVariable used to save")
),
Arrays.asList(
Collections.singletonList(
RunnerParameter.getInstance(OUTPUT_FILE_IS_PURGED, "File is purged", Object.class, RunnerParameter.Level.REQUIRED, "True if the file is purged correctly")
),
Arrays.asList(
Collections.singletonList(
BpmnError.getInstance(StorageDefinition.ERROR_INCORRECT_STORAGEDEFINITION, "Incorrect storage definition")));
}

/**
* mark this worker as a Framework runner
*
* @return
* @return true if the runner is part of the framework
*/
@Override
public boolean isFrameworkRunner() {
Expand All @@ -53,7 +53,7 @@ public boolean isFrameworkRunner() {

@Override
public String getName() {
return "CherryPurgeFile";
return "FileStoragePurgeFile";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean isFrameworkRunner() {

@Override
public String getName() {
return "CherrySaveFileToDisk";
return "FileStorageSaveFileToDisk";
}

@Override
Expand All @@ -82,7 +82,7 @@ public String getLabel() {

@Override
public String getDescription() {
return "Save a file in a storage definition a disk";
return "Save a file from a storage definition to a disk";
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/camunda/cherry/ping/PingConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.net.InetAddress;
import java.util.Collections;
import java.util.Map;

/* ------------------------------------------------------------------- */

Expand Down Expand Up @@ -61,9 +62,11 @@ public Object execute(OutboundConnectorContext context) throws Exception {

// context.validate(pingConnectorInput);
Thread.sleep( pingConnectorInput.getDelay());
InetAddress IP=InetAddress.getLocalHost();
InetAddress ipAddress=InetAddress.getLocalHost();

return new PingConnectorOutput(System.currentTimeMillis(), IP.getHostAddress());
return new PingConnectorOutput(System.currentTimeMillis(),
ipAddress.getHostAddress(),
Map.of("JDK", System.getProperty("java.version")));
}

}
Expand Down
70 changes: 41 additions & 29 deletions src/main/java/io/camunda/cherry/ping/PingConnectorOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,49 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class PingConnectorOutput extends AbstractConnectorOutput {

private long internalTimeStampMS;
private String internalIpAddress;

public PingConnectorOutput() {
super();
}

public PingConnectorOutput(long currentTimestamp, String ipAddress) {
super();
this.internalTimeStampMS = currentTimestamp;
this.internalIpAddress = ipAddress;
}

@Override
public List<RunnerParameter> getOutputParameters() {
return Arrays.asList(
RunnerParameter.getInstance("timeStampMS", "Time stamp", Long.class, RunnerParameter.Level.REQUIRED, "Produce a timestamp"),
RunnerParameter.getInstance("ipAddress", "Ip Address", String.class, RunnerParameter.Level.REQUIRED, "Returm the IpAddress")
);
}

/* The getter must start by a lower case */
public long gettimeStampMS() {
return internalTimeStampMS;
}
/* The getter must start by a lower case */
public String getipAddress() {
return internalIpAddress;
}
private long internalTimeStampMS;
private String internalIpAddress;

private Map<String, Object> parameters;

public PingConnectorOutput() {
super();
}

public PingConnectorOutput(long currentTimestamp, String ipAddress, Map<String,Object> parameters) {
super();
this.internalTimeStampMS = currentTimestamp;
this.internalIpAddress = ipAddress;
this.parameters = parameters;
}

@Override
public List<RunnerParameter> getOutputParameters() {
return Arrays.asList(
RunnerParameter.getInstance("timeStampMS", "Time stamp", Long.class, RunnerParameter.Level.REQUIRED,
"Produce a timestamp"),
RunnerParameter.getInstance("ipAddress", "Ip Address", String.class, RunnerParameter.Level.REQUIRED,
"Returm the IpAddress"),
RunnerParameter.getInstance("parameters", "Parameters", Map.class, RunnerParameter.Level.REQUIRED,
"Returm parameters"));
}

/* The getter must start by a lower case */
public long gettimeStampMS() {
return internalTimeStampMS;
}

/* The getter must start by a lower case */
public String getipAddress() {
return internalIpAddress;
}

public Map<String, Object> getparameters() {
return parameters;
}
}

20 changes: 12 additions & 8 deletions src/test/resources/connectorworker/PingObjectConnector.bpmn

Large diffs are not rendered by default.

0 comments on commit 857699d

Please sign in to comment.