Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#1271: Retrieve process definitions from data index instead of openapi.json #2377

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]>;
Expand Down Expand Up @@ -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[]> {
Expand Down Expand Up @@ -100,7 +98,7 @@ export class ProcessDefinitionListGatewayApiImpl implements ProcessDefinitionLis
}

getProcessDefinitionsQuery(): Promise<ProcessDefinition[]> {
return getProcessDefinitionList(this.kogitoAppUrl, this.openApiPath);
return this.queries.getProcessDefinitions();
}

openTriggerCloudEvent(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
});
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading