Skip to content

Commit

Permalink
Revert "replace businessKey (#157)" (#303)
Browse files Browse the repository at this point in the history
This reverts commit 1ab4ae4.
  • Loading branch information
ydayagi authored Jan 21, 2025
1 parent be2c6d8 commit 50ccb2c
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 413 deletions.
6 changes: 0 additions & 6 deletions workspaces/orchestrator/.changeset/good-wasps-double.md

This file was deleted.

5 changes: 0 additions & 5 deletions workspaces/orchestrator/.changeset/silly-horses-glow.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('fetchInstances', () => {
definitionIds,
)}`;
const queryBody =
'id, processName, processId, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}';
'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}';

const mockProcessInstances: ProcessInstance[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Red Hat, Inc.
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { LoggerService } from '@backstage/backend-plugin-api';

import { Client, fetchExchange, gql } from '@urql/core';
Expand Down Expand Up @@ -300,7 +299,7 @@ export class DataIndexService {
const graphQlQuery = buildGraphQlQuery({
type: 'ProcessInstances',
queryBody:
'id, processName, processId, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',
'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',
whereClause,
pagination,
});
Expand Down Expand Up @@ -457,6 +456,7 @@ export class DataIndexService {
processName
processId
serviceUrl
businessKey
state
start
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class OrchestratorService {
definitionId: string;
serviceUrl: string;
inputData?: ProcessInstanceVariables;
businessKey?: string;
cacheHandler?: CacheHandler;
}): Promise<WorkflowExecutionResponse | undefined> {
const { definitionId, cacheHandler } = args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ describe('SonataFlowService', () => {
expect(loggerMock.child).not.toHaveBeenCalled();
});

it('should include businessKey in the URL if provided', async () => {
// Given
const businessKey = 'key-123';
setupTest({ ok: true, json: { id: definitionId, status: 'completed' } });

// When
const result = await sonataFlowService.executeWorkflow({
definitionId,
serviceUrl,
inputData,
businessKey,
});

// Then
expect(fetch).toHaveBeenCalledWith(
`${serviceUrl}/${definitionId}?businessKey=${businessKey}`,
expectedFetchRequestInit(),
);
expect(result).toEqual({ id: definitionId, status: 'completed' });
});
it('should propagate thrown error when the fetch response is not ok without extra info', async () => {
// When
setupTest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ export class SonataFlowService {
definitionId: string;
serviceUrl: string;
inputData?: ProcessInstanceVariables;
businessKey?: string;
}): Promise<WorkflowExecutionResponse | undefined> {
const urlToFetch = `${args.serviceUrl}/${args.definitionId}`;
const urlToFetch = args.businessKey
? `${args.serviceUrl}/${args.definitionId}?businessKey=${args.businessKey}`
: `${args.serviceUrl}/${args.definitionId}`;

const response = await fetch(urlToFetch, {
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Red Hat, Inc.
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import moment from 'moment';

import {
Expand Down Expand Up @@ -134,6 +133,7 @@ export function mapToProcessInstanceDTO(
processName: processInstance.processName,
description: processInstance.description,
serviceUrl: processInstance.serviceUrl,
businessKey: processInstance.businessKey,
endpoint: processInstance.endpoint,
error: processInstance.error,
category: mapWorkflowCategoryDTO(processInstance.category),
Expand All @@ -142,7 +142,6 @@ export function mapToProcessInstanceDTO(
duration: duration,
// @ts-ignore
workflowdata: variables?.workflowdata,
assessmentInstanceId: variables?.orchestratorAssessmentInstanceId as string,
state: processInstance.state
? getProcessInstancesStatusDTOFromString(processInstance.state)
: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright Red Hat, Inc.
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Request } from 'express';

import {
Expand Down Expand Up @@ -377,6 +376,7 @@ describe('executeWorkflow', () => {
const actualResultV2: ExecuteWorkflowResponseDTO = await v2.executeWorkflow(
workflowData,
workflowInfo.id,
'businessKey',
);

// Assert
Expand Down Expand Up @@ -484,14 +484,9 @@ describe('getInstanceById', () => {

it('Instance exists, assessment non empty string', async () => {
const processInstance = generateProcessInstance(1);
processInstance.businessKey = 'testBusinessKey';
const assessedBy = generateProcessInstance(1);
if (
processInstance.variables &&
typeof processInstance.variables !== 'string'
) {
processInstance.variables.orchestratorAssessmentInstanceId =
assessedBy.id;
}
assessedBy.id = processInstance.businessKey;

(mockOrchestratorService.fetchInstance as jest.Mock)
.mockResolvedValueOnce(processInstance)
Expand All @@ -506,6 +501,9 @@ describe('getInstanceById', () => {
expect(processInstanceV2).toBeDefined();
expect(processInstanceV2.instance).toBeDefined();
expect(processInstanceV2.assessedBy).toBeDefined();
expect(processInstanceV2.assessedBy?.id).toEqual(
processInstance.businessKey,
);
expect(processInstanceV2.instance.id).toEqual(processInstance.id);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ProcessInstance,
ProcessInstanceListResultDTO,
ProcessInstanceState,
ProcessInstanceVariables,
WorkflowDTO,
WorkflowInfo,
WorkflowOverviewDTO,
Expand Down Expand Up @@ -140,16 +141,9 @@ export class V2 {

let assessedByInstance: ProcessInstance | undefined;

let variables: Record<string, unknown> | undefined;
if (typeof instance.variables === 'string') {
variables = JSON.parse(instance?.variables);
} else {
variables = instance.variables;
}

if (includeAssessment && variables?.orchestratorAssessmentInstanceId) {
if (includeAssessment && instance.businessKey) {
assessedByInstance = await this.orchestratorService.fetchInstance({
instanceId: variables.orchestratorAssessmentInstanceId as string,
instanceId: instance.businessKey,
cacheHandler: 'throw',
});
}
Expand All @@ -165,6 +159,7 @@ export class V2 {
public async executeWorkflow(
executeWorkflowRequestDTO: ExecuteWorkflowRequestDTO,
workflowId: string,
businessKey: string | undefined,
): Promise<ExecuteWorkflowResponseDTO> {
const definition = await this.orchestratorService.fetchWorkflowInfo({
definitionId: workflowId,
Expand All @@ -178,12 +173,10 @@ export class V2 {
}
const executionResponse = await this.orchestratorService.executeWorkflow({
definitionId: workflowId,
inputData: {
workflowdata: executeWorkflowRequestDTO.inputData,
orchestratorAssessmentInstanceId:
executeWorkflowRequestDTO.orchestratorAssessmentInstanceId,
},
inputData:
executeWorkflowRequestDTO.inputData as ProcessInstanceVariables,
serviceUrl: definition.serviceUrl,
businessKey,
cacheHandler: 'throw',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
orchestratorWorkflowSpecificPermission,
orchestratorWorkflowUsePermission,
orchestratorWorkflowUseSpecificPermission,
QUERY_PARAM_BUSINESS_KEY,
QUERY_PARAM_INCLUDE_ASSESSMENT,
WorkflowOverviewListResultDTO,
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
Expand Down Expand Up @@ -482,10 +483,15 @@ function setupInternalRoutes(
manageDenyAuthorization(endpointName, endpoint, req);
}

const businessKey = routerApi.v2.extractQueryParam(
c.request,
QUERY_PARAM_BUSINESS_KEY,
);

const executeWorkflowRequestDTO = req.body;

return routerApi.v2
.executeWorkflow(executeWorkflowRequestDTO, workflowId)
.executeWorkflow(executeWorkflowRequestDTO, workflowId, businessKey)
.then(result => res.status(200).json(result))
.catch(error => {
auditLogRequestError(error, endpointName, endpoint, req);
Expand Down
Loading

0 comments on commit 50ccb2c

Please sign in to comment.