Skip to content

Import and export MooseModel in a JSON format that is easy to use with Neo4J

License

Notifications You must be signed in to change notification settings

badetitou/Moose2GraphJson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moose2GraphJson

I can export and import any MooseModel in a json format adapted for graph database

Install

Stable version

Metacello new
  githubUser: 'badetitou' project: 'Moose2GraphJson' commitish: 'v1.0.0' path: 'src';
  baseline: 'Moose2GraphJson';
  load

Last version

Metacello new
  githubUser: 'badetitou' project: 'Moose2GraphJson' commitish: 'main' path: 'src';
  baseline: 'Moose2GraphJson';
  load

Export a model

'D:/test.json' asFileReference writeStreamDo: [ :stream | (M2GJExporter on: stream) writeMooseModel: aMooseModel ]

Import a model

(M2GJImporter on: 'D:/ref/to/model.json' asFileReference readStream) 
  model: MooseModel new;
  yourself.
importer import.
importer model name

Import in neo4j

You can load the generated json file with this command

CALL apoc.load.json('file:///test-graph.json') YIELD value
WITH value.nodes AS nodes, value.relationships AS rels
UNWIND nodes AS n
CALL apoc.create.node(n.labels, apoc.map.setKey(n.properties, 'id', n.id)) YIELD node
WITH rels, apoc.map.fromPairs(COLLECT([n.id, node])) AS nMap
UNWIND rels AS r
WITH r, nMap[TOSTRING(r.startNode)] AS startNode, nMap[TOSTRING(r.endNode)] AS endNode
WHERE startNode IS NOT NULL and endNode IS NOT NULL 
CALL apoc.create.relationship(startNode, r.type, r.properties, endNode) YIELD rel
RETURN rel

JSON model format

Goal

Import and Export Fame model the following format

{
  "name":"modelName",
  "nodes": [
    {
      "id": 3510982, 
      "labels": ["FAMIX.Class"],
      "properties": { "isStub": false, "isInterface": false, "numberOfLinesOfCode": 0, "name": "a" }
    },
    {
      "id": 3510983, 
      "labels": ["FAMIX.Attribute"],
      "properties": { "name": "a1", "hasClassScope": false, "numberOfLinesOfCode": -1, "isStub": false }
    },
    {
      "id": 3510984, 
      "labels": ["FAMIX.Attribute"],
      "properties": { "name": "a2", "hasClassScope": false, "numberOfLinesOfCode": -1, "isStub": false }
    }
  ],
  "relationships": [
    { "type": "parentType", "startNode": 3510983, "endNode": 3510982, "properties": {} },
    { "type": "parentType", "startNode": 3510984, "endNode": 3510982, "properties": {} }
  ]
}