Skip to content

Commit

Permalink
KOGITO-10047: Enable SWF Dev UI extension for Quarkus 3
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovmr committed Feb 7, 2024
1 parent 553d178 commit e9d197b
Show file tree
Hide file tree
Showing 8 changed files with 9,312 additions and 3,090 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/dev-static/webapp</outputDirectory>
<outputDirectory>${basedir}/target/classes/dev-static/resources/webapp</outputDirectory>
<resources>
<resource>
<directory>${path.to.webapp.app}/dist/resources/webapp</directory>
Expand All @@ -143,14 +143,15 @@
</resources>
</configuration>
</execution>

<execution>
<id>copy-envelope-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/dev-static/</outputDirectory>
<outputDirectory>${basedir}/target/classes/dev-static/resources</outputDirectory>
<resources>
<resource>
<directory>${path.to.webapp.app}/dist/resources</directory>
Expand All @@ -175,6 +176,25 @@
</resources>
</configuration>
</execution>

<execution>
<id>copy-index</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/dev-static</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/classes/static</directory>
<includes>
<include>index.html</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.kie.kogito.swf.tools.deployment;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Path;
import java.util.Optional;

Expand All @@ -30,22 +32,57 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ConfigurationBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.deployment.util.WebJarUtil;
import io.quarkus.devconsole.spi.DevConsoleTemplateInfoBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.runtime.devmode.DevConsoleRecorder;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;

public class DevConsoleProcessor {

private static final String STATIC_RESOURCES_PATH = "dev-static/";
private static final String BASE_RELATIVE_URL = "/q/dev-v1/org.kie.kogito.kogito-quarkus-serverless-workflow-devui";
private static final String DATA_INDEX_CAPABILITY = "org.kie.kogito.data-index";

@BuildStep(onlyIf = IsDevelopment.class)
public CardPageBuildItem pages(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
LaunchModeBuildItem launchModeBuildItem,
ConfigurationBuildItem configurationBuildItem) throws UnsupportedEncodingException {

String uiPath = nonApplicationRootPathBuildItem.resolveManagementPath(BASE_RELATIVE_URL,
managementInterfaceBuildTimeConfig, launchModeBuildItem, true);

String devUIUrl = getProperty(configurationBuildItem, "kogito.dev-ui.url");
String devUIUrlQueryParam = devUIUrl != null ? "&devUIUrl=" + URLEncoder.encode(devUIUrl, "UTF-8") : "";

String dataIndexUrl = getProperty(configurationBuildItem, "kogito.data-index.url");
String dataIndexUrlQueryParam = dataIndexUrl != null ? "&dataIndexUrl=" + URLEncoder.encode(dataIndexUrl, "UTF-8") : "";

CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();

cardPageBuildItem.addPage(Page.externalPageBuilder("Workflows")
.url(uiPath + "/index.html?page=Processes" + devUIUrlQueryParam + dataIndexUrlQueryParam, uiPath)
.isHtmlContent()
.icon("font-awesome-solid:diagram-project"));

cardPageBuildItem.addPage(Page.externalPageBuilder("Monitoring")
.url(uiPath + "/index.html?page=Monitoring" + devUIUrlQueryParam + dataIndexUrlQueryParam, uiPath)
.isHtmlContent()
.icon("font-awesome-solid:gauge-high"));

return cardPageBuildItem;
}

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.RUNTIME_INIT)
public void deployStaticResources(final DevConsoleRecorder recorder,
Expand All @@ -66,12 +103,6 @@ public void deployStaticResources(final DevConsoleRecorder recorder,
STATIC_RESOURCES_PATH,
true);

routeBuildItemBuildProducer.produce(new RouteBuildItem.Builder()
.route(BASE_RELATIVE_URL + "/resources/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(),
shutdownContext))
.build());

