Skip to content

Commit

Permalink
Merge pull request #116 from jobyjames1/main
Browse files Browse the repository at this point in the history
refactor: migrate UDM enum to reference tables #106
  • Loading branch information
shah authored Jun 30, 2023
2 parents ea69fb4 + 87bd8b8 commit 5007d01
Show file tree
Hide file tree
Showing 14 changed files with 1,064 additions and 421 deletions.
71 changes: 66 additions & 5 deletions examples/infra-assurance/ia-example.omc.sqla.fixture.puml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,62 @@
FontSize 12
}

entity "party_role" as party_role {
**party_role_id**: INTEGER
--
* code: TEXT
* value: TEXT
created_at: TIMESTAMP
created_by: TEXT
updated_at: TIMESTAMP
updated_by: TEXT
deleted_at: TIMESTAMP
deleted_by: TEXT
activity_log: TEXT
}

entity "party_identifier_type" as party_identifier_type {
**party_identifier_type_id**: INTEGER
--
* code: TEXT
* value: TEXT
created_at: TIMESTAMP
created_by: TEXT
updated_at: TIMESTAMP
updated_by: TEXT
deleted_at: TIMESTAMP
deleted_by: TEXT
activity_log: TEXT
}

entity "person_type" as person_type {
**person_type_id**: INTEGER
--
* code: TEXT
* value: TEXT
created_at: TIMESTAMP
created_by: TEXT
updated_at: TIMESTAMP
updated_by: TEXT
deleted_at: TIMESTAMP
deleted_by: TEXT
activity_log: TEXT
}

entity "contact_type" as contact_type {
**contact_type_id**: INTEGER
--
* code: TEXT
* value: TEXT
created_at: TIMESTAMP
created_by: TEXT
updated_at: TIMESTAMP
updated_by: TEXT
deleted_at: TIMESTAMP
deleted_by: TEXT
activity_log: TEXT
}

