Skip to content

Commit

Permalink
update LocalMappingPropertyInfo.localMappingPropertyType to use refer…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
akphi committed May 10, 2022
1 parent 9030a54 commit bf902e2
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-lies-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
---

Update `LocalMappingPropertyInfo` metamodel to have `localMappingPropertyType: PackageableElementReference<Type>`
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const observe_LocalMappingPropertyInfo = skipObserved(
hashCode: computed,
});

// TODO localMappingPropertyType!: Type;
observe_PackageableElementReference(metamodel.localMappingPropertyType);
observe_Multiplicity(metamodel.localMappingPropertyMultiplicity);

return metamodel;
Expand Down
9 changes: 9 additions & 0 deletions packages/legend-graph/src/models/metamodels/pure/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ export abstract class ReferenceWithOwner extends RequiredReference {
this.ownerReference = ownerReference;
}
}

export abstract class OptionalReferenceWithOwner extends OptionalReference {
readonly ownerReference: OptionalReference;

protected constructor(ownerReference: OptionalReference) {
super();
this.ownerReference = ownerReference;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import { hashArray, type Hashable } from '@finos/legend-shared';
import type { Multiplicity } from '../domain/Multiplicity';
import type { Type } from '../domain/Type';
import { CORE_HASH_STRUCTURE } from '../../../../../MetaModelConst';
import type { PackageableElementReference } from '../PackageableElementReference';

export class LocalMappingPropertyInfo implements Hashable {
localMappingProperty!: boolean;
// TODO: refactor this to use `PackageableElementReference`
localMappingPropertyType!: Type;
localMappingPropertyType!: PackageableElementReference<Type>;
localMappingPropertyMultiplicity!: Multiplicity;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.LOCAL_MAPPING_PROPERTY,
this.localMappingPropertyType.path,
this.localMappingPropertyType.hashValue,
this.localMappingPropertyMultiplicity,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,21 @@ export abstract class PropertyMapping implements Hashable, Stubable {
readonly _isEmbedded: boolean = false;

property: PropertyReference;
// NOTE: in case the holder of this property mapping is an embedded property mapping, that embedded property mapping is considered the source
// otherwise, it is always the top/root `InstanceSetImplementation` that is considered the source implementation
// TODO: change this to use `SetImplemenetationReference`
/**
* NOTE: in case the holder of this property mapping is an embedded property mapping,
* that embedded property mapping is considered the source otherwise, it is always
* the top/root `InstanceSetImplementation` that is considered the source implementation
*
* TODO: change this to use `SetImplemenetationReference`
*/
sourceSetImplementation: SetImplementation;
// NOTE: in Pure, we actually only store `targetId` and `sourceId` instead of the reference
// but for convenience and graph completeness validation purpose we will resolve to the actual set implementations here
// TODO: change this to use `OptionalSetImplemenetationReference`
/**
* NOTE: in Pure, we actually only store `targetId` and `sourceId` instead of the
* reference but for convenience and graph completeness validation purpose we will
* resolve to the actual set implementations here
*
* TODO: change this to use `OptionalSetImplemenetationReference`
*/
targetSetImplementation?: SetImplementation | undefined;
localMappingProperty?: LocalMappingPropertyInfo | undefined;
// store?: Store | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
*/

import {
PackageableElementExplicitReference,
type PackageableElementReference,
type PackageableElementImplicitReference,
type OptionalPackageableElementImplicitReference,
type PackageableElementReference,
type OptionalPackageableElementReference,
PackageableElementExplicitReference,
OptionalPackageableElementExplicitReference,
} from '../PackageableElementReference';
import type { Mapping } from './Mapping';
import type { SetImplementation } from './SetImplementation';
import { ReferenceWithOwner } from '../../Reference';
import {
OptionalReferenceWithOwner,
ReferenceWithOwner,
} from '../../Reference';

export abstract class SetImplementationReference extends ReferenceWithOwner {
override readonly ownerReference: PackageableElementReference<Mapping>;
Expand Down Expand Up @@ -71,3 +77,57 @@ export class SetImplementationImplicitReference extends SetImplementationReferen
return new SetImplementationImplicitReference(ownerReference, value);
}
}

export abstract class OptionalSetImplementationReference extends OptionalReferenceWithOwner {
override readonly ownerReference: OptionalPackageableElementReference<Mapping>;
value?: SetImplementation | undefined;

protected constructor(
ownerReference: OptionalPackageableElementReference<Mapping>,
value: SetImplementation | undefined,
) {
super(ownerReference);
this.ownerReference = ownerReference;
this.value = value;
}
}

export class OptionalSetImplementationExplicitReference extends OptionalSetImplementationReference {
override readonly ownerReference: OptionalPackageableElementReference<Mapping>;

private constructor(value: SetImplementation | undefined) {
const ownerReference = OptionalPackageableElementExplicitReference.create(
value?._PARENT,
);
super(ownerReference, value);
this.ownerReference = ownerReference;
}

static create(
value: SetImplementation,
): OptionalSetImplementationExplicitReference {
return new OptionalSetImplementationExplicitReference(value);
}
}

export class OptionalSetImplementationImplicitReference extends OptionalSetImplementationReference {
override readonly ownerReference: OptionalPackageableElementReference<Mapping>;

private constructor(
ownerReference: OptionalPackageableElementImplicitReference<Mapping>,
value: SetImplementation | undefined,
) {
super(ownerReference, value);
this.ownerReference = ownerReference;
}

static create(
ownerReference: PackageableElementImplicitReference<Mapping>,
value: SetImplementation,
): OptionalSetImplementationImplicitReference {
return new OptionalSetImplementationImplicitReference(
ownerReference,
value,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ const transformLocalPropertyInfo = (
value: LocalMappingPropertyInfo,
): V1_LocalMappingPropertyInfo => {
const localPropertyInfo = new V1_LocalMappingPropertyInfo();
localPropertyInfo.type = value.localMappingPropertyType.path;
localPropertyInfo.type =
value.localMappingPropertyType.valueForSerialization ?? '';
localPropertyInfo.multiplicity = V1_transformMultiplicity(
value.localMappingPropertyMultiplicity,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
localMapping.localMappingPropertyMultiplicity = _multiplicity;
localMapping.localMappingPropertyType = this.context.resolveType(
localMappingProperty.type,
).value;
);
} else {
assertNonEmptyString(
protocol.property.class,
Expand Down Expand Up @@ -478,7 +478,7 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
localMapping.localMappingPropertyMultiplicity = _multiplicity;
localMapping.localMappingPropertyType = this.context.resolveType(
localMappingProperty.type,
).value;
);
propertyOwner = property._OWNER;
} else {
if (this.immediateParent instanceof AssociationImplementation) {
Expand Down

0 comments on commit bf902e2

Please sign in to comment.