GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: json importer did not use merge strategy correctly · humemai/arcadedb-embedded-python@9b117d2

This repository was archived by the owner on Nov 21, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • integration/src
    • main/java/com/arcadedb/integration/importer/format
      • JSONImporterFormat.java
    • test
      • java/com/arcadedb/integration/importer
        • JSONImporterIT.java
      • resources
        • importer-employees.json
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎integration/src/main/java/com/arcadedb/integration/importer/format/JSONImporterFormat.java‎

Copy file name to clipboardExpand all lines: integration/src/main/java/com/arcadedb/integration/importer/format/JSONImporterFormat.java
+39-22Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@
5656

5757
public class JSONImporterFormat implements FormatImporter {
5858
static class CascadingProperties {
59-
CascadingProperties parent;
60-
Map<String, Object> map;
59+
final CascadingProperties parent;
60+
final Map<String, Object> map;
6161

62-
public CascadingProperties(CascadingProperties parent, Map<String, Object> map) {
62+
public CascadingProperties(final CascadingProperties parent, final Map<String, Object> map) {
6363
this.parent = parent;
6464
this.map = map;
6565
}
6666
}
6767

6868
@Override
69-
public void load(final SourceSchema sourceSchema, final AnalyzedEntity.ENTITY_TYPE entityType, final Parser parser, final DatabaseInternal database,
69+
public void load(final SourceSchema sourceSchema, final AnalyzedEntity.ENTITY_TYPE entityType, final Parser parser,
70+
final DatabaseInternal database,
7071
final ImporterContext context, final ImporterSettings settings) throws IOException {
7172

7273
final JSONObject mapping = settings.mapping != null ? new JSONObject(settings.mapping) : null;
@@ -119,7 +120,8 @@ public String getFormat() {
119120
return "JSON";
120121
}
121122

122-
private void parseRecords(final JsonReader reader, final Database database, final ImporterSettings settings, final ImporterContext context,
123+
private void parseRecords(final JsonReader reader, final Database database, final ImporterSettings settings,
124+
final ImporterContext context,
123125
final JSONArray mapping, boolean ignore) throws IOException {
124126
reader.beginArray();
125127

@@ -148,13 +150,15 @@ private void parseRecords(final JsonReader reader, final Database database, fina
148150
reader.endArray();
149151
}
150152

151-
private static MutableDocument saveAnonymousRecord(final Database database, final ImporterSettings settings, final Map<String, Object> map) {
153+
private static MutableDocument saveAnonymousRecord(final Database database, final ImporterSettings settings,
154+
final Map<String, Object> map) {
152155
// NO MAPPING, SAVE THE RECORD AS A DOCUMENT
153156
database.getSchema().getOrCreateDocumentType(settings.documentTypeName);
154157
return database.newDocument(settings.documentTypeName).set(map).save();
155158
}
156159

157-
private Object parseRecord(final JsonReader reader, final ImporterSettings settings, final ImporterContext context, final Database database,
160+
private Object parseRecord(final JsonReader reader, final ImporterSettings settings, final ImporterContext context,
161+
final Database database,
158162
final JSONObject mapping, final boolean ignore) throws IOException {
159163
final CascadingProperties attributes = ignore ? null : new CascadingProperties(null, new LinkedHashMap<>());
160164

@@ -250,20 +254,23 @@ private Object getAttribute(final CascadingProperties properties, final String n
250254
return properties.map.get(name);
251255
}
252256

253-
private Document createRecord(final Database database, final ImporterContext context, final CascadingProperties attributes, final JSONObject mapping,
257+
private Document createRecord(final Database database, final ImporterContext context, final CascadingProperties attributes,
258+
final JSONObject mapping,
254259
final ImporterSettings settings) {
255260
if (mapping == null)
256261
return null;
257262
//return saveAnonymousRecord(database, settings, (Map<String, Object>) attributes.map);
258263

259264
if (!mapping.has("@cat")) {
260-
LogManager.instance().log(this, Level.WARNING, "No @cat tag defined in mapping object. The following object will be skipped %s", attributes);
265+
LogManager.instance()
266+
.log(this, Level.WARNING, "No @cat tag defined in mapping object. The following object will be skipped %s", attributes);
261267
context.errors.incrementAndGet();
262268
return null;
263269
}
264270

265271
if (!mapping.has("@type")) {
266-
LogManager.instance().log(this, Level.WARNING, "No @type tag defined in mapping object. The following object will be skipped %s", attributes);
272+
LogManager.instance()
273+
.log(this, Level.WARNING, "No @type tag defined in mapping object. The following object will be skipped %s", attributes);
267274
context.errors.incrementAndGet();
268275
return null;
269276
}
@@ -314,7 +321,8 @@ private Document createRecord(final Database database, final ImporterContext con
314321
if (prop == null) {
315322
if (idValue == null) {
316323
// NO ID FOUND, SKIP THE RECORD
317-
LogManager.instance().log(this, Level.WARNING, "@id property not found on current record, skipping record: %s", attributes);
324+
LogManager.instance()
325+
.log(this, Level.WARNING, "@id property not found on current record, skipping record: %s", attributes);
318326
context.errors.incrementAndGet();
319327
return null;
320328
}
@@ -362,7 +370,8 @@ record = database.newDocument(typeName);
362370
return record;
363371
}
364372

365-
private void applyMappingRules(final Database database, final ImporterContext context, final MutableDocument record, final CascadingProperties attributes,
373+
private void applyMappingRules(final Database database, final ImporterContext context, final MutableDocument record,
374+
final CascadingProperties attributes,
366375
final JSONObject mapping, final ImporterSettings settings) {
367376
resolveProperties(mapping, attributes);
368377

@@ -390,7 +399,8 @@ private void applyMappingRules(final Database database, final ImporterContext co
390399
} else if (mappingValue instanceof JSONArray) {
391400
if (!(attributeValue instanceof Collection)) {
392401
LogManager.instance()
393-
.log(this, Level.WARNING, "Defined an array on mapping for property '%s' but found the object of class %s as attribute", mappingName,
402+
.log(this, Level.WARNING,
403+
"Defined an array on mapping for property '%s' but found the object of class %s as attribute", mappingName,
394404
attributeValue.getClass());
395405
context.errors.incrementAndGet();
396406
continue;
@@ -411,7 +421,8 @@ private void applyMappingRules(final Database database, final ImporterContext co
411421
}
412422
}
413423

414-
private List<Object> parseArray(final JsonReader reader, final ImporterSettings settings, final ImporterContext context, final Database database,
424+
private List<Object> parseArray(final JsonReader reader, final ImporterSettings settings, final ImporterContext context,
425+
final Database database,
415426
final JSONArray mapping, boolean ignore) throws IOException {
416427
final List<Object> list = ignore ? null : new ArrayList<>();
417428
reader.beginArray();
@@ -455,7 +466,8 @@ private List<Object> parseArray(final JsonReader reader, final ImporterSettings
455466
return list;
456467
}
457468

458-
private Object convertMap(final Database database, final ImporterContext context, final MutableDocument record, final Object value, final Object mapping,
469+
private Object convertMap(final Database database, final ImporterContext context, final MutableDocument record,
470+
final Object value, final Object mapping,
459471
final CascadingProperties attributes, final ImporterSettings settings) {
460472
if (mapping instanceof JSONObject) {
461473
final JSONObject mappingObject = (JSONObject) mapping;
@@ -464,24 +476,25 @@ private Object convertMap(final Database database, final ImporterContext context
464476
if (value instanceof Map)
465477
// CONVERT EMBEDDED MAP INTO A RECORD
466478
attributeMap = new LinkedHashMap<>((Map<String, Object>) value);
467-
else {
479+
else
468480
// TREAT THE VALUE AS ID
469481
attributeMap = new LinkedHashMap<>();
470-
}
471482

472483
final String subCategory = mappingObject.has("@cat") ? mappingObject.getString("@cat") : null;
473484
final String subTypeName = mappingObject.has("@type") ? mappingObject.getString("@type") : null;
474485

475486
if ("e".equals(subCategory)) {
476487
// TRANSFORM INTO AN EDGE
477488
if (subTypeName == null) {
478-
LogManager.instance().log(this, Level.WARNING, "Cannot convert object into an edge because the edge @type is not defined");
489+
LogManager.instance()
490+
.log(this, Level.WARNING, "Cannot convert object into an edge because the edge @type is not defined");
479491
context.errors.incrementAndGet();
480492
return null;
481493
}
482494

483495
if (!(record instanceof Vertex)) {
484-
LogManager.instance().log(this, Level.WARNING, "Cannot convert object into an edge because the root record is not a vertex");
496+
LogManager.instance()
497+
.log(this, Level.WARNING, "Cannot convert object into an edge because the root record is not a vertex");
485498
context.errors.incrementAndGet();
486499
return null;
487500
}
@@ -497,15 +510,18 @@ private Object convertMap(final Database database, final ImporterContext context
497510
destVertexItem = attributeMap.get(inVertex);
498511
} else if (inValue instanceof JSONObject) {
499512
destVertexMappingObject = (JSONObject) inValue;
513+
attributeMap.put((String) destVertexMappingObject.get("@id"), value);
500514
destVertexItem = attributeMap;
501515
} else {
502516
LogManager.instance()
503-
.log(this, Level.WARNING, "Cannot convert object into an edge because the destination vertx @in type is not supported: " + inValue);
517+
.log(this, Level.WARNING,
518+
"Cannot convert object into an edge because the destination vertx @in type is not supported: " + inValue);
504519
context.errors.incrementAndGet();
505520
return null;
506521
}
507522
} else {
508-
LogManager.instance().log(this, Level.WARNING, "Cannot convert object into an edge because the destination vertx @in is not defined");
523+
LogManager.instance()
524+
.log(this, Level.WARNING, "Cannot convert object into an edge because the destination vertx @in is not defined");
509525
context.errors.incrementAndGet();
510526
return null;
511527
}
@@ -514,7 +530,8 @@ private Object convertMap(final Database database, final ImporterContext context
514530
if (destVertexItem instanceof Document)
515531
destVertex = (MutableVertex) destVertexItem;
516532
else if (destVertexItem instanceof Map) {
517-
destVertex = (MutableVertex) createRecord(record.getDatabase(), context, new CascadingProperties(attributes, (Map<String, Object>) destVertexItem),
533+
destVertex = (MutableVertex) createRecord(record.getDatabase(), context,
534+
new CascadingProperties(attributes, (Map<String, Object>) destVertexItem),
518535
destVertexMappingObject, settings);
519536
if (destVertex == null) {
520537
LogManager.instance().log(this, Level.WARNING, "Cannot convert inner map into destination vertex: %s", destVertexItem);
Collapse file

‎integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java‎

Copy file name to clipboardExpand all lines: integration/src/test/java/com/arcadedb/integration/importer/JSONImporterIT.java
+19-18Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public void importSingleObject() throws IOException {
3838
final String databasePath = "target/databases/test-import-graph";
3939

4040
Importer importer = new Importer(
41-
("-url file://src/test/resources/importer-one-object.json -database " + databasePath + " -documentType Food -forceDatabaseCreate true").split(" "));
41+
("-url file://src/test/resources/importer-one-object.json -database " + databasePath
42+
+ " -documentType Food -forceDatabaseCreate true").split(" "));
4243
importer.load();
4344

4445
try (final Database db = new DatabaseFactory(databasePath).open()) {
@@ -102,7 +103,8 @@ public void importEmployees() throws IOException {
102103
"}";
103104

104105
Importer importer = new Importer(
105-
new String[] { "-url", "file://src/test/resources/importer-employees.json", "-database", databasePath, "-forceDatabaseCreate", "true", "-mapping",
106+
new String[] { "-url", "file://src/test/resources/importer-employees.json", "-database", databasePath,
107+
"-forceDatabaseCreate", "true", "-mapping",
106108
mapping });
107109
importer.load();
108110

@@ -114,26 +116,25 @@ public void importEmployees() throws IOException {
114116

115117
if ("Marcus".equalsIgnoreCase(name)) {
116118
Assertions.assertEquals("1234", vertex.getString("id"));
117-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.OUT))
118-
v.getString("1230");
119-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.IN))
120-
Assertions.fail();
119+
Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER"));
120+
Assertions.assertEquals(2, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER"));
121121
} else if ("Win".equals(name)) {
122122
Assertions.assertEquals("1230", vertex.getString("id"));
123-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.IN))
124-
v.getString("1234");
125-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.OUT))
126-
v.getString("1231");
127-
} else {
128-
Assertions.assertEquals("1231", vertex.getString("id"));
129-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.IN))
130-
v.getString("1230");
131-
for (Vertex v : vertex.getVertices(Vertex.DIRECTION.OUT))
132-
Assertions.fail();
133-
}
123+
Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER"));
124+
Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER"));
125+
} else if ("Dave".equals(name)) {
126+
Assertions.assertEquals("1232", vertex.getString("id"));
127+
Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER"));
128+
Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER"));
129+
} else if ("Albert".equals(name)) {
130+
Assertions.assertEquals("1239", vertex.getString("id"));
131+
Assertions.assertEquals(1, vertex.countEdges(Vertex.DIRECTION.OUT, "HAS_MANAGER"));
132+
Assertions.assertEquals(0, vertex.countEdges(Vertex.DIRECTION.IN, "HAS_MANAGER"));
133+
} else
134+
Assertions.fail();
134135
}
135136

136-
Assertions.assertEquals(3, db.countType("User", true));
137+
Assertions.assertEquals(4, db.countType("User", true));
137138
}
138139

139140
TestHelper.checkActiveDatabases();
Collapse file

‎integration/src/test/resources/importer-employees.json‎

Copy file name to clipboard
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
{
22
"Users": [
33
{
4+
"id": "1",
45
"EmployeeID": "1234",
5-
"ManagerID": "1230",
66
"Name": "Marcus"
77
},
88
{
9+
"id": "2",
910
"EmployeeID": "1230",
10-
"ManagerID": "1231",
11+
"ManagerID": "1234",
1112
"Name": "Win"
13+
},
14+
{
15+
"id": "3",
16+
"EmployeeID": "1232",
17+
"ManagerID": "1234",
18+
"Name": "Dave"
19+
},
20+
{
21+
"id": "4",
22+
"EmployeeID": "1239",
23+
"ManagerID": "1232",
24+
"Name": "Albert"
1225
}
1326
]
1427
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.