use of org.kie.kogito.codegen.decision.events.DecisionCloudEventMetaFactoryGenerator in project kogito-runtimes by kiegroup.
the class DecisionCodegen method generateAndStoreRestResources.
private void generateAndStoreRestResources() {
// REST resources
List<DecisionRestResourceGenerator> rgs = new ArrayList<>();
List<DMNModel> models = resources.stream().map(DMNResource::getDmnModel).collect(Collectors.toList());
DMNOASResult oasResult = null;
try {
oasResult = DMNOASGeneratorFactory.generator(models).build();
String jsonContent = new ObjectMapper().writeValueAsString(oasResult.getJsonSchemaNode());
storeFile(GeneratedFileType.STATIC_HTTP_RESOURCE, "dmnDefinitions.json", jsonContent);
} catch (Exception e) {
LOGGER.error("Error while trying to generate OpenAPI specification for the DMN models", e);
}
for (DMNModel model : models) {
if (model.getName() == null || model.getName().isEmpty()) {
throw new RuntimeException("Model name should not be empty");
}
boolean stronglyTypedEnabled = Optional.ofNullable(context()).flatMap(c -> c.getApplicationProperty(STRONGLY_TYPED_CONFIGURATION_KEY)).map(Boolean::parseBoolean).orElse(false);
if (stronglyTypedEnabled) {
generateStronglyTypedInput(model);
}
DecisionRestResourceGenerator resourceGenerator = new DecisionRestResourceGenerator(context(), model, applicationCanonicalName()).withStronglyTyped(stronglyTypedEnabled).withOASResult(oasResult, isMPAnnotationsPresent(), isIOSwaggerOASv3AnnotationsPresent());
rgs.add(resourceGenerator);
}
if (context().hasRESTForGenerator(this)) {
for (DecisionRestResourceGenerator resourceGenerator : rgs) {
if (context().getAddonsConfig().usePrometheusMonitoring()) {
generateAndStoreGrafanaDashboards(resourceGenerator);
}
storeFile(REST_TYPE, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
}
}
DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
for (DMNResource resource : resources) {
DMNModel model = resource.getDmnModel();
Definitions definitions = model.getDefinitions();
for (DRGElement drg : definitions.getDrgElement()) {
if (drg instanceof Decision) {
Decision decision = (Decision) drg;
decision.setExpression(null);
} else if (drg instanceof BusinessKnowledgeModel) {
BusinessKnowledgeModel bkm = (BusinessKnowledgeModel) drg;
bkm.setEncapsulatedLogic(null);
}
}
String relativePath = CodegenStringUtil.escapeIdentifier(model.getNamespace()).replace(".", "/") + "/" + CodegenStringUtil.escapeIdentifier(model.getName()) + ".dmn_nologic";
storeFile(GeneratedFileType.INTERNAL_RESOURCE, relativePath, marshaller.marshal(definitions));
}
if (context().getAddonsConfig().useCloudEvents()) {
final DecisionCloudEventMetaFactoryGenerator ceMetaFactoryGenerator = new DecisionCloudEventMetaFactoryGenerator(context(), models);
storeFile(REST_TYPE, ceMetaFactoryGenerator.generatedFilePath(), ceMetaFactoryGenerator.generate());
}
}
Aggregations