@@ -995,17 +995,23 @@ private static Promise<Result> deleteFromIndex(String id) throws UnsupportedEnco
995
995
996
996
private static Promise <Result > transformAndIndex (String id , JsonNode jsonBody )
997
997
throws IOException , FileNotFoundException , RecognitionException , UnsupportedEncodingException {
998
- JsonNode transformedJson = transform (jsonBody );
999
- Promise <JsonNode > dataPromise = id .startsWith ("f" ) && transformedJson .has ("hbzId" ) ? // hbz-Fremddaten
1000
- addToLobidData (transformedJson ) : Promise .pure (transformedJson );
998
+ JsonNode transformedJson = transformStrapiToLobid (jsonBody );
999
+ Promise <JsonNode > dataPromise = Promise .pure (transformedJson );
1000
+ if (id .startsWith ("f" )) { // Fremddaten
1001
+ if (transformedJson .has ("hbzId" )) {
1002
+ dataPromise = addToLobidData (transformedJson );
1003
+ } else if (transformedJson .has ("hebisId" )) {
1004
+ dataPromise = addToHebisData (transformedJson );
1005
+ }
1006
+ }
1001
1007
return dataPromise .flatMap (result -> {
1002
1008
Cache .remove (String .format ("/%s" , id ));
1003
1009
WSRequest request = WS .url (elasticsearchUrl (id )).setHeader ("Content-Type" , "application/json" );
1004
1010
return request .put (result ).map (response -> status (response .getStatus (), response .getBody ()));
1005
1011
});
1006
1012
}
1007
1013
1008
- private static JsonNode transform (JsonNode jsonBody )
1014
+ private static JsonNode transformStrapiToLobid (JsonNode jsonBody )
1009
1015
throws IOException , FileNotFoundException , RecognitionException {
1010
1016
File input = new File ("conf/output/test-output-strapi.json" );
1011
1017
File output = new File ("conf/output/test-output-0.json" );
@@ -1023,6 +1029,33 @@ private static Promise<JsonNode> addToLobidData(JsonNode transformedJson) {
1023
1029
return merged ;
1024
1030
}
1025
1031
1032
+ private static Promise <JsonNode > addToHebisData (JsonNode transformedJson ) {
1033
+ WSRequest hebisRequest = WS .url ("http://sru.hebis.de/sru/DB=2.1" ).setHeader ("Accept" , "application/xml" )
1034
+ .setQueryParameter ("query" , "pica.ppn = \" " + transformedJson .get ("hebisId" ).textValue () + "\" " )//
1035
+ .setQueryParameter ("version" , "1.1" )//
1036
+ .setQueryParameter ("operation" , "searchRetrieve" )//
1037
+ .setQueryParameter ("stylesheet" , "http://sru.hebis.de/sru/?xsl=searchRetrieveResponse" )//
1038
+ .setQueryParameter ("recordSchema" , "marc21" )//
1039
+ .setQueryParameter ("maximumRecords" , "1" )//
1040
+ .setQueryParameter ("startRecord" , "1" )//
1041
+ .setQueryParameter ("recordPacking" , "xml" )//
1042
+ .setQueryParameter ("sortKeys" , "LST_Y,pica,0,," );
1043
+ Promise <String > hebisXmlPromise = hebisRequest .get ().map (WSResponse ::asByteArray ).map (byteArray -> new String (byteArray , "UTF-8" ));
1044
+ Promise <JsonNode > hebisJsonPromise = hebisXmlPromise .map (hebisXml -> transformHebisToLobid (hebisXml ));
1045
+ Promise <JsonNode > merged = hebisJsonPromise .map (hebisJson -> mergeRecords (transformedJson , hebisJson ));
1046
+ return merged ;
1047
+ }
1048
+
1049
+ private static JsonNode transformHebisToLobid (String xmlBody )
1050
+ throws IOException , FileNotFoundException , RecognitionException {
1051
+ File input = new File ("conf/output/test-output-hebis.xml" );
1052
+ File output = new File ("conf/output/test-output-0.json" );
1053
+ Files .write (Paths .get (input .getAbsolutePath ()), xmlBody .getBytes ());
1054
+ ETL .main (new String [] {"conf/rpb-test-titel-hebis-to-lobid.flux" });
1055
+ String result = Files .readAllLines (Paths .get (output .getAbsolutePath ())).stream ().collect (Collectors .joining ("\n " ));
1056
+ return Json .parse (result );
1057
+ }
1058
+
1026
1059
private static JsonNode mergeRecords (JsonNode transformedJson , JsonNode lobidJson )
1027
1060
throws JsonMappingException , JsonProcessingException {
1028
1061
ObjectMapper objectMapper = new ObjectMapper ();
@@ -1039,6 +1072,9 @@ private static JsonNode mergeRecords(JsonNode transformedJson, JsonNode lobidJso
1039
1072
: transformedObject ;
1040
1073
lobidMap .put (key , values );
1041
1074
});
1075
+ if (transformedJson .has ("hebisId" )) {
1076
+ lobidMap .remove ("hasItem" ); // temp: https://github.com/hbz/rpb/pull/105#discussion_r2022907781
1077
+ }
1042
1078
return Json .toJson (lobidMap );
1043
1079
}
1044
1080
0 commit comments