entity "organization_role_type" as organization_role_type {
**organization_role_type_id**: INTEGER
--
Expand Down Expand Up @@ -145,7 +201,7 @@
**party_identifier_id**: INTEGER
--
* identifier_number: TEXT
* party_identifier_type_id: TEXT
* party_identifier_type_id: INTEGER
* party_id: INTEGER
created_at: TIMESTAMP
created_by: TEXT
Expand All @@ -160,7 +216,7 @@
**person_id**: INTEGER
--
* party_id: INTEGER
* person_type_id: TEXT
* person_type_id: INTEGER
* person_first_name: TEXT
* person_last_name: TEXT
honorific_prefix: TEXT
Expand All @@ -180,7 +236,7 @@
* party_id: INTEGER
* related_party_id: INTEGER
* relation_type_id: TEXT
party_role_id: TEXT
party_role_id: INTEGER
created_at: TIMESTAMP
created_by: TEXT
updated_at: TIMESTAMP
Expand Down Expand Up @@ -224,7 +280,7 @@
entity "contact_electronic" as contact_electronic {
**contact_electronic_id**: INTEGER
--
* contact_type_id: TEXT
* contact_type_id: INTEGER
* party_id: INTEGER
* electronics_details: TEXT
created_at: TIMESTAMP
Expand All @@ -239,7 +295,7 @@
entity "contact_land" as contact_land {
**contact_land_id**: INTEGER
--
* contact_type_id: TEXT
* contact_type_id: INTEGER
* party_id: INTEGER
* address_line1: TEXT
* address_line2: TEXT
Expand Down Expand Up @@ -898,15 +954,20 @@
graph |o..o{ boundary
host |o..o{ host_boundary
boundary |o..o{ raci_matrix_subject_boundary
party_identifier_type |o..o{ party_identifier
party |o..o{ party_identifier
party |o..o{ person
person_type |o..o{ person
party |o..o{ party_relation
party |o..o{ party_relation
party_role |o..o{ party_relation
party |o..o{ organization
person |o..o{ organization_role
organization |o..o{ organization_role
organization_role_type |o..o{ organization_role
contact_type |o..o{ contact_electronic
party |o..o{ contact_electronic
contact_type |o..o{ contact_land
party |o..o{ contact_land
organization |o..o{ asset
vulnerability_source |o..o{ vulnerability
Expand Down
185 changes: 112 additions & 73 deletions examples/infra-assurance/ia-example.omc.sqla.fixture.sh

Large diffs are not rendered by default.

185 changes: 112 additions & 73 deletions examples/infra-assurance/ia-example.omc.sqla.fixture.sql

Large diffs are not rendered by default.

57 changes: 36 additions & 21 deletions examples/infra-assurance/ia-example.omc.sqla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export type Person =
PersonGM,
"person_first_name" | "person_last_name"
>
& Partial<Pick<PersonGM, "person_type_id">>
// & Partial<Pick<PersonGM, "person_type_id">>
& {
person_type_id?: emit.SqlTextSupplier<emit.SqlEmitContext>;
}
& Pick<
ContactLandGM,
| "address_line1"
Expand Down Expand Up @@ -185,6 +188,7 @@ type OrganizationRole = OrganizationType & {
person_id: emit.SqlTextSupplier<emit.SqlEmitContext>;
organization_id: emit.SqlTextSupplier<emit.SqlEmitContext>;
organization_role_type_id: emit.SqlTextSupplier<emit.SqlEmitContext>;
party_role_id?: emit.SqlTextSupplier<emit.SqlEmitContext>;
};
type PartyRelation = PartyRole & OrganizationRole & {
party_id: emit.SqlTextSupplier<emit.SqlEmitContext>;
Expand All @@ -199,24 +203,31 @@ const person = {
party_type_id: "PERSON",
});
const partyIdSS = udm.party.select(partyDML.insertable);
const personTypeId = person.person_type_id
? person.person_type_id
: "INDIVIDUAL";
const personDML = udm.person.insertDML({
party_id: udm.party.select(partyDML.insertable),
person_first_name: person.person_first_name,
person_last_name: person.person_last_name,
person_type_id: person.person_type_id
? person.person_type_id
: "INDIVIDUAL",
person_type_id: udm.personType.select({
code: personTypeId,
}),
});
const personIdSS = udm.person.select(personDML.insertable);
const contactElectronicDML = {
email: udm.contactElectronic.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "OFFICIAL_EMAIL",
contact_type_id: udm.contactType.select({
code: "OFFICIAL_EMAIL",
}),
electronics_details: person.email_address,
}),
phoneNumber: udm.contactElectronic.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "MOBILE_PHONE_NUMBER",
contact_type_id: udm.contactType.select({
code: "MOBILE_PHONE_NUMBER",
}),
electronics_details: person.phone_number,
}),
ALL: () =>
Expand All @@ -227,7 +238,9 @@ const person = {
};
const contactLandDML = udm.contactLand.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "OFFICIAL_ADDRESS",
contact_type_id: udm.contactType.select({
code: "OFFICIAL_ADDRESS",
}),
address_line1: person.address_line1,
address_line2: person.address_line2 ? person.address_line2 : "",
address_city: person.address_city,
Expand Down Expand Up @@ -297,12 +310,16 @@ const organization = {
const contactElectronicDML = {
email: udm.contactElectronic.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "OFFICIAL_EMAIL",
contact_type_id: udm.contactType.select({
code: "OFFICIAL_EMAIL",
}),
electronics_details: organization.email_address,
}),
phoneNumber: udm.contactElectronic.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "LAND_PHONE_NUMBER",
contact_type_id: udm.contactType.select({
code: "LAND_PHONE_NUMBER",
}),
electronics_details: organization.phone_number,
}),
ALL: () =>
Expand All @@ -313,7 +330,9 @@ const organization = {
};
const contactLandDML = udm.contactLand.insertDML({
party_id: udm.party.select(partyDML.insertable),
contact_type_id: "OFFICIAL_ADDRESS",
contact_type_id: udm.contactType.select({
code: "OFFICIAL_ADDRESS",
}),
address_line1: organization.address_line1,
address_line2: organization.address_line2
? organization.address_line2
Expand Down Expand Up @@ -352,13 +371,16 @@ const personToOrganizationRelation = {
insertDML: (
partyRelation: PartyRelation,
) => {
const partyRoleId = partyRelation.party_role_id
? partyRelation.party_role_id
: "VENDOR";
const partyRelationDML = udm.partyRelation.insertDML({
party_id: partyRelation.party_id,
related_party_id: partyRelation.related_party_id,
relation_type_id: "ORGANIZATION_TO_PERSON",
party_role_id: partyRelation.party_role_id
? partyRelation.party_role_id
: "VENDOR",
party_role_id: udm.partyRole.select({
code: partyRoleId,
}),
});
const oraganizationRoleDML = udm.organizationRole.insertDML({
person_id: partyRelation.person_id,
Expand All @@ -375,12 +397,6 @@ const personToOrganizationRelation = {
},
};

const organizationRoleTypeInsertion = udm.organizationRoleType
.insertDML({
code: "LEAD_SOFTWARE_ENGINEER",
value: "Lead Software Engineer",
});

const organizationRoleTypeCode = udm.organizationRoleType.select({
code: "LEAD_SOFTWARE_ENGINEER",
});
Expand Down Expand Up @@ -500,8 +516,7 @@ const personDetailsSkill = {
${personDetailsSkill.oracle}
${personDetailsSkill.java}
${personDetailsSkill.jQuery}
${personDetailsSkill.osQuery}
${organizationRoleTypeInsertion}`,
${personDetailsSkill.osQuery}`,
};

const organizationToPersonAllRelations = {
Expand Down
67 changes: 63 additions & 4 deletions pattern/infra-assurance/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export const allReferenceTables: (
)[] = [
udm.execCtx,
udm.partyType,
udm.partyRole,
contractStatus,
paymentType,
periodicity,
Expand Down Expand Up @@ -287,9 +286,6 @@ export const allReferenceTables: (
auditPurpose,
auditorStatusType,
udm.partyRelationType,
udm.partyIdentifierType,
udm.personType,
udm.contactType,
trainingSubject,
statusValues,
ratingValue,
Expand Down Expand Up @@ -876,6 +872,10 @@ export const allContentTables: SQLa.TableDefinition<
udm.EmitContext,
typ.TypicalDomainQS
>[] = [
udm.partyRole,
udm.partyIdentifierType,
udm.personType,
udm.contactType,
udm.organizationRoleType,
graph,
boundary,
Expand Down Expand Up @@ -1241,6 +1241,57 @@ const vendorView = SQLa.safeViewDefinition(
INNER JOIN contact_land l ON l.party_id = pr.party_id AND l.contact_type_id = 'OFFICIAL_ADDRESS'
WHERE prl.party_role_id = 'VENDOR' AND prl.relation_type_id = 'ORGANIZATION_TO_PERSON'`;

const partyRoleInsertion = udm
.partyRole.insertDML([{
code: "CUSTOMER",
value: "Customer",
}, {
code: "VENDOR",
value: "Vendor",
}]);

const partyIdentifierTypeInsertion = udm
.partyIdentifierType.insertDML([{
code: "UUID",
value: "UUID",
}, {
code: "DRIVING_LICENSE",
value: "Driving License",
}, {
code: "PASSPORT",
value: "Passport",
}]);

const personTypeInsertion = udm
.personType.insertDML([{
code: "INDIVIDUAL",
value: "Individual",
}, {
code: "PROFESSIONAL",
value: "Professional",
}]);

const contactTypeInsertion = udm
.contactType.insertDML([{
code: "HOME_ADDRESS",
value: "Home Address",
}, {
code: "OFFICIAL_ADDRESS",
value: "Official Address",
}, {
code: "MOBILE_PHONE_NUMBER",
value: "Mobile Phone Number",
}, {
code: "LAND_PHONE_NUMBER",
value: "Land Phone Number",
}, {
code: "OFFICIAL_EMAIL",
value: "Official Email",
}, {
code: "PERSONAL_EMAIL",
value: "Personal Email",
}]);

const organizationRoleTypeInsertion = udm
.organizationRoleType.insertDML([{
code: "PROJECT_MANAGER_TECHNOLOGY",
Expand Down Expand Up @@ -1368,6 +1419,14 @@ export function sqlDDL() {
-- seed Data
${allReferenceTables.map(e => e.seedDML).flat()}
${partyRoleInsertion}
${partyIdentifierTypeInsertion}
${personTypeInsertion}
${contactTypeInsertion}
${organizationRoleTypeInsertion}
`;
}
Expand Down
Loading

0 comments on commit 5007d01

Please sign in to comment.