-
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 (#540)
* MODEXPW-470 Added mrc
- Loading branch information
1 parent
fb91db8
commit fa67100
Showing
21 changed files
with
481 additions
and
10 deletions.
There are no files selected for viewing
Submodule folio-export-common
updated
4 files
+13 −0 | schemas/srs/marcRecord.json | |
+14 −0 | schemas/srs/rawRecord.json | |
+14 −0 | schemas/srs/srsRecord.json | |
+24 −0 | 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
74 changes: 74 additions & 0 deletions
74
src/main/java/org/folio/dew/batch/MarcAsListStringsWriter.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,74 @@ | ||
package org.folio.dew.batch; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.dew.client.SrsClient; | ||
import org.folio.dew.domain.dto.Formatable; | ||
import org.springframework.batch.core.configuration.annotation.StepScope; | ||
import org.springframework.batch.item.Chunk; | ||
import org.springframework.batch.item.ExecutionContext; | ||
import org.springframework.batch.item.ItemStream; | ||
import org.springframework.batch.item.file.FlatFileItemWriter; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
@Log4j2 | ||
@StepScope | ||
public class MarcAsListStringsWriter<T, U extends Formatable<T>> extends FlatFileItemWriter<List<U>> { | ||
|
||
private SrsClient srsClient; | ||
private MarcAsStringWriter<String> delegateToStringWriter; | ||
|
||
public MarcAsListStringsWriter(String outputFileName, SrsClient srsClient) { | ||
super(); | ||
this.srsClient = srsClient; | ||
delegateToStringWriter = new MarcAsStringWriter<>(outputFileName); | ||
} | ||
|
||
@Override | ||
public void write(Chunk<? extends List<U>> items) throws Exception { | ||
delegateToStringWriter.write(new Chunk<>(items.getItems().stream().flatMap(List::stream).filter(itm -> itm.isInstanceFormat() && itm.isSourceMarc()).map(marc -> getMarcContent(marc.getId())) | ||
.filter(Objects::nonNull).toList())); | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
Assert.notNull(delegateToStringWriter, "Delegate was not set"); | ||
} | ||
|
||
@Override | ||
public void open(ExecutionContext executionContext) { | ||
if (nonNull(delegateToStringWriter)) { | ||
((ItemStream) delegateToStringWriter).open(executionContext); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(ExecutionContext executionContext) { | ||
if (nonNull(delegateToStringWriter)) { | ||
((ItemStream) delegateToStringWriter).update(executionContext); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (nonNull(delegateToStringWriter)) { | ||
((ItemStream) delegateToStringWriter).close(); | ||
} | ||
} | ||
|
||
private String getMarcContent(String id) { | ||
var srsRecords = srsClient.getMarc(id, "INSTANCE"); | ||
if (srsRecords.getSourceRecords().isEmpty()) { | ||
log.warn("No SRS records found by instanceId = {}", id); | ||
return null; | ||
} | ||
var recordId = srsRecords.getSourceRecords().get(0).getRecordId(); | ||
var marcRecord = srsClient.getMarcContent(recordId); | ||
log.info("MARC record found by recordId = {}", recordId); | ||
return marcRecord.getRawRecord().getContent(); | ||
} | ||
} |
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,21 @@ | ||
package org.folio.dew.batch; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.batch.item.file.FlatFileItemWriter; | ||
import org.springframework.batch.item.file.transform.PassThroughLineAggregator; | ||
import org.springframework.core.io.FileSystemResource; | ||
|
||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
|
||
@Log4j2 | ||
public class MarcAsStringWriter<T> extends FlatFileItemWriter<T> { | ||
|
||
public MarcAsStringWriter(String outputFileName) { | ||
super(); | ||
setResource(new FileSystemResource(outputFileName + ".mrc")); | ||
setLineSeparator(EMPTY); | ||
setLineAggregator(new PassThroughLineAggregator<>()); | ||
setShouldDeleteIfEmpty(true); | ||
setName("marcItemWriter"); | ||
} | ||
} |
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,19 @@ | ||
package org.folio.dew.client; | ||
|
||
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.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); | ||
} |
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
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
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
Oops, something went wrong.