Skip to content

Commit

Permalink
Add support for mastery precedence rules (#2427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeoye Oluwatobi authored Jul 15, 2023
1 parent 01b2c64 commit 58e87d5
Show file tree
Hide file tree
Showing 19 changed files with 1,451 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-moose-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-extension-dsl-mastery': patch
---

Support for Mastery Precedence rules
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,299 @@ export const TEST_DATA__roundtrip = [
},
],
},
precedenceRules: [
{
_type: 'createRule',
masterRecordFilter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'person',
},
],
parameters: [
{
_type: 'var',
class: 'mastery::test::model::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'person',
},
],
},
paths: [
{
property: 'name',
filter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'name',
},
],
parameters: [
{
_type: 'var',
class: 'String',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'name',
},
],
},
},
],
scopes: [
{
_type: 'dataProviderIdScope',
dataProviderId: 'reuters',
},
{
_type: 'recordSourceScope',
recordSourceId: 'reuters-equity',
},
],
},
{
_type: 'deleteRule',
masterRecordFilter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'person',
},
],
parameters: [
{
_type: 'var',
class: 'mastery::test::model::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'person',
},
],
},
paths: [
{
property: 'name',
filter: {
_type: 'lambda',
body: [
{
_type: 'func',
fControl: 'equal_Any_MANY__Any_MANY__Boolean_1_',
function: 'equal',
parameters: [
{
_type: 'property',
parameters: [
{
_type: 'var',
name: 'person',
},
],
property: 'name',
},
{
_type: 'string',
value: 'tobi',
},
],
},
],
parameters: [
{
_type: 'var',
class: 'mastery::test::model::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'person',
},
],
},
},
],
scopes: [
{
_type: 'dataProviderTypeScope',
dataProviderType: 'Aggregator',
},
],
},
{
_type: 'sourcePrecedenceRule',
masterRecordFilter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'person',
},
],
parameters: [
{
_type: 'var',
class: 'mastery::test::model::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'person',
},
],
},
paths: [
{
property: 'name',
filter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'name',
},
],
parameters: [
{
_type: 'var',
class: 'String',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'name',
},
],
},
},
],
precedence: 1,
action: 'Overwrite',
scopes: [
{
_type: 'dataProviderTypeScope',
dataProviderType: 'Aggregator',
},
],
},
{
_type: 'conditionalRule',
masterRecordFilter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'person',
},
],
parameters: [
{
_type: 'var',
class: 'mastery::test::model::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'person',
},
],
},
paths: [
{
property: 'name',
filter: {
_type: 'lambda',
body: [
{
_type: 'var',
name: 'name',
},
],
parameters: [
{
_type: 'var',
class: 'String',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'name',
},
],
},
},
],
predicate: {
_type: 'lambda',
body: [
{
_type: 'func',
fControl: 'equal_Any_MANY__Any_MANY__Boolean_1_',
function: 'equal',
parameters: [
{
_type: 'property',
parameters: [
{
_type: 'var',
name: 'proposed',
},
],
property: 'name',
},
{
_type: 'property',
parameters: [
{
_type: 'var',
name: 'masterRecord',
},
],
property: 'name',
},
],
},
],
parameters: [
{
_type: 'var',
class: 'org::legend::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'proposed',
},
{
_type: 'var',
class: 'org::legend::Person',
multiplicity: {
lowerBound: 1,
upperBound: 1,
},
name: 'masterRecord',
},
],
},
scopes: [
{
_type: 'dataProviderTypeScope',
dataProviderType: 'Exchange',
},
],
},
],
sources: [
{
createBlockedException: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const observe_Mastery = skipObserved(
modelClass: observable,
identityResolution: observable,
sources: observable,
precedenceRules: observable,
_elementHashCode: override,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import packageJson from '../../../../package.json' assert { type: 'json' };
import { MasterRecordDefinition } from '../../../graph/metamodel/pure/model/packageableElements/mastery/DSL_Mastery_MasterRecordDefinition.js';
import { V1_MasterRecordDefinition } from './v1/model/packageableElements/mastery/V1_DSL_Mastery_MasterRecordDefinition.js';
import {
V1_conditionalRuleSchema,
V1_createRuleSchema,
V1_deleteRuleSchema,
V1_MASTER_RECORD_DEFINITION_ELEMENT_PROTOCOL_TYPE,
V1_masterRecordDefinitionModelSchema,
V1_sourcePrecedenceRuleSchema,
} from './v1/transformation/pureProtocol/V1_DSL_Mastery_ProtocolHelper.js';
import { V1_buildMasterRecordDefinition } from './v1/transformation/pureGraph/to/V1_DSL_Mastery_BuilderHelper.js';
import { V1_transformMasterRecordDefinition } from './v1/transformation/pureGraph/from/V1_DSL_Mastery_TransformerHelper.js';
Expand All @@ -38,11 +42,23 @@ import {
} from '@finos/legend-graph';
import { assertType, type PlainObject } from '@finos/legend-shared';
import { deserialize, serialize } from 'serializr';
import type {
DSL_Mastery_PureProtocolProcessorPlugin_Extension,
V1_PrecedenceRuleProtocolDeserializer,
V1_PrecedenceRuleProtocolSerializer,
} from './DSL_Mastery_PureProtocolProcessorPlugin_Extension.js';
import {
type V1_PrecedenceRule,
V1_RuleType,
} from './v1/model/packageableElements/mastery/V1_DSL_Mastery_PrecedenceRule.js';

export const MASTER_RECORD_DEFINITION_ELEMENT_CLASSIFIER_PATH =
'meta::pure::mastery::metamodel::MasterRecordDefinition';

export class DSL_Mastery_PureProtocolProcessorPlugin extends PureProtocolProcessorPlugin {
export class DSL_Mastery_PureProtocolProcessorPlugin
extends PureProtocolProcessorPlugin
implements DSL_Mastery_PureProtocolProcessorPlugin_Extension
{
constructor() {
super(
packageJson.extensions.pureProtocolProcessorPlugin,
Expand Down Expand Up @@ -141,4 +157,44 @@ export class DSL_Mastery_PureProtocolProcessorPlugin extends PureProtocolProcess
},
];
}

V1_getExtraPrecedenceRuleProtocolSerializers?(): V1_PrecedenceRuleProtocolSerializer[] {
return [
(
protocol: V1_PrecedenceRule,
): PlainObject<V1_PrecedenceRule> | undefined => {
switch (protocol._type) {
case V1_RuleType.CREATE_RULE:
return serialize(V1_createRuleSchema, protocol);
case V1_RuleType.CONDITIONAL_RULE:
return serialize(V1_conditionalRuleSchema, protocol);
case V1_RuleType.SOURCE_PRECEDENCE_RULE:
return serialize(V1_sourcePrecedenceRuleSchema, protocol);
case V1_RuleType.DELETE_RULE:
return serialize(V1_deleteRuleSchema, protocol);
default:
return undefined;
}
},
];
}

V1_getExtraPrecedenceRuleProtocolDeserializers?(): V1_PrecedenceRuleProtocolDeserializer[] {
return [
(json: PlainObject<V1_PrecedenceRule>): V1_PrecedenceRule | undefined => {
switch (json._type) {
case V1_RuleType.CREATE_RULE:
return deserialize(V1_createRuleSchema, json);
case V1_RuleType.CONDITIONAL_RULE:
return deserialize(V1_conditionalRuleSchema, json);
case V1_RuleType.SOURCE_PRECEDENCE_RULE:
return deserialize(V1_sourcePrecedenceRuleSchema, json);
case V1_RuleType.DELETE_RULE:
return deserialize(V1_deleteRuleSchema, json);
default:
return undefined;
}
},
];
}
}
Loading

0 comments on commit 58e87d5

Please sign in to comment.