Search in sources :

Example 1 with ByteArrayResource

use of io.automatiko.engine.services.io.ByteArrayResource in project automatiko-engine by automatiko-io.

the class DecisionCodegen method ofPath.

public static DecisionCodegen ofPath(List<String> dependencies, Path... paths) throws IOException {
    List<DMNResource> resources = new ArrayList<>();
    for (String dependency : dependencies) {
        List<Resource> dmnresources = new ArrayList<>();
        File file = new File(dependency);
        if (file.isDirectory()) {
            Path srcPath = file.toPath();
            if (Files.exists(srcPath)) {
                try (Stream<Path> filesStream = Files.walk(srcPath)) {
                    List<File> files = filesStream.filter(p -> p.toString().endsWith(".dmn")).map(Path::toFile).collect(Collectors.toList());
                    resources.addAll(parseFiles(srcPath, files));
                }
            }
        } else {
            try (ZipFile zipFile = new ZipFile(dependency)) {
                Enumeration<? extends ZipEntry> entries = zipFile.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = entries.nextElement();
                    if (entry.getName().endsWith(".dmn")) {
                        InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                        resource.setSourcePath(entry.getName());
                        dmnresources.add(resource);
                    }
                }
            } catch (IOException e) {
            }
            resources.addAll(parseDecisions(Paths.get(dependency), dmnresources));
        }
    }
    for (Path path : paths) {
        Path srcPath = Paths.get(path.toString());
        if (Files.exists(srcPath)) {
            try (Stream<Path> filesStream = Files.walk(srcPath)) {
                List<File> files = filesStream.filter(p -> p.toString().endsWith(".dmn")).map(Path::toFile).collect(Collectors.toList());
                resources.addAll(parseFiles(srcPath, files));
            }
        }
    }
    return ofDecisions(resources);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Resource(io.automatiko.engine.api.io.Resource) FileSystemResource(io.automatiko.engine.services.io.FileSystemResource) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) InternalResource(io.automatiko.engine.services.io.InternalResource) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipFile(java.util.zip.ZipFile) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) File(java.io.File)

Example 2 with ByteArrayResource

use of io.automatiko.engine.services.io.ByteArrayResource in project automatiko-engine by automatiko-io.

the class DecisionCodegen method ofJar.

public static DecisionCodegen ofJar(List<String> dependencies, Path... jarPaths) throws IOException {
    List<DMNResource> dmnResources = new ArrayList<>();
    for (Path jarPath : jarPaths) {
        List<Resource> resources = new ArrayList<>();
        try (ZipFile zipFile = new ZipFile(jarPath.toFile())) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().endsWith(".dmn")) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setSourcePath(entry.getName());
                    resources.add(resource);
                }
            }
        }
        dmnResources.addAll(parseDecisions(jarPath, resources));
    }
    for (String dependency : dependencies) {
        List<Resource> resources = new ArrayList<>();
        try (ZipFile zipFile = new ZipFile(dependency)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().endsWith(".dmn")) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setSourcePath(entry.getName());
                    resources.add(resource);
                }
            }
        } catch (IOException e) {
        }
        dmnResources.addAll(parseDecisions(Paths.get(dependency), resources));
    }
    return ofDecisions(dmnResources);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Resource(io.automatiko.engine.api.io.Resource) FileSystemResource(io.automatiko.engine.services.io.FileSystemResource) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) InternalResource(io.automatiko.engine.services.io.InternalResource) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile)

Example 3 with ByteArrayResource

use of io.automatiko.engine.services.io.ByteArrayResource in project automatiko-engine by automatiko-io.

the class ProcessCodegen method ofPath.

public static ProcessCodegen ofPath(List<String> dependencies, Path... paths) throws IOException {
    List<Process> allProcesses = new ArrayList<>();
    for (String dependency : dependencies) {
        File file = new File(dependency);
        if (file.isDirectory()) {
            try (Stream<Path> filesStream = Files.walk(file.toPath())) {
                List<File> files = filesStream.filter(p -> SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(p.toString()::endsWith) || SUPPORTED_SW_EXTENSIONS.keySet().stream().anyMatch(p.toString()::endsWith)).map(Path::toFile).collect(Collectors.toList());
                allProcesses.addAll(parseProcesses(files, true));
            }
        } else {
            try (ZipFile zipFile = new ZipFile(dependency)) {
                Enumeration<? extends ZipEntry> entries = zipFile.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = entries.nextElement();
                    ResourceType resourceType = determineResourceType(entry.getName());
                    if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                        InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                        resource.setResourceType(resourceType);
                        resource.setSourcePath(entry.getName());
                        allProcesses.addAll(parseProcessFile(resource));
                    }
                }
            } catch (IOException e) {
            }
        }
    }
    for (Path path : paths) {
        Path srcPath = Paths.get(path.toString());
        try (Stream<Path> filesStream = Files.walk(srcPath)) {
            List<File> files = filesStream.filter(p -> SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(p.toString()::endsWith) || SUPPORTED_SW_EXTENSIONS.keySet().stream().anyMatch(p.toString()::endsWith)).map(Path::toFile).collect(Collectors.toList());
            allProcesses.addAll(parseProcesses(files, false));
        }
    }
    return ofProcesses(allProcesses);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) ResourceType(io.automatiko.engine.api.io.ResourceType) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipFile(java.util.zip.ZipFile) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) File(java.io.File)

Example 4 with ByteArrayResource

use of io.automatiko.engine.services.io.ByteArrayResource in project automatiko-engine by automatiko-io.

the class ProcessCodegen method ofJar.

public static ProcessCodegen ofJar(List<String> dependencies, Path... jarPaths) {
    List<Process> processes = new ArrayList<>();
    for (Path jarPath : jarPaths) {
        try (ZipFile zipFile = new ZipFile(jarPath.toFile())) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    for (String dependency : dependencies) {
        try (ZipFile zipFile = new ZipFile(dependency)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
        }
    }
    return ofProcesses(processes);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) ResourceType(io.automatiko.engine.api.io.ResourceType) UncheckedIOException(java.io.UncheckedIOException) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile)

Aggregations

ByteArrayResource (io.automatiko.engine.services.io.ByteArrayResource)4 InternalResource (io.automatiko.engine.services.io.InternalResource)4 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 Process (io.automatiko.engine.api.definition.process.Process)2 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)2 Resource (io.automatiko.engine.api.io.Resource)2 ResourceType (io.automatiko.engine.api.io.ResourceType)2 ResourceType.determineResourceType (io.automatiko.engine.api.io.ResourceType.determineResourceType)2 GeneratedFile (io.automatiko.engine.codegen.GeneratedFile)2 FileSystemResource (io.automatiko.engine.services.io.FileSystemResource)2 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2