Skip to content

Commit

Permalink
fix(orchestrator): only inputs inherited from the assessment workflow…
Browse files Browse the repository at this point in the history
… should be disabled 🍒 (#1443)

fix(orchestrator): only inputs inherited from the assessment workflow should be disabled (#1436)
  • Loading branch information
caponetto authored Apr 3, 2024
1 parent 2b4faad commit 8e9298d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('workflow input schema response', () => {
expect(response.schemaSteps[0].title).toEqual('Data Input Schema');
});

it('composed schema also wihtout refs should return multiple steps', () => {
it('composed schema also without refs should return multiple steps', () => {
const response = service.getWorkflowInputSchemaResponse(
mockComposedGreetingWorkflowData.workflowDefinition,
mockComposedGreetingWorkflowData.schema,
Expand Down Expand Up @@ -117,4 +117,86 @@ describe('workflow input schema response', () => {
});
expect(response.schemaSteps[0].readonlyKeys).toEqual(['language', 'name']);
});

it('using assessment variables on composed schema should return read only keys', () => {
const newComponentValues = {
orgName: 'org.example',
repoName: 'example',
description: 'example description',
};
const response = service.getWorkflowInputSchemaResponse(
mockSpringBootWorkflowData.workflowDefinition,
mockSpringBootWorkflowData.schema,
undefined,
{
workflowdata: {
newComponent: newComponentValues,
},
},
);
expect(response.isComposedSchema).toEqual(true);
expect(response.schemaSteps[0].data).toEqual(newComponentValues);
expect(response.schemaSteps[0].readonlyKeys).toEqual(
Object.keys(newComponentValues),
);
});

it('using initial workflow and assessment variables should return read only keys', () => {
const response = service.getWorkflowInputSchemaResponse(
mockGreetingWorkflowData.workflowDefinition,
mockGreetingWorkflowData.schema,
{
workflowdata: {
name: 'John Doe',
language: 'Spanish',
},
},
{
workflowdata: {
name: 'John Doe',
waitOrError: 'Error',
},
},
);
expect(response.isComposedSchema).toEqual(false);
expect(response.schemaSteps[0].data).toEqual({
language: 'Spanish',
name: 'John Doe',
});
expect(response.schemaSteps[0].readonlyKeys).toEqual(['name']);
});

it('using initial workflow and assessment variables on composed schema should return read only keys', () => {
const newComponentValues = {
orgName: 'org.example',
repoName: 'example',
description: 'example description',
};
const javaMetadataValues = {
groupId: 'org.example',
artifactId: 'example',
version: '1.0.0',
};
const response = service.getWorkflowInputSchemaResponse(
mockSpringBootWorkflowData.workflowDefinition,
mockSpringBootWorkflowData.schema,
{
workflowdata: {
newComponent: newComponentValues,
javaMetadata: javaMetadataValues,
},
},
{
workflowdata: {
newComponent: newComponentValues,
},
},
);
expect(response.isComposedSchema).toEqual(true);
expect(response.schemaSteps[0].data).toEqual(newComponentValues);
expect(response.schemaSteps[1].data).toEqual(javaMetadataValues);
expect(response.schemaSteps[0].readonlyKeys).toEqual(
Object.keys(newComponentValues),
);
});
});
51 changes: 41 additions & 10 deletions plugins/orchestrator-backend/src/service/DataInputSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,25 @@ export class DataInputSchemaService {

private getInputSchemaSteps(
schema: ComposedSchema,
isAssessment: boolean,
workflowData?: JsonObject,
assessmentWorkflowData?: JsonObject,
): WorkflowInputSchemaStep[] {
return Object.entries(schema.properties).map(([key, curSchema]) => {
const data = (workflowData?.[key] as JsonObject) ?? {};
const data = this.extractInnerProperty(workflowData, key);
const assessmentData = this.extractInnerProperty(
assessmentWorkflowData,
key,
);
const assessmentInitialState = this.extractInitialStateFromWorkflowData(
assessmentData,
curSchema.properties,
);
return {
title: curSchema.title || key,
key,
schema: curSchema,
data,
readonlyKeys: isAssessment ? Object.keys(data) : [],
readonlyKeys: this.extractObjectKeys(assessmentInitialState),
};
});
}
Expand All @@ -91,11 +99,11 @@ export class DataInputSchemaService {
instanceVariables?: ProcessInstanceVariables,
assessmentInstanceVariables?: ProcessInstanceVariables,
): WorkflowInputSchemaResponse {
const variables = instanceVariables ?? assessmentInstanceVariables;
const isAssessment = !!assessmentInstanceVariables;
const workflowData = variables
? (variables[WORKFLOW_DATA_KEY] as JsonObject)
: undefined;
const instanceWorkflowData = this.extractWorkflowData(instanceVariables);
const assessmentInstanceWorkflowData = this.extractWorkflowData(
assessmentInstanceVariables,
);
const workflowData = instanceWorkflowData ?? assessmentInstanceWorkflowData;

const res: WorkflowInputSchemaResponse = {
definition,
Expand All @@ -115,8 +123,8 @@ export class DataInputSchemaService {
if (isComposedSchema(resolvedSchema)) {
res.schemaSteps = this.getInputSchemaSteps(
resolvedSchema,
isAssessment,
workflowData,
assessmentInstanceWorkflowData,
);
res.isComposedSchema = true;
} else {
Expand All @@ -126,13 +134,19 @@ export class DataInputSchemaService {
resolvedSchema.properties,
)
: {};
const assessmentData =
assessmentInstanceWorkflowData &&
this.extractInitialStateFromWorkflowData(
assessmentInstanceWorkflowData,
resolvedSchema.properties,
);
res.schemaSteps = [
{
schema: resolvedSchema,
title: resolvedSchema.title ?? SINGLE_SCHEMA_TITLE,
key: SINGLE_SCHEMA_KEY,
data,
readonlyKeys: isAssessment ? Object.keys(data) : [],
readonlyKeys: this.extractObjectKeys(assessmentData),
},
];
}
Expand All @@ -144,4 +158,21 @@ export class DataInputSchemaService {
}
return res;
}

private extractWorkflowData(
variables?: ProcessInstanceVariables,
): JsonObject | undefined {
return variables ? (variables[WORKFLOW_DATA_KEY] as JsonObject) : undefined;
}

private extractObjectKeys(obj: JsonObject | undefined): string[] {
return obj ? Object.keys(obj) : [];
}

private extractInnerProperty(
obj: JsonObject | undefined,
key: string,
): JsonObject {
return (obj?.[key] as JsonObject) ?? {};
}
}

0 comments on commit 8e9298d

Please sign in to comment.