-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODEXPW-470 - .mrc-file creation (#542)
* MODEXPW-470 Added mrc (squashed)
- Loading branch information
1 parent
fa67100
commit 693e7dd
Showing
14 changed files
with
177 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule folio-export-common
updated
4 files
+0 −13 | schemas/srs/marcRecord.json | |
+0 −14 | schemas/srs/rawRecord.json | |
+0 −14 | schemas/srs/srsRecord.json | |
+0 −24 | schemas/srs/srsRecordCollection.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
package org.folio.dew.client; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.folio.dew.config.feign.FeignClientConfiguration; | ||
import org.folio.dew.domain.dto.MarcRecord; | ||
import org.folio.dew.domain.dto.SrsRecordCollection; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(name = "source-storage", configuration = FeignClientConfiguration.class) | ||
public interface SrsClient { | ||
|
||
@GetMapping(value = "/source-records") | ||
SrsRecordCollection getMarc(@RequestParam("instanceId") String instanceId, @RequestParam("idType") String idType); | ||
|
||
@GetMapping(value = "/records/{srsId}") | ||
MarcRecord getMarcContent(@PathVariable String srsId); | ||
@GetMapping(value = "/source-records", produces = MediaType.APPLICATION_JSON_VALUE) | ||
JsonNode getMarc(@RequestParam("instanceId") String instanceId, @RequestParam("idType") String idType); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/folio/dew/service/JsonToMarcConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.folio.dew.service; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.marc4j.MarcException; | ||
import org.marc4j.MarcJsonReader; | ||
import org.marc4j.MarcStreamWriter; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Log4j2 | ||
@Component | ||
public class JsonToMarcConverter { | ||
|
||
public String convertJsonRecordToMarcRecord(String jsonRecord) throws IOException { | ||
var byteArrayInputStream = new ByteArrayInputStream(jsonRecord.getBytes(StandardCharsets.UTF_8)); | ||
var byteArrayOutputStream = new ByteArrayOutputStream(); | ||
try (byteArrayInputStream; byteArrayOutputStream) { | ||
var marcJsonReader = new MarcJsonReader(byteArrayInputStream); | ||
var marcStreamWriter = new MarcStreamWriter(byteArrayOutputStream, StandardCharsets.UTF_8.name()); | ||
writeMarc(marcJsonReader, marcStreamWriter); | ||
return byteArrayOutputStream.toString(); | ||
} catch (IOException e) { | ||
log.error(e.getMessage()); | ||
throw e; | ||
} | ||
} | ||
|
||
private void writeMarc(MarcJsonReader marcJsonReader, MarcStreamWriter marcStreamWriter) { | ||
try { | ||
while (marcJsonReader.hasNext()) { | ||
var marc = marcJsonReader.next(); | ||
marcStreamWriter.write(marc); | ||
} | ||
} catch (Exception e) { | ||
log.error(e.getMessage()); | ||
throw new MarcException(e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/resources/mappings/srs-record-invalid-content.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/source-storage/source-records?instanceId=7772796a-b88b-4991-a9f7-2e368217c487&idType=INSTANCE" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": "{\n \"sourceRecords\": [\n {\n \"recordId\": \"777fad9e-7f8e-4d8e-9a71-00d251817866\", \"parsedRecord\": {\n \"id\": \"8e5ea07d-0c06-4a3b-ab34-f4fc3f76bc09\",\n \"conten\": {\"ghf\": \"marc content\"} }}\n ],\n \"totalRecords\": 1\n}", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7772796a-b88b-4991-a9f7-2e368217c487 |