Skip to content

Commit

Permalink
Don't change order in json (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed May 27, 2024
1 parent 27851dd commit 00c24b8
Show file tree
Hide file tree
Showing 153 changed files with 331 additions and 320 deletions.
43 changes: 27 additions & 16 deletions src/main/java/org/lobid/resources/EtikettJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,42 @@ public void process(final String json) {
private String getEtikettForEveryUri(final Map<String, Object> jsonMap)
throws IOException {
// don't label the root id
Object rootId = jsonMap.remove("id");
getAllJsonNodes(jsonMap);
jsonMap.put("id", rootId);

Iterator<String> it = jsonMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
getAllNodesRecursivelyAndLabelThemIfNecessary(jsonMap, key);
}
return pretty ? JsonUtils.toPrettyString(jsonMap)
: JsonUtils.toString(jsonMap);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<String, Object> getAllJsonNodes(Map<String, Object> jsonMap) {
private void getAllNodesRecursivelyAndLabelThemIfNecessary(Map<String, Object> jsonMap, String key) {
if (jsonMap.get(key) instanceof ArrayList) {
((ArrayList) jsonMap.get(key))//
.stream().filter(e -> (e instanceof LinkedHashMap))
.forEach(e -> labelNodesWithKeyId((Map<String, Object>) e));
}
else if (jsonMap.get(key) instanceof LinkedHashMap) {
labelNodesWithKeyId((Map<String, Object>) jsonMap.get(key));
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<String, Object> labelNodesWithKeyId(Map<String, Object> jsonMap) {
Iterator<String> it = jsonMap.keySet().iterator();
boolean hasLabel = false;
String id = null;
while (it.hasNext()) {
String key = it.next();
if (key.equals("label"))
hasLabel = true;
else if (!hasLabel && key.equals("id"))
id = (String) jsonMap.get(key);
if (jsonMap.get(key) instanceof ArrayList)
((ArrayList) jsonMap.get(key))//
.stream().filter(e -> (e instanceof LinkedHashMap))
.forEach(e -> getAllJsonNodes((Map<String, Object>) e));
else if (jsonMap.get(key) instanceof LinkedHashMap)
getAllJsonNodes((Map<String, Object>) jsonMap.get(key));
if (key.equals("label")) {
hasLabel = true;
}
else if (!hasLabel && key.equals("id")) {
id = (String) jsonMap.get(key);
}
else {
getAllNodesRecursivelyAndLabelThemIfNecessary(jsonMap, key);
}
}
if (id != null && !(hasLabel))
jsonMap.put("label", etikettMaker.getEtikett(id).label);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990001412590206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990001412590206441",
"id" : "http://lobid.org/resources/990001412590206441#!",
"hbzId" : "HT000161712",
"deprecatedUri" : "http://lobid.org/resources/HT000161712#!",
"oclcNumber" : [ "600913146" ],
Expand Down Expand Up @@ -400,6 +401,5 @@
"label" : "Herausgeber/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990001412590206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990011470300206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990011470300206441",
"id" : "http://lobid.org/resources/990011470300206441#!",
"hbzId" : "HT003109553",
"deprecatedUri" : "http://lobid.org/resources/HT003109553#!",
"isbn" : [ "087395694X", "9780873956949", "0873956958", "9780873956956" ],
Expand Down Expand Up @@ -178,6 +179,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990011470300206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990014830510206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990014830510206441",
"id" : "http://lobid.org/resources/990014830510206441#!",
"hbzId" : "HT003864492",
"deprecatedUri" : "http://lobid.org/resources/HT003864492#!",
"isbn" : [ "0405039204", "9780405039201" ],
Expand Down Expand Up @@ -183,6 +184,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990014830510206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990016782920206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990016782920206441",
"id" : "http://lobid.org/resources/990016782920206441#!",
"hbzId" : "HT004285445",
"deprecatedUri" : "http://lobid.org/resources/HT004285445#!",
"ismn" : [ "M204421206" ],
Expand Down Expand Up @@ -223,6 +224,5 @@
"label" : "Komposition"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990016782920206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990021367710206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990021367710206441",
"id" : "http://lobid.org/resources/990021367710206441#!",
"hbzId" : "HT005207972",
"deprecatedUri" : "http://lobid.org/resources/HT005207972#!",
"isbn" : [ "0256018243", "9780256018240" ],
Expand Down Expand Up @@ -234,6 +235,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990021367710206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990021974470206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990021974470206441",
"id" : "http://lobid.org/resources/990021974470206441#!",
"hbzId" : "HT005271161",
"deprecatedUri" : "http://lobid.org/resources/HT005271161#!",
"oclcNumber" : [ "1067969357" ],
Expand Down Expand Up @@ -273,6 +274,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990021974470206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990026405480206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990026405480206441",
"id" : "http://lobid.org/resources/990026405480206441#!",
"hbzId" : "HT006813395",
"deprecatedUri" : "http://lobid.org/resources/HT006813395#!",
"isbn" : [ "3893505547", "9783893505548" ],
Expand Down Expand Up @@ -253,6 +254,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990026405480206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990030574430206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990030574430206441",
"id" : "http://lobid.org/resources/990030574430206441#!",
"hbzId" : "HT007847893",
"deprecatedUri" : "http://lobid.org/resources/HT007847893#!",
"oclcNumber" : [ "1071256649" ],
Expand Down Expand Up @@ -156,6 +157,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990030574430206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990033263300206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990033263300206441",
"id" : "http://lobid.org/resources/990033263300206441#!",
"hbzId" : "HT008389117",
"deprecatedUri" : "http://lobid.org/resources/HT008389117#!",
"oclcNumber" : [ "1068461604" ],
Expand Down Expand Up @@ -98,6 +99,5 @@
"label" : "Monograph/Item",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Monograph_Item"
},
"type" : [ "BibliographicResource", "ReferenceSource", "Book" ],
"id" : "http://lobid.org/resources/990033263300206441#!"
"type" : [ "BibliographicResource", "ReferenceSource", "Book" ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990035016180206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990035016180206441",
"id" : "http://lobid.org/resources/990035016180206441#!",
"hbzId" : "HT008733617",
"deprecatedUri" : "http://lobid.org/resources/HT008733617#!",
"isbn" : [ "3598521103", "9783598521102" ],
Expand Down Expand Up @@ -313,6 +314,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990035016180206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990041403870206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990041403870206441",
"id" : "http://lobid.org/resources/990041403870206441#!",
"hbzId" : "HT009965981",
"deprecatedUri" : "http://lobid.org/resources/HT009965981#!",
"isbn" : [ "3897051346", "9783897051348" ],
Expand Down Expand Up @@ -120,6 +121,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990041403870206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990050000600206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990050000600206441",
"id" : "http://lobid.org/resources/990050000600206441#!",
"hbzId" : "HT006855611",
"deprecatedUri" : "http://lobid.org/resources/HT006855611#!",
"oclcNumber" : [ "961364901" ],
Expand Down Expand Up @@ -643,6 +644,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990050000600206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990051552280206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990051552280206441",
"id" : "http://lobid.org/resources/990051552280206441#!",
"hbzId" : "HT009719670",
"deprecatedUri" : "http://lobid.org/resources/HT009719670#!",
"title" : "Le cinéma de la vie",
Expand Down Expand Up @@ -131,6 +132,5 @@
"label" : "Sonstige"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990051552280206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990051708340206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990051708340206441",
"id" : "http://lobid.org/resources/990051708340206441#!",
"hbzId" : "HT009976241",
"deprecatedUri" : "http://lobid.org/resources/HT009976241#!",
"oclcNumber" : [ "1072570332" ],
Expand Down Expand Up @@ -113,6 +114,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990051708340206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990052965140206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990052965140206441",
"id" : "http://lobid.org/resources/990052965140206441#!",
"hbzId" : "HT002529477",
"deprecatedUri" : "http://lobid.org/resources/HT002529477#!",
"oclcNumber" : [ "183288969" ],
Expand Down Expand Up @@ -317,6 +318,5 @@
"label" : "Autor/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990052965140206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990053976760206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990053976760206441",
"id" : "http://lobid.org/resources/990053976760206441#!",
"issn" : [ "00319244" ],
"oclcNumber" : [ "1367315083" ],
"zdbId" : "123550-3",
Expand Down Expand Up @@ -608,6 +609,5 @@
"label" : "Serial",
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Serial"
},
"type" : [ "BibliographicResource", "Periodical" ],
"id" : "http://lobid.org/resources/990053976760206441#!"
"type" : [ "BibliographicResource", "Periodical" ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990054089950206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990054089950206441",
"id" : "http://lobid.org/resources/990054089950206441#!",
"issn" : [ "00387452" ],
"oclcNumber" : [ "165544004" ],
"zdbId" : "204679-9",
Expand Down Expand Up @@ -60217,6 +60218,5 @@
"label" : "Chefredaktion"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990054089950206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990054215550206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990054215550206441",
"id" : "http://lobid.org/resources/990054215550206441#!",
"issn" : [ "00663859", "02509911" ],
"oclcNumber" : [ "1367306405" ],
"zdbId" : "1257-9",
Expand Down Expand Up @@ -222,6 +223,5 @@
"label" : "Herausgeber/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990054215550206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990054301770206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990054301770206441",
"id" : "http://lobid.org/resources/990054301770206441#!",
"issn" : [ "01715224" ],
"oclcNumber" : [ "183206499" ],
"zdbId" : "133469-4",
Expand Down Expand Up @@ -299,6 +300,5 @@
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Serial"
},
"type" : [ "BibliographicResource", "Periodical", "PublicationIssue" ],
"responsibilityStatement" : [ "hrsg. im Auftrag des Deutschen Fremdenverkehrsverbandes e.V. Frankfurt/Main und in Zusammenarbeit mit dem Deutschen Bäderverband e.V" ],
"id" : "http://lobid.org/resources/990054301770206441#!"
"responsibilityStatement" : [ "hrsg. im Auftrag des Deutschen Fremdenverkehrsverbandes e.V. Frankfurt/Main und in Zusammenarbeit mit dem Deutschen Bäderverband e.V" ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990054345550206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990054345550206441",
"id" : "http://lobid.org/resources/990054345550206441#!",
"issn" : [ "01770403" ],
"oclcNumber" : [ "985104571" ],
"zdbId" : "619424-2",
Expand Down Expand Up @@ -853,6 +854,5 @@
"label" : "Herausgeber/in"
},
"type" : [ "Contribution" ]
} ],
"id" : "http://lobid.org/resources/990054345550206441#!"
} ]
}
4 changes: 2 additions & 2 deletions src/test/resources/alma-fix/990055981810206441.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@context" : "http://lobid.org/resources/context.jsonld",
"almaMmsId" : "990055981810206441",
"id" : "http://lobid.org/resources/990055981810206441#!",
"issn" : [ "09405453" ],
"oclcNumber" : [ "724554237" ],
"zdbId" : "1089874-8",
Expand Down Expand Up @@ -423,6 +424,5 @@
"id" : "https://www.loc.gov/marc/bibliographic/bdleader.html#Serial"
},
"type" : [ "BibliographicResource", "Periodical" ],
"responsibilityStatement" : [ "Hrsg.: Kortum-Gesellschaft Bochum e.V." ],
"id" : "http://lobid.org/resources/990055981810206441#!"
"responsibilityStatement" : [ "Hrsg.: Kortum-Gesellschaft Bochum e.V." ]
}
Loading

0 comments on commit 00c24b8

Please sign in to comment.