routeBuildItemBuildProducer.produce(new RouteBuildItem.Builder()
.route(BASE_RELATIVE_URL + "/*")
.handler(recorder.devConsoleHandler(devConsoleStaticResourcesDeploymentPath.toString(),
Expand All @@ -87,4 +118,31 @@ public void isDataIndexAvailable(BuildProducer<DevConsoleTemplateInfoBuildItem>
devConsoleTemplateInfoBuildItemBuildProducer.produce(new DevConsoleTemplateInfoBuildItem("isDataIndexAvailable",
dataIndexServiceAvailableBuildItem.isPresent() || capabilities.isPresent(DATA_INDEX_CAPABILITY)));
}

private static String getProperty(ConfigurationBuildItem configurationBuildItem,
String propertyKey) {

String propertyValue = configurationBuildItem
.getReadResult()
.getAllBuildTimeValues()
.get(propertyKey);

if (propertyValue == null) {
propertyValue = configurationBuildItem
.getReadResult()
.getBuildTimeRunTimeValues()
.get(propertyKey);
} else {
return propertyValue;
}

if (propertyValue == null) {
propertyValue = configurationBuildItem
.getReadResult()
.getRunTimeDefaultValues()
.get(propertyKey);
}

return propertyValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<div id="envelope-app"></div>

<script src="resources/webapp/standalone.js"></script>
<script>
const urlParams = new URLSearchParams(window.location.search);
const page = urlParams.get("page");
const devUIUrl = urlParams.get("devUIUrl");
const dataIndexUrl = urlParams.get("dataIndexUrl");

const devUI = RuntimeToolsDevUI.open({
container: document.getElementById("envelope-app"),
isDataIndexAvailable: true,
dataIndexUrl: dataIndexUrl ? dataIndexUrl : "" + "/graphql",
page: page,
devUIUrl: devUIUrl ? devUIUrl : window.location.origin,
openApiPath: "q/openapi.json",
availablePages: ["Processes", "Monitoring", "CustomDashboard"],
customLabels: {
singularProcessLabel: "Workflow",
pluralProcessLabel: "Workflows",
},
omittedProcessTimelineEvents: ["EmbeddedStart", "EmbeddedEnd", "Script"],
diagramPreviewSize: {
width: 1000,
height: 1000,
},
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ private void start(final URL classLoaderCustomDashboardUrl, final URL customDash
} catch (Exception ex) {
LOGGER.warn("Couldn't properly initialize CustomDashboardStorageImpl");
} finally {
if (classLoaderCustomDashboardUrl == null) {
return;
}

init(readCustomDashboardResources());
String storageUrl = getStorageUrl(classLoaderCustomDashboardUrl);
Thread t = new Thread(new DashboardFilesWatcher(reload(), storageUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"mini-css-extract-plugin": "^2.7.6",
"node-polyfill-webpack-plugin": "^2.0.1",
"nodemon": "^2.0.22",
"openapi-types": "^9.3.1",
"openapi-types": "^7.0.1",
"raw-loader": "^4.0.2",
"rimraf": "^3.0.2",
"sass-loader": "^12.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/

import { OpenAPI } from 'openapi-types';
import { GraphQL } from '@kogito-apps/consoles-common/dist/graphql';
import {
BulkProcessInstanceActionResponse,
Expand Down Expand Up @@ -542,38 +544,50 @@ export const getCustomDashboardContent = (name: string): Promise<string> => {
});
};

export const getCustomWorkflowSchema = (
export const getCustomWorkflowSchemaFromApi = async (
api: OpenAPI.Document,
workflowName: string
): Promise<Record<string, any>> => {
let schema = {};

try {
const schemaFromRequestBody =
api.paths['/' + workflowName].post.requestBody.content['application/json']
.schema;

if (schemaFromRequestBody.type) {
schema = {
type: schemaFromRequestBody.type,
properties: schemaFromRequestBody.properties
};
} else {
schema = (api as any).components.schemas[workflowName + '_input'];
}
} catch (e) {
console.log(e);
schema = (api as any).components.schemas[workflowName + '_input'];
}

// Components can contain the content of internal refs ($ref)
// This keeps the refs working while avoiding circular refs with the workflow itself
if (schema) {
const { [workflowName + '_input']: _, ...schemas } =
(api as any).components?.schemas ?? {};
(schema as any)['components'] = { schemas };
}

return schema ?? null;
};

export const getCustomWorkflowSchema = async (
devUIUrl: string,
openApiPath: string,
workflowName: string
): Promise<Record<string, any>> => {
return new Promise((resolve, reject) => {
SwaggerParser.parse(`${devUIUrl}/${openApiPath}`)
.then((response: any) => {
let schema = {};
try {
const schemaFromRequestBody =
response.paths['/' + workflowName].post.requestBody.content[
'application/json'
].schema;
/* istanbul ignore else*/
if (schemaFromRequestBody.type) {
schema = {
type: schemaFromRequestBody.type,
properties: schemaFromRequestBody.properties
};
} else {
schema = response.components.schemas[workflowName + '_input'];
}
} catch (e) {
console.log(e);
schema = response.components.schemas[workflowName + '_input'];
}
if (schema) {
resolve(schema);
} else {
resolve(null);
}
.then(async (response: any) => {
resolve(await getCustomWorkflowSchemaFromApi(response, workflowName));
})
.catch((err) => reject(err));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ describe('swf custom form tests', () => {

it('get custom workflow schema - success - with workflowdata', async () => {
const schema = {
components: {
schemas: {}
},
type: 'object',
properties: {
name: {
Expand Down
Loading

0 comments on commit e9d197b

Please sign in to comment.