use of io.automatiko.engine.api.io.Resource 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);
}
use of io.automatiko.engine.api.io.Resource 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);
}
use of io.automatiko.engine.api.io.Resource in project automatiko-engine by automatiko-io.
the class DmnRuntimeProvider method fromResources.
private static Either<Exception, DMNRuntime> fromResources(Collection<org.kie.api.io.Resource> resources) {
ExtendedDMNProfile profile = new ExtendedDMNProfile();
DMNCompilerConfigurationImpl cc = new DMNCompilerConfigurationImpl();
cc.addExtensions(profile.getExtensionRegisters());
cc.addDRGElementCompilers(profile.getDRGElementCompilers());
cc.addFEELProfile(profile);
DMNCompiler dmnCompiler = new DMNCompilerImpl(cc);
List<DMNResource> dmnResources = new ArrayList<>();
for (org.kie.api.io.Resource r : resources) {
Definitions definitions;
try {
definitions = getMarshaller(cc).unmarshal(r.getReader());
} catch (IOException e) {
return Either.ofLeft(e);
}
DMNResource dmnResource = new DMNResource(definitions, new ResourceWithConfiguration() {
@Override
public ResourceConfiguration getResourceConfiguration() {
// TODO Auto-generated method stub
return null;
}
@Override
public org.kie.api.io.Resource getResource() {
return (org.kie.api.io.Resource) r;
}
@Override
public Consumer<Object> getBeforeAdd() {
return null;
}
@Override
public Consumer<Object> getAfterAdd() {
return null;
}
});
dmnResources.add(dmnResource);
}
DMNAssemblerService.enrichDMNResourcesWithImportsDependencies(dmnResources, Collections.emptyList());
List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
List<DMNModel> dmnModels = new ArrayList<>();
for (DMNResource dmnRes : sortedDmnResources) {
DMNModel dmnModel = dmnCompiler.compile(dmnRes.getDefinitions(), dmnRes.getResAndConfig().getResource(), dmnModels);
if (dmnModel != null) {
dmnModels.add(dmnModel);
} else {
return Either.ofLeft(new IllegalStateException("Unable to compile DMN model for the resource " + dmnRes.getResAndConfig().getResource()));
}
}
return Either.ofRight(new DMNRuntimeImpl(new DMNRuntimeKBStatic(dmnModels, Arrays.asList(profile))));
}
use of io.automatiko.engine.api.io.Resource in project automatiko-engine by automatiko-io.
the class ServerlessProcess method from.
public static List<ServerlessProcess> from(ProcessConfig config, Resource... resources) {
List<ServerlessProcess> compiled = new ArrayList<>();
ServerlessWorkflowParser parser = new ServerlessWorkflowParser();
for (Resource resource : resources) {
try {
compiled.add(new ServerlessProcess(parser.parse(resource.getReader()), config));
} catch (IOException e) {
e.printStackTrace();
}
}
return compiled;
}
use of io.automatiko.engine.api.io.Resource in project automatiko-engine by automatiko-io.
the class ClassPathResource method listResources.
public Collection<Resource> listResources() {
try {
URL url = getURL();
if ("file".equals(url.getProtocol())) {
File dir = new File(StringUtils.toURI(url.toString()).getSchemeSpecificPart());
List<Resource> resources = new ArrayList<Resource>();
for (File file : dir.listFiles()) {
resources.add(new FileSystemResource(file));
}
return resources;
}
} catch (Exception e) {
// swollow as we'll throw an exception anyway
}
throw new RuntimeException("This Resource cannot be listed, or is not a directory");
}
Aggregations