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; children; } -const ProcessDefinitionListContextProvider: React.FC = ({ children }) => { - const runtimeToolsApi: DevUIAppContext = useDevUIAppContext(); - +const ProcessDefinitionListContextProvider: React.FC = ({ + 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; @@ -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 { @@ -100,7 +98,7 @@ export class ProcessDefinitionListGatewayApiImpl implements ProcessDefinitionLis } getProcessDefinitionsQuery(): Promise { - 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; +} + +export class GraphQLProcessDefinitionListQueries implements ProcessDefinitionListQueries { + private readonly client: ApolloClient; + + constructor(client: ApolloClient) { + this.client = client; + } + + getProcessDefinitions(): Promise { + 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 = ({ - + 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 = ({ const renderProcessVariables = (): JSX.Element => { return ( - {Object.keys(updateJson).length > 0 && ( + {updateJson && Object.keys(updateJson).length > 0 && ( { - 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 => { - 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): Promise => { + return new Promise((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