This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 048ced98086 kie-issues#1271: Retrieve process definitions from data 
index instead of openapi.json (#2377)
048ced98086 is described below

commit 048ced98086d1bbed859abaf7f0f3dc3b808c7fc
Author: Paulo Martins <[email protected]>
AuthorDate: Tue May 28 14:21:08 2024 -0300

    kie-issues#1271: Retrieve process definitions from data index instead of 
openapi.json (#2377)
---
 .../ProcessDefinitionListContextProvider.tsx       | 15 +++---
 .../ProcessDefinitionListGatewayApi.ts             | 12 ++---
 .../ProcessDefinitionListQueries.ts                | 38 +++++++++++++++
 .../components/DevUI/DevUILayout/DevUILayout.tsx   |  2 +-
 .../components/ProcessDetails/ProcessDetails.tsx   |  2 +-
 .../src/gatewayApi/apis.tsx                        | 55 +++++++++-------------
 .../src/graphql/types.tsx                          |  9 ++++
 7 files changed, 84 insertions(+), 49 deletions(-)

diff --git 
a/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListContextProvider.tsx
 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListContextProvider.tsx
index b91c3ccc880..2b3788fd23f 100644
--- 
a/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListContextProvider.tsx
+++ 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListContextProvider.tsx
@@ -20,19 +20,20 @@ import React, { useMemo } from "react";
 import { DevUIAppContext, useDevUIAppContext } from 
"../../components/contexts/DevUIAppContext";
 import ProcessDefinitionListContext from "./ProcessDefinitionListContext";
 import { ProcessDefinitionListGatewayApiImpl } from 
"./ProcessDefinitionListGatewayApi";
+import { ApolloClient } from "apollo-client";
+import { GraphQLProcessDefinitionListQueries } from 
"./ProcessDefinitionListQueries";
 
 interface ProcessDefinitionListContextProviderProps {
+  apolloClient: ApolloClient<any>;
   children;
 }
 
-const ProcessDefinitionListContextProvider: 
React.FC<ProcessDefinitionListContextProviderProps> = ({ children }) => {
-  const runtimeToolsApi: DevUIAppContext = useDevUIAppContext();
-
+const ProcessDefinitionListContextProvider: 
React.FC<ProcessDefinitionListContextProviderProps> = ({
+  apolloClient,
+  children,
+}) => {
   const gatewayApiImpl = useMemo(() => {
-    return new ProcessDefinitionListGatewayApiImpl(
-      runtimeToolsApi.getRemoteKogitoAppUrl() ?? runtimeToolsApi.getDevUIUrl(),
-      runtimeToolsApi.getOpenApiPath()
-    );
+    return new ProcessDefinitionListGatewayApiImpl(new 
GraphQLProcessDefinitionListQueries(apolloClient));
   }, []);
 
   return (
diff --git 
a/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListGatewayApi.ts
 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListGatewayApi.ts
index 33ce5d8b47e..09fa21a432c 100644
--- 
a/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListGatewayApi.ts
+++ 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListGatewayApi.ts
@@ -18,7 +18,7 @@
  */
 
 import { ProcessDefinition } from 
"@kie-tools/runtime-tools-process-gateway-api/dist/types";
-import { getProcessDefinitionList } from 
"@kie-tools/runtime-tools-process-gateway-api/dist/gatewayApi";
+import { ProcessDefinitionListQueries } from "./ProcessDefinitionListQueries";
 
 export interface ProcessDefinitionListGatewayApi {
   getProcessDefinitionFilter: () => Promise<string[]>;
@@ -46,13 +46,11 @@ export class ProcessDefinitionListGatewayApiImpl implements 
ProcessDefinitionLis
   private readonly onOpenProcessListeners: OnOpenProcessFormListener[] = [];
   private readonly onOpenTriggerCloudEventListeners: 
OnOpenTriggerCloudEventListener[] = [];
 
-  private readonly kogitoAppUrl: string;
-  private readonly openApiPath: string;
+  private readonly queries: ProcessDefinitionListQueries;
   private processDefinitionFilter: string[] = [];
 
-  constructor(url: string, path: string) {
-    this.kogitoAppUrl = url;
-    this.openApiPath = path;
+  constructor(queries: ProcessDefinitionListQueries) {
+    this.queries = queries;
   }
 
   getProcessDefinitionFilter(): Promise<string[]> {
@@ -100,7 +98,7 @@ export class ProcessDefinitionListGatewayApiImpl implements 
ProcessDefinitionLis
   }
 
   getProcessDefinitionsQuery(): Promise<ProcessDefinition[]> {
-    return getProcessDefinitionList(this.kogitoAppUrl, this.openApiPath);
+    return this.queries.getProcessDefinitions();
   }
 
   openTriggerCloudEvent(): void {
diff --git 
a/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListQueries.ts
 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListQueries.ts
new file mode 100644
index 00000000000..7acdbcdb2b7
--- /dev/null
+++ 
b/packages/runtime-tools-process-dev-ui-webapp/src/channel/ProcessDefinitionList/ProcessDefinitionListQueries.ts
@@ -0,0 +1,38 @@
+/**
+ * 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.
+ */
+import { ApolloClient } from "apollo-client";
+import { ProcessDefinition } from 
"@kie-tools/runtime-tools-process-gateway-api/dist/types";
+import { getProcessDefinitions } from 
"@kie-tools/runtime-tools-process-gateway-api/dist/gatewayApi";
+import { OperationType } from 
"@kie-tools/runtime-tools-shared-gateway-api/dist/types";
+
+export interface ProcessDefinitionListQueries {
+  getProcessDefinitions(): Promise<ProcessDefinition[]>;
+}
+
+export class GraphQLProcessDefinitionListQueries implements 
ProcessDefinitionListQueries {
+  private readonly client: ApolloClient<any>;
+
+  constructor(client: ApolloClient<any>) {
+    this.client = client;
+  }
+
+  getProcessDefinitions(): Promise<ProcessDefinition[]> {
+    return getProcessDefinitions(this.client);
+  }
+}
diff --git 
a/packages/runtime-tools-process-dev-ui-webapp/src/components/DevUI/DevUILayout/DevUILayout.tsx
 
b/packages/runtime-tools-process-dev-ui-webapp/src/components/DevUI/DevUILayout/DevUILayout.tsx
index a213ba7dd05..a21816cdb04 100755
--- 
a/packages/runtime-tools-process-dev-ui-webapp/src/components/DevUI/DevUILayout/DevUILayout.tsx
+++ 
b/packages/runtime-tools-process-dev-ui-webapp/src/components/DevUI/DevUILayout/DevUILayout.tsx
@@ -90,7 +90,7 @@ const DevUILayout: React.FC<IOwnProps> = ({
             <ProcessListContextProvider apolloClient={apolloClient}>
               <ProcessDetailsContextProvider apolloClient={apolloClient}>
                 <JobsManagementContextProvider apolloClient={apolloClient}>
-                  <ProcessDefinitionListContextProvider>
+                  <ProcessDefinitionListContextProvider 
apolloClient={apolloClient}>
                     <FormsListContextProvider>
                       <FormDetailsContextProvider>
                         <ProcessFormContextProvider>
diff --git 
a/packages/runtime-tools-process-enveloped-components/src/processDetails/envelope/components/ProcessDetails/ProcessDetails.tsx
 
b/packages/runtime-tools-process-enveloped-components/src/processDetails/envelope/components/ProcessDetails/ProcessDetails.tsx
index df83fd3b576..0de3359300c 100644
--- 
a/packages/runtime-tools-process-enveloped-components/src/processDetails/envelope/components/ProcessDetails/ProcessDetails.tsx
+++ 
b/packages/runtime-tools-process-enveloped-components/src/processDetails/envelope/components/ProcessDetails/ProcessDetails.tsx
@@ -320,7 +320,7 @@ const ProcessDetails: React.FC<ProcessDetailsProps> = ({
   const renderProcessVariables = (): JSX.Element => {
     return (
       <Flex direction={{ default: "column" }} flex={{ default: "flex_1" }}>
-        {Object.keys(updateJson).length > 0 && (
+        {updateJson && Object.keys(updateJson).length > 0 && (
           <FlexItem>
             <ProcessVariables
               displayLabel={displayLabel}
diff --git a/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx 
b/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx
index 002e605d9b3..17c52c84882 100644
--- a/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx
+++ b/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx
@@ -511,39 +511,28 @@ export const saveFormContent = (formName: string, 
content: FormContent): Promise
   });
 };
 
-export const createProcessDefinitionList = (processDefinitionObjs: any, url: 
string): ProcessDefinition[] => {
-  const processDefinitionList: ProcessDefinition[] = [];
-  processDefinitionObjs.forEach((processDefObj: any) => {
-    const processName = Object.keys(processDefObj)[0].split("/")[1];
-    const endpoint = `${url}/${processName}`;
-    processDefinitionList.push({
-      processName,
-      endpoint,
-    });
-  });
-  return processDefinitionList;
-};
-
-export const getProcessDefinitionList = (kogitoAppUrl: string, openApiPath: 
string): Promise<ProcessDefinition[]> => {
-  return new Promise((resolve, reject) => {
-    SwaggerParser.parse(`${kogitoAppUrl}/${openApiPath.replace(/^\//, "")}`)
-      .then((response) => {
-        const processDefinitionObjs: any = [];
-        const paths = response.paths;
-        const regexPattern = /^\/[^\n/]+\/schema/;
-        Object.getOwnPropertyNames(paths)
-          .filter((path) => regexPattern.test(path.toString()))
-          .forEach((url) => {
-            let processArray = url.split("/");
-            processArray = processArray.filter((name) => name.length !== 0);
-            /* istanbul ignore else*/
-            if 
(Object.prototype.hasOwnProperty.call(paths[`/${processArray[0]}`], "post")) {
-              processDefinitionObjs.push({ [url]: paths[url] });
-            }
-          });
-        resolve(createProcessDefinitionList(processDefinitionObjs, 
kogitoAppUrl));
-      })
-      .catch((err) => reject(err));
+export const getProcessDefinitions = (client: ApolloClient<any>): 
Promise<ProcessDefinition[]> => {
+  return new Promise<ProcessDefinition[]>((resolve, reject) => {
+    client
+      .query({
+        query: GraphQL.GetProcessDefinitionsDocument,
+        fetchPolicy: "network-only",
+        errorPolicy: "all",
+      })
+      .then((value) => {
+        const processDefinitions = value.data.ProcessDefinitions;
+        resolve(
+          value.data.ProcessDefinitions.map((item: { id: string; endpoint: 
string }) => {
+            return {
+              processName: item.id,
+              endpoint: item.endpoint,
+            };
+          })
+        );
+      })
+      .catch((reason) => {
+        reject({ errorMessage: JSON.stringify(reason) });
+      });
   });
 };
 
diff --git a/packages/runtime-tools-process-gateway-api/src/graphql/types.tsx 
b/packages/runtime-tools-process-gateway-api/src/graphql/types.tsx
index 502ff4e5110..609a31320fa 100644
--- a/packages/runtime-tools-process-gateway-api/src/graphql/types.tsx
+++ b/packages/runtime-tools-process-gateway-api/src/graphql/types.tsx
@@ -1425,6 +1425,15 @@ export namespace GraphQL {
 
   export type HandleJobRescheduleMutation = { __typename?: "Mutation"; 
JobReschedule?: string | null };
 
+  export const GetProcessDefinitionsDocument = gql`
+    query getProcessDefinitions {
+      ProcessDefinitions {
+        id
+        endpoint
+      }
+    }
+  `;
+
   export const GetProcessInstancesDocument = gql`
     query getProcessInstances(
       $where: ProcessInstanceArgument


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to