From 16d9d5ad7e825205c9890a2a5680b241f133fa17 Mon Sep 17 00:00:00 2001 From: sanket Shevkar <43399522+sanketshevkar@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:11:58 +0530 Subject: [PATCH] bug(common): include derived types in dependency graph (#90) * bug(common): include derived types in dependency graph Signed-off-by: Sanket Shevkar * bug(common): include derived types in dependency graph Signed-off-by: Sanket Shevkar --------- Signed-off-by: Sanket Shevkar Co-authored-by: Sanket Shevkar --- lib/common/graph.js | 20 ++++++++++-- test/common/graph.js | 77 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/lib/common/graph.js b/lib/common/graph.js index 774f0627..7d6370e7 100644 --- a/lib/common/graph.js +++ b/lib/common/graph.js @@ -143,12 +143,22 @@ class DirectedGraph { */ print(writer) { writer.writeLine(0, 'flowchart LR'); + const diagramNodeSet = new Set(); Object.entries(this.adjacencyMap).forEach(([source, edges]) =>{ - writer.writeLine(1, `\`${source}\``); + diagramNodeSet.add( `\`${source}\``); (edges || []).forEach(target => { - writer.writeLine(1, `\`${source}\` --> \`${target}\``); + const setEntry = `\`${source}\` --> \`${target}\``; + if(diagramNodeSet.has(`\`${target}\` --> \`${source}\``)) { + diagramNodeSet.delete(`\`${target}\` --> \`${source}\``); + diagramNodeSet.add(`\`${source}\` <--> \`${target}\``); + } else { + diagramNodeSet.add(setEntry); + } }); }); + diagramNodeSet.forEach((diagramNode) => { + writer.writeLine(1, diagramNode); + }); } } @@ -174,8 +184,12 @@ class ConcertoGraphVisitor extends DiagramVisitor { if (classDeclaration.getSuperType()){ parameters.graph.addEdge(classDeclaration.getFullyQualifiedName(), classDeclaration.getSuperType()); + // this "if" block adds the types that extend the Super type + if(classDeclaration.getSuperType() !== 'concerto@1.0.0.Concept') { + parameters.graph.addVertex(classDeclaration.getSuperType()); + parameters.graph.addEdge(classDeclaration.getSuperType(), classDeclaration.getFullyQualifiedName()); + } } - super.visitClassDeclaration(classDeclaration, parameters); parameters.stack.pop(); } diff --git a/test/common/graph.js b/test/common/graph.js index 65fd5742..fb87eb74 100644 --- a/test/common/graph.js +++ b/test/common/graph.js @@ -95,39 +95,42 @@ describe('graph', function () { \`org.acme.hr@1.0.0.Department\` \`org.acme.hr@1.0.0.Department\` --> \`concerto@1.0.0.Concept\` \`org.acme.hr@1.0.0.Equipment\` - \`org.acme.hr@1.0.0.Equipment\` --> \`concerto@1.0.0.Asset\` + \`concerto@1.0.0.Asset\` + \`concerto@1.0.0.Asset\` <--> \`org.acme.hr@1.0.0.Equipment\` \`org.acme.hr@1.0.0.LaptopMake\` \`org.acme.hr@1.0.0.LaptopMake\` --> \`concerto@1.0.0.Concept\` \`org.acme.hr@1.0.0.Laptop\` - \`org.acme.hr@1.0.0.Laptop\` --> \`org.acme.hr@1.0.0.Equipment\` + \`org.acme.hr@1.0.0.Laptop\` <--> \`org.acme.hr@1.0.0.Equipment\` \`org.acme.hr@1.0.0.Laptop\` --> \`org.acme.hr@1.0.0.LaptopMake\` \`org.acme.hr@1.0.0.Person\` - \`org.acme.hr@1.0.0.Person\` --> \`concerto@1.0.0.Participant\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr.base@1.0.0.Address\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr.base@1.0.0.SSN\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr@1.0.0.NextOfKin\` + \`concerto@1.0.0.Participant\` + \`concerto@1.0.0.Participant\` <--> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.Employee\` - \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Person\` + \`org.acme.hr@1.0.0.Employee\` <--> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Department\` \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr.base@1.0.0.Address\` \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Equipment\` - \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Manager\` \`org.acme.hr@1.0.0.Contractor\` - \`org.acme.hr@1.0.0.Contractor\` --> \`org.acme.hr@1.0.0.Person\` + \`org.acme.hr@1.0.0.Contractor\` <--> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.Contractor\` --> \`org.acme.hr@1.0.0.Company\` \`org.acme.hr@1.0.0.Contractor\` --> \`org.acme.hr@1.0.0.Manager\` \`org.acme.hr@1.0.0.Manager\` - \`org.acme.hr@1.0.0.Manager\` --> \`org.acme.hr@1.0.0.Employee\` + \`org.acme.hr@1.0.0.Manager\` <--> \`org.acme.hr@1.0.0.Employee\` \`org.acme.hr@1.0.0.Manager\` --> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.CompanyEvent\` - \`org.acme.hr@1.0.0.CompanyEvent\` --> \`concerto@1.0.0.Event\` + \`concerto@1.0.0.Event\` + \`concerto@1.0.0.Event\` <--> \`org.acme.hr@1.0.0.CompanyEvent\` \`org.acme.hr@1.0.0.Onboarded\` - \`org.acme.hr@1.0.0.Onboarded\` --> \`org.acme.hr@1.0.0.CompanyEvent\` + \`org.acme.hr@1.0.0.Onboarded\` <--> \`org.acme.hr@1.0.0.CompanyEvent\` \`org.acme.hr@1.0.0.Onboarded\` --> \`org.acme.hr@1.0.0.Employee\` \`org.acme.hr@1.0.0.ChangeOfAddress\` - \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`concerto@1.0.0.Transaction\` \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`org.acme.hr.base@1.0.0.Address\` + \`concerto@1.0.0.Transaction\` + \`concerto@1.0.0.Transaction\` <--> \`org.acme.hr@1.0.0.ChangeOfAddress\` \`org.acme.hr@1.0.0.KinName\` \`org.acme.hr@1.0.0.KinTelephone\` `); @@ -149,7 +152,7 @@ describe('graph', function () { .filter(declaration => connectedGraph.hasVertex(declaration.getFullyQualifiedName())); expect(filteredModelManager.getModelFiles()).toHaveLength(2); - expect(filteredModelManager.getModelFiles()[0].getAllDeclarations()).toHaveLength(3); + expect(filteredModelManager.getModelFiles()[0].getAllDeclarations()).toHaveLength(5); writer.openFile('graph.mmd'); connectedGraph.print(writer); @@ -157,22 +160,70 @@ describe('graph', function () { expect(writer.data.get('graph.mmd')).toEqual(`flowchart LR \`org.acme.hr.base@1.0.0.State\` \`org.acme.hr.base@1.0.0.State\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr.base@1.0.0.TShirtSizeType\` + \`org.acme.hr.base@1.0.0.TShirtSizeType\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr.base@1.0.0.EmployeeTShirtSizes\` + \`org.acme.hr.base@1.0.0.EmployeeTShirtSizes\` --> \`org.acme.hr.base@1.0.0.SSN\` + \`org.acme.hr.base@1.0.0.EmployeeTShirtSizes\` --> \`org.acme.hr.base@1.0.0.TShirtSizeType\` \`org.acme.hr.base@1.0.0.Address\` \`org.acme.hr.base@1.0.0.Address\` --> \`concerto@1.0.0.Concept\` \`org.acme.hr.base@1.0.0.Address\` --> \`org.acme.hr.base@1.0.0.State\` \`org.acme.hr.base@1.0.0.SSN\` + \`org.acme.hr@1.0.0.CompanyProperties\` + \`org.acme.hr@1.0.0.CompanyProperties\` --> \`String\` + \`org.acme.hr@1.0.0.EmployeeSocialSecurityNumbers\` + \`org.acme.hr@1.0.0.EmployeeSocialSecurityNumbers\` --> \`String\` + \`org.acme.hr@1.0.0.EmployeeSocialSecurityNumbers\` --> \`org.acme.hr.base@1.0.0.SSN\` \`org.acme.hr@1.0.0.NextOfKin\` \`org.acme.hr@1.0.0.NextOfKin\` --> \`org.acme.hr@1.0.0.KinName\` \`org.acme.hr@1.0.0.NextOfKin\` --> \`org.acme.hr@1.0.0.KinTelephone\` + \`org.acme.hr@1.0.0.EmployeeProfiles\` + \`org.acme.hr@1.0.0.EmployeeProfiles\` --> \`String\` + \`org.acme.hr@1.0.0.EmployeeProfiles\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr@1.0.0.EmployeeDirectory\` + \`org.acme.hr@1.0.0.EmployeeDirectory\` --> \`org.acme.hr.base@1.0.0.SSN\` + \`org.acme.hr@1.0.0.EmployeeDirectory\` --> \`org.acme.hr@1.0.0.Employee\` + \`org.acme.hr@1.0.0.Company\` + \`org.acme.hr@1.0.0.Company\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr.base@1.0.0.Address\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr@1.0.0.CompanyProperties\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr@1.0.0.EmployeeDirectory\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr.base@1.0.0.EmployeeTShirtSizes\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr@1.0.0.EmployeeProfiles\` + \`org.acme.hr@1.0.0.Company\` --> \`org.acme.hr@1.0.0.EmployeeSocialSecurityNumbers\` + \`org.acme.hr@1.0.0.Department\` + \`org.acme.hr@1.0.0.Department\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr@1.0.0.Equipment\` + \`concerto@1.0.0.Asset\` + \`concerto@1.0.0.Asset\` <--> \`org.acme.hr@1.0.0.Equipment\` + \`org.acme.hr@1.0.0.LaptopMake\` + \`org.acme.hr@1.0.0.LaptopMake\` --> \`concerto@1.0.0.Concept\` + \`org.acme.hr@1.0.0.Laptop\` + \`org.acme.hr@1.0.0.Laptop\` <--> \`org.acme.hr@1.0.0.Equipment\` + \`org.acme.hr@1.0.0.Laptop\` --> \`org.acme.hr@1.0.0.LaptopMake\` \`org.acme.hr@1.0.0.Person\` - \`org.acme.hr@1.0.0.Person\` --> \`concerto@1.0.0.Participant\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr.base@1.0.0.Address\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr.base@1.0.0.SSN\` \`org.acme.hr@1.0.0.Person\` --> \`org.acme.hr@1.0.0.NextOfKin\` + \`concerto@1.0.0.Participant\` + \`concerto@1.0.0.Participant\` <--> \`org.acme.hr@1.0.0.Person\` + \`org.acme.hr@1.0.0.Employee\` + \`org.acme.hr@1.0.0.Employee\` <--> \`org.acme.hr@1.0.0.Person\` + \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Department\` + \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr.base@1.0.0.Address\` + \`org.acme.hr@1.0.0.Employee\` --> \`org.acme.hr@1.0.0.Equipment\` + \`org.acme.hr@1.0.0.Contractor\` + \`org.acme.hr@1.0.0.Contractor\` <--> \`org.acme.hr@1.0.0.Person\` + \`org.acme.hr@1.0.0.Contractor\` --> \`org.acme.hr@1.0.0.Company\` + \`org.acme.hr@1.0.0.Contractor\` --> \`org.acme.hr@1.0.0.Manager\` + \`org.acme.hr@1.0.0.Manager\` + \`org.acme.hr@1.0.0.Manager\` <--> \`org.acme.hr@1.0.0.Employee\` + \`org.acme.hr@1.0.0.Manager\` --> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.ChangeOfAddress\` - \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`concerto@1.0.0.Transaction\` \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`org.acme.hr@1.0.0.Person\` \`org.acme.hr@1.0.0.ChangeOfAddress\` --> \`org.acme.hr.base@1.0.0.Address\` + \`concerto@1.0.0.Transaction\` + \`concerto@1.0.0.Transaction\` <--> \`org.acme.hr@1.0.0.ChangeOfAddress\` \`org.acme.hr@1.0.0.KinName\` \`org.acme.hr@1.0.0.KinTelephone\` `);