Search in sources :

Example 1 with ByteArrayFile

use of io.automatiko.engine.workflow.file.ByteArrayFile in project automatiko-engine by automatiko-io.

the class FileSystemFileVariableAugmentor method augmentOnUpdate.

@Override
public Object augmentOnUpdate(String processId, String processVersion, String processInstanceId, Variable variable, Object value) {
    Object originalValue = value;
    value = retrieveValue(value);
    if (value == null) {
        return value;
    }
    StringBuilder url = new StringBuilder(serviceUrl);
    url.append(processId).append("/");
    if (processVersion != null && !processVersion.isEmpty()) {
        url.append(processVersion).append("/");
    }
    url.append(processInstanceId).append("/").append(variable.getName());
    if (value instanceof ByteArrayFile) {
        ByteArrayFile file = (ByteArrayFile) value;
        if (file.content() != null) {
            FileSystemFile fsFile = new FileSystemFile(file.name(), null, file.attributes());
            fsFile.url(url.toString() + "/" + file.name());
            // replace file on file system
            store.replace(file.content(), processId, processVersion, processInstanceId, variable.getName(), file.name());
            value = updateValue(originalValue, fsFile);
        }
    } else if (value instanceof Collection) {
        Collection<ByteArrayFile> fsFiles = new ArrayList<>();
        for (Object potentialFile : (Collection<?>) value) {
            if (potentialFile instanceof ByteArrayFile) {
                ByteArrayFile file = (ByteArrayFile) potentialFile;
                if (file.content() != null) {
                    FileSystemFile fsFile = new FileSystemFile(file.name(), null, file.attributes());
                    fsFile.url(url.toString() + "/" + file.name());
                    // replace file on file system
                    store.replace(file.content(), processId, processVersion, processInstanceId, variable.getName(), file.name());
                    fsFiles.add(fsFile);
                } else {
                    fsFiles.add(file);
                }
            }
        }
        return updateValue(originalValue, fsFiles);
    }
    return value;
}
Also used : Collection(java.util.Collection) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Example 2 with ByteArrayFile

use of io.automatiko.engine.workflow.file.ByteArrayFile in project automatiko-engine by automatiko-io.

the class FileSystemFileVariableAugmentor method augmentOnCreate.

@Override
public Object augmentOnCreate(String processId, String processVersion, String processInstanceId, Variable variable, Object value) {
    Object originalValue = value;
    value = retrieveValue(value);
    if (value == null) {
        return value;
    }
    StringBuilder url = new StringBuilder(serviceUrl);
    url.append(processId).append("/");
    if (processVersion != null && !processVersion.isEmpty()) {
        url.append(processVersion).append("/");
    }
    url.append(processInstanceId).append("/").append(variable.getName());
    if (value instanceof ByteArrayFile) {
        ByteArrayFile file = (ByteArrayFile) value;
        if (file.content() != null) {
            FileSystemFile fsFile = new FileSystemFile(file.name(), null, file.attributes());
            fsFile.url(url.toString() + "/" + file.name());
            // store file on file system
            store.save(file.content(), processId, processVersion, processInstanceId, variable.getName(), file.name());
            value = updateValue(originalValue, fsFile);
        }
    } else if (value instanceof Collection) {
        Collection<ByteArrayFile> fsFiles = new ArrayList<>();
        for (Object potentialFile : (Collection<?>) value) {
            if (potentialFile instanceof ByteArrayFile) {
                ByteArrayFile file = (ByteArrayFile) potentialFile;
                if (file.content() != null) {
                    FileSystemFile fsFile = new FileSystemFile(file.name(), null, file.attributes());
                    fsFile.url(url.toString() + "/" + file.name());
                    // store file on file system
                    store.save(file.content(), processId, processVersion, processInstanceId, variable.getName(), file.name());
                    fsFiles.add(fsFile);
                } else {
                    fsFiles.add(file);
                }
            }
        }
        return updateValue(originalValue, fsFiles);
    }
    return value;
}
Also used : Collection(java.util.Collection) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Example 3 with ByteArrayFile

use of io.automatiko.engine.workflow.file.ByteArrayFile in project automatiko-engine by automatiko-io.

the class FileSystemFileVariableAugmentor method augmentOnDelete.

@Override
public void augmentOnDelete(String processId, String processVersion, String processInstanceId, Variable variable, Object value) {
    value = retrieveValue(value);
    if (value instanceof ByteArrayFile) {
        ByteArrayFile file = (ByteArrayFile) value;
        store.remove(processId, processVersion, processInstanceId, variable.getName(), file.name());
    } else if (value instanceof Collection) {
        for (Object potentialFile : (Collection<?>) value) {
            if (potentialFile instanceof ByteArrayFile) {
                ByteArrayFile file = (ByteArrayFile) potentialFile;
                store.remove(processId, processVersion, processInstanceId, variable.getName(), file.name());
            }
        }
    }
}
Also used : Collection(java.util.Collection) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Example 4 with ByteArrayFile

use of io.automatiko.engine.workflow.file.ByteArrayFile in project automatiko-engine by automatiko-io.

the class S3FileVariableAugmentor method augmentOnUpdate.

@Override
public Object augmentOnUpdate(String processId, String processVersion, String processInstanceId, Variable variable, Object value) {
    Object originalValue = value;
    value = retrieveValue(value);
    if (value == null) {
        return value;
    }
    StringBuilder url = new StringBuilder(serviceUrl);
    url.append(processId).append("/");
    if (processVersion != null && !processVersion.isEmpty()) {
        url.append(processVersion).append("/");
    }
    url.append(processInstanceId).append("/").append(variable.getName());
    if (value instanceof ByteArrayFile) {
        ByteArrayFile file = (ByteArrayFile) value;
        if (file.content() != null) {
            S3File fsFile = new S3File(file.name(), null, file.attributes());
            fsFile.url(url.toString() + "/" + file.name());
            // replace file on file system
            store.replace(file, processId, processVersion, processInstanceId, variable.getName(), file.name());
            value = updateValue(originalValue, fsFile);
        }
    } else if (value instanceof Collection) {
        Collection<ByteArrayFile> fsFiles = new ArrayList<>();
        for (Object potentialFile : (Collection<?>) value) {
            if (potentialFile instanceof ByteArrayFile) {
                ByteArrayFile file = (ByteArrayFile) potentialFile;
                if (file.content() != null) {
                    S3File fsFile = new S3File(file.name(), null, file.attributes());
                    fsFile.url(url.toString() + "/" + file.name());
                    // replace file on file system
                    store.replace(file, processId, processVersion, processInstanceId, variable.getName(), file.name());
                    fsFiles.add(fsFile);
                } else {
                    fsFiles.add(file);
                }
            }
        }
        return updateValue(originalValue, fsFiles);
    }
    return value;
}
Also used : Collection(java.util.Collection) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Example 5 with ByteArrayFile

use of io.automatiko.engine.workflow.file.ByteArrayFile in project automatiko-engine by automatiko-io.

the class S3FileVariableAugmentor method augmentOnCreate.

@Override
public Object augmentOnCreate(String processId, String processVersion, String processInstanceId, Variable variable, Object value) {
    Object originalValue = value;
    value = retrieveValue(value);
    if (value == null) {
        return value;
    }
    StringBuilder url = new StringBuilder(serviceUrl);
    url.append(processId).append("/");
    if (processVersion != null && !processVersion.isEmpty()) {
        url.append(processVersion).append("/");
    }
    url.append(processInstanceId).append("/").append(variable.getName());
    if (value instanceof ByteArrayFile) {
        ByteArrayFile file = (ByteArrayFile) value;
        if (file.content() != null) {
            S3File fsFile = new S3File(file.name(), null, file.attributes());
            fsFile.url(url.toString() + "/" + file.name());
            // store file on file system
            store.save(file, processId, processVersion, processInstanceId, variable.getName(), file.name());
            value = updateValue(originalValue, fsFile);
        }
    } else if (value instanceof Collection) {
        Collection<ByteArrayFile> fsFiles = new ArrayList<>();
        for (Object potentialFile : (Collection<?>) value) {
            if (potentialFile instanceof ByteArrayFile) {
                ByteArrayFile file = (ByteArrayFile) potentialFile;
                if (file.content() != null) {
                    S3File fsFile = new S3File(file.name(), null, file.attributes());
                    fsFile.url(url.toString() + "/" + file.name());
                    // store file on file system
                    store.save(file, processId, processVersion, processInstanceId, variable.getName(), file.name());
                    fsFiles.add(fsFile);
                } else {
                    fsFiles.add(file);
                }
            }
        }
        return updateValue(originalValue, fsFiles);
    }
    return value;
}
Also used : Collection(java.util.Collection) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Aggregations

ByteArrayFile (io.automatiko.engine.workflow.file.ByteArrayFile)16 Collection (java.util.Collection)11 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 File (io.automatiko.engine.api.workflow.files.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 ObjectMarshallingStrategy (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy)1 ServiceExecutionError (io.automatiko.engine.api.workflow.ServiceExecutionError)1 Variable (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 DataHandler (javax.activation.DataHandler)1 TypeConversionException (org.apache.camel.TypeConversionException)1 Attachment (org.apache.camel.attachment.Attachment)1 MailMessage (org.apache.camel.component.mail.MailMessage)1