Skip to content

Commit

Permalink
add parameter multiplicity validation for service registration (#1538)
Browse files Browse the repository at this point in the history
* Add a parameter multiplicity validation for service registration

improve condition and error messages

improve error message

add a comparator for multiplicity

* add one changeset
  • Loading branch information
irisyngao authored Oct 10, 2022
1 parent a6830b4 commit 34d6f9d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changeset/seven-flowers-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
5 changes: 5 additions & 0 deletions .changeset/strong-lions-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-application-studio': patch
---

Add service parameter multiplicity validation during service registration ([#1539](https://github.com/finos/legend-studio/issues/1539)).
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ import {
getNullableFirstElement,
assertTrue,
URL_SEPARATOR,
filterByType,
} from '@finos/legend-shared';
import { LEGEND_STUDIO_APP_EVENT } from '../../../LegendStudioAppEvent.js';
import { Version } from '@finos/legend-server-sdlc';
import {
type Service,
type ServiceRegistrationResult,
type PureExecution,
ServiceExecutionMode,
buildLambdaVariableExpressions,
VariableExpression,
TYPICAL_MULTIPLICITY_TYPE,
generateMultiplicityString,
multiplicityComparator,
} from '@finos/legend-graph';
import { ServiceRegistrationEnvironmentConfig } from '../../../../application/LegendStudioApplicationConfig.js';
import {
Expand Down Expand Up @@ -314,5 +321,37 @@ export class ServiceRegistrationState {
'Service version can not be empty in Semi-interactive and Prod service type',
);
}

// validate service parameter multiplicities
const supportedServiceParamMultiplicties = [
TYPICAL_MULTIPLICITY_TYPE.ONE,
TYPICAL_MULTIPLICITY_TYPE.ZEROMANY,
TYPICAL_MULTIPLICITY_TYPE.ZEROONE,
].map((p) =>
this.editorStore.graphManagerState.graph.getTypicalMultiplicity(p),
);
const invalidParams = buildLambdaVariableExpressions(
(this.service.execution as PureExecution).func,
this.editorStore.graphManagerState,
)
.filter(filterByType(VariableExpression))
.filter(
(p) =>
!supportedServiceParamMultiplicties.some((m) =>
multiplicityComparator(m, p.multiplicity),
),
);
assertTrue(
invalidParams.length === 0,
`Parameter(s)${invalidParams.map(
(p) =>
` ${p.name}: [${generateMultiplicityString(
p.multiplicity.lowerBound,
p.multiplicity.upperBound,
)}]`,
)} has/have unsupported multiplicity. Supported multiplicities include ${supportedServiceParamMultiplicties.map(
(m) => ` [${generateMultiplicityString(m.lowerBound, m.upperBound)}]`,
)}.`,
);
}
}
6 changes: 6 additions & 0 deletions packages/legend-graph/src/graph/helpers/DomainHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ export const getMultiplicityDescription = (
}`;
};

export const multiplicityComparator = (
mul1: Multiplicity,
mul2: Multiplicity,
): boolean =>
mul1.upperBound === mul2.upperBound && mul1.lowerBound === mul2.lowerBound;

export const isElementDeprecated = (
element: AnnotatedElement | Class,
graph: PureModel,
Expand Down

0 comments on commit 34d6f9d

Please sign in to comment.