From 43595035f8c04b959878080d81dd3808ca6f0f3a Mon Sep 17 00:00:00 2001 From: Simon Tzanakis Date: Wed, 18 Sep 2024 10:39:18 +0200 Subject: [PATCH] MET-6117 Remove deprecations from oai harvesting (#693) --- .../oaipmh/CloseableHttpOaiClient.java | 1 - .../metis/harvesting/oaipmh/OaiHarvester.java | 6 +- .../harvesting/oaipmh/OaiHarvesterImpl.java | 229 +----------------- .../oaipmh/OaiHarvestingIterator.java | 218 +++++++++++++++++ .../metis/harvesting/oaipmh/OaiRecord.java | 18 +- .../oaipmh/OaiRecordHeaderIterator.java | 13 - .../harvesting/OaiHarvesterImplTest.java | 4 +- .../metis/harvesting/OaiRecordParserTest.java | 4 +- 8 files changed, 238 insertions(+), 255 deletions(-) create mode 100644 metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvestingIterator.java delete mode 100644 metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecordHeaderIterator.java diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/CloseableHttpOaiClient.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/CloseableHttpOaiClient.java index 109987ab0..236dccb6d 100644 --- a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/CloseableHttpOaiClient.java +++ b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/CloseableHttpOaiClient.java @@ -6,7 +6,6 @@ import java.io.Closeable; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.util.List; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvester.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvester.java index 80f76eeb5..5e25efcba 100644 --- a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvester.java +++ b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvester.java @@ -1,7 +1,7 @@ package eu.europeana.metis.harvesting.oaipmh; -import eu.europeana.metis.harvesting.FullRecordHarvestingIterator; import eu.europeana.metis.harvesting.HarvesterException; +import eu.europeana.metis.harvesting.HarvestingIterator; /** * Implementations of this interface provide OAI-PMH harvesting access. @@ -14,7 +14,7 @@ public interface OaiHarvester { * @param harvest The harvest request to execute. * @return An iterator providing access to the headers. The caller needs to close it after use. */ - OaiRecordHeaderIterator harvestRecordHeaders(OaiHarvest harvest); + HarvestingIterator harvestRecordHeaders(OaiHarvest harvest); /** * Harvest the full records. @@ -22,7 +22,7 @@ public interface OaiHarvester { * @param harvest The harvest request to execute. * @return An iterator providing access to the headers. The caller needs to close it after use. */ - FullRecordHarvestingIterator harvestRecords(OaiHarvest harvest); + HarvestingIterator harvestRecords(OaiHarvest harvest); /** * Harvest an individual record. diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvesterImpl.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvesterImpl.java index 798aabf23..5c854e2bc 100644 --- a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvesterImpl.java +++ b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvesterImpl.java @@ -2,51 +2,22 @@ import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performThrowingFunction; -import eu.europeana.metis.harvesting.FullRecordHarvestingIterator; import eu.europeana.metis.harvesting.HarvesterException; import eu.europeana.metis.harvesting.HarvestingIterator; -import eu.europeana.metis.harvesting.ReportingIteration; -import eu.europeana.metis.harvesting.ReportingIteration.IterationResult; -import io.gdcc.xoai.model.oaipmh.results.record.Header; +import eu.europeana.metis.harvesting.oaipmh.OaiHarvestingIterator.RecordOaiHeaderPostProcessing; import io.gdcc.xoai.model.oaipmh.verbs.Verb; -import io.gdcc.xoai.serviceprovider.ServiceProvider; -import io.gdcc.xoai.serviceprovider.exceptions.BadArgumentException; import io.gdcc.xoai.serviceprovider.exceptions.OAIRequestException; -import io.gdcc.xoai.serviceprovider.model.Context; import io.gdcc.xoai.serviceprovider.parameters.GetRecordParameters; -import io.gdcc.xoai.serviceprovider.parameters.ListIdentifiersParameters; import io.gdcc.xoai.serviceprovider.parameters.Parameters; import java.io.IOException; import java.io.InputStream; -import java.util.Iterator; -import java.util.Optional; -import java.util.function.Predicate; -import javax.xml.XMLConstants; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPathFactoryConfigurationException; import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; /** * This class provides an implementation of the {@link OaiHarvester} functionality. */ public class OaiHarvesterImpl implements OaiHarvester { - private static final Logger LOGGER = LoggerFactory.getLogger(OaiHarvesterImpl.class); - - private static final String COMPLETE_LIST_SIZE_XPATH = - "/*[local-name()='OAI-PMH']" + - "/*[local-name()='ListIdentifiers']" + - "/*[local-name()='resumptionToken']"; - public static final String COMPLETE_LIST_SIZE = "completeListSize"; - private final ConnectionClientFactory connectionClientFactory; /** @@ -59,30 +30,17 @@ public OaiHarvesterImpl(ConnectionClientFactory connectionClientFactory) { } @Override - public OaiRecordHeaderIterator harvestRecordHeaders(OaiHarvest harvest) { - return new RecordHeaderIterator(connectionClientFactory.createConnectionClient( - harvest.getRepositoryUrl()), harvest); + public HarvestingIterator harvestRecordHeaders(OaiHarvest oaiHarvest) { + return new OaiHarvestingIterator<>(connectionClientFactory.createConnectionClient( + oaiHarvest.getRepositoryUrl()), oaiHarvest, (header, oaiClient, harvest) -> header); } @Override - public FullRecordHarvestingIterator harvestRecords(OaiHarvest harvest) { - return new FullRecordIterator(connectionClientFactory.createConnectionClient( - harvest.getRepositoryUrl()), harvest); - } - - private static ListIdentifiersParameters prepareListIdentifiersParameters(OaiHarvest harvest) { - ListIdentifiersParameters parameters = ListIdentifiersParameters.request() - .withMetadataPrefix(harvest.getMetadataPrefix()); - if (harvest.getFrom() != null) { - parameters.withFrom(harvest.getFrom()); - } - if (harvest.getUntil() != null) { - parameters.withUntil(harvest.getUntil()); - } - if (harvest.getSetSpec() != null) { - parameters.withSetSpec(harvest.getSetSpec()); - } - return parameters; + public HarvestingIterator harvestRecords(OaiHarvest oaiHarvest) { + final RecordOaiHeaderPostProcessing postProcessing = (header, oaiClient, harvest) -> harvestRecord(oaiClient, harvest, + header.getOaiIdentifier()); + return new OaiHarvestingIterator<>(connectionClientFactory.createConnectionClient( + oaiHarvest.getRepositoryUrl()), oaiHarvest, postProcessing); } @Override @@ -126,31 +84,6 @@ public Integer countRecords(OaiHarvest harvest) throws HarvesterException { } } - private static Integer readCompleteListSizeFromXML(InputStream stream) throws HarvesterException { - final XPathExpression expr; - try { - final XPathFactory xpathFactory = XPathFactory.newInstance(); - xpathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - final XPath xpath = xpathFactory.newXPath(); - expr = xpath.compile(COMPLETE_LIST_SIZE_XPATH); - } catch (XPathExpressionException | XPathFactoryConfigurationException e) { - throw new HarvesterException("Cannot compile xpath expression.", e); - } - try { - final Node resumptionTokenNode = (Node) expr - .evaluate(new InputSource(stream), XPathConstants.NODE); - if (resumptionTokenNode != null) { - final Node node = resumptionTokenNode.getAttributes().getNamedItem(COMPLETE_LIST_SIZE); - if (node != null) { - return Integer.valueOf(node.getNodeValue()); - } - } - } catch (NumberFormatException | XPathExpressionException e) { - LOGGER.debug("Cannot read completeListSize from OAI response ", e); - } - return null; - } - /** * Implementations of this interface can provide connection clients. */ @@ -163,150 +96,6 @@ public interface ConnectionClientFactory { * @return A connection instance. */ CloseableOaiClient createConnectionClient(String oaiPmhEndpoint); - } - - private static class RecordHeaderIterator extends OaiHarvestingIterator - implements OaiRecordHeaderIterator { - - public RecordHeaderIterator(CloseableOaiClient oaiClient, OaiHarvest harvest) { - super(oaiClient, harvest); - } - - @Override - public void forEachFiltered(ReportingIteration action, - Predicate filter) throws HarvesterException { - forEachHeaderFiltered(action, filter); - } - } - - private static class FullRecordIterator extends OaiHarvestingIterator - implements FullRecordHarvestingIterator { - - public FullRecordIterator(CloseableOaiClient oaiClient, OaiHarvest harvest) { - super(oaiClient, harvest); - } - - @Override - public void forEachFiltered(ReportingIteration action, - Predicate filter) throws HarvesterException { - forEachRecordFiltered(action, filter); - } - } - - /** - * Iterator for harvesting. It wraps a source iterator and provides additional closing functionality for the connection client. - */ - private static abstract class OaiHarvestingIterator implements HarvestingIterator { - - private Iterator
source = null; - private final CloseableOaiClient oaiClient; - private final OaiHarvest harvest; - - /** - * Constructor. - * - * @param oaiClient The client to close when the iterator is closed. - * @param harvest The harvest request to execute. - */ - public OaiHarvestingIterator(CloseableOaiClient oaiClient, OaiHarvest harvest) { - this.oaiClient = oaiClient; - this.harvest = harvest; - } - - private Iterator
getOrCreateSource() throws HarvesterException { - if (this.source != null) { - return source; - } - final ListIdentifiersParameters parameters = prepareListIdentifiersParameters(harvest); - try { - this.source = new ServiceProvider(new Context().withOAIClient(this.oaiClient)) - .listIdentifiers(parameters); - } catch (RuntimeException | BadArgumentException e) { - try { - this.close(); - } catch (IOException ioException) { - LOGGER.info("Could not close connection client.", ioException); - } - throw new HarvesterException(e.getMessage(), e); - } - return this.source; - } - - public void forEachRecordFiltered(final ReportingIteration action, - final Predicate filter) throws HarvesterException { - final RecordPostProcessing postProcessing = header -> harvestRecord(oaiClient, harvest, header.getOaiIdentifier()); - forEachWithPostProcessing(action, postProcessing, filter); - } - - public void forEachHeaderFiltered(final ReportingIteration action, - final Predicate filter) throws HarvesterException { - forEachWithPostProcessing(action, header -> header, filter); - } - public void forEachWithPostProcessing(final ReportingIteration action, - final RecordPostProcessing postProcessing, final Predicate filter) - throws HarvesterException { - final SingleIteration singleIteration = new SingleIteration<>(filter, postProcessing, action); - try { - while (getOrCreateSource().hasNext()) { - final Header header = Optional.of(getOrCreateSource().next()) - .orElseThrow(() -> new HarvesterException("Unexpected null header.")); - try { - if (singleIteration.process(header) == IterationResult.TERMINATE) { - break; - } - } catch (IOException e) { - throw new HarvesterException("Problem while processing: " + header.getIdentifier(), e); - } - } - } catch (RuntimeException e) { - throw new HarvesterException("Problem while iterating through OAI headers.", e); - } - } - - @Override - public void forEachNonDeleted(ReportingIteration action) throws HarvesterException { - forEachFiltered(action, Predicate.not(OaiRecordHeader::isDeleted)); - } - - @Override - public Integer countRecords() throws HarvesterException { - final Parameters parameters = Parameters.parameters().withVerb(Verb.Type.ListIdentifiers) - .include(prepareListIdentifiersParameters(harvest)); - try (final InputStream listIdentifiersResponse = performThrowingFunction(oaiClient, - client -> client.execute(parameters))) { - return readCompleteListSizeFromXML(listIdentifiersResponse); - } catch (OAIRequestException | IOException e) { - throw new HarvesterException(String.format( - "Problem with counting records for endpoint %1$s because of: %2$s", - harvest.getRepositoryUrl(), e.getMessage()), e); - } - } - - @Override - public void close() throws IOException { - this.oaiClient.close(); - } } - - private interface RecordPostProcessing { - - O postProcess(OaiRecordHeader input) throws HarvesterException; - } - - private record SingleIteration(Predicate filter, - RecordPostProcessing postProcessing, - ReportingIteration action) { - - public IterationResult process(Header input) throws HarvesterException, IOException { - final OaiRecordHeader header = OaiRecordHeader.convert(input); - if (filter.test(header)) { - final O postProcessResult = Optional.ofNullable(postProcessing.postProcess(header)) - .orElseThrow(() -> new HarvesterException("Post processing result cannot be null.")); - return Optional.ofNullable(action.process(postProcessResult)) - .orElseThrow(() -> new HarvesterException("Iteration result cannot be null.")); - } - return IterationResult.CONTINUE; - } - } } diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvestingIterator.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvestingIterator.java new file mode 100644 index 000000000..2861d35c8 --- /dev/null +++ b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiHarvestingIterator.java @@ -0,0 +1,218 @@ +package eu.europeana.metis.harvesting.oaipmh; + +import static eu.europeana.metis.utils.SonarqubeNullcheckAvoidanceUtils.performThrowingFunction; + +import eu.europeana.metis.harvesting.HarvesterException; +import eu.europeana.metis.harvesting.HarvestingIterator; +import eu.europeana.metis.harvesting.ReportingIteration; +import eu.europeana.metis.harvesting.ReportingIteration.IterationResult; +import io.gdcc.xoai.model.oaipmh.results.record.Header; +import io.gdcc.xoai.model.oaipmh.verbs.Verb; +import io.gdcc.xoai.serviceprovider.ServiceProvider; +import io.gdcc.xoai.serviceprovider.exceptions.BadArgumentException; +import io.gdcc.xoai.serviceprovider.exceptions.OAIRequestException; +import io.gdcc.xoai.serviceprovider.model.Context; +import io.gdcc.xoai.serviceprovider.parameters.ListIdentifiersParameters; +import io.gdcc.xoai.serviceprovider.parameters.Parameters; +import java.io.IOException; +import java.io.InputStream; +import java.lang.invoke.MethodHandles; +import java.util.Iterator; +import java.util.Optional; +import java.util.function.Predicate; +import javax.xml.XMLConstants; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import javax.xml.xpath.XPathFactoryConfigurationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +/** + * Iterator for harvesting. It wraps a source iterator and provides additional closing functionality for the connection client. + */ +class OaiHarvestingIterator implements HarvestingIterator { + + private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static final String COMPLETE_LIST_SIZE_XPATH = + "/*[local-name()='OAI-PMH']" + + "/*[local-name()='ListIdentifiers']" + + "/*[local-name()='resumptionToken']"; + public static final String COMPLETE_LIST_SIZE = "completeListSize"; + private Iterator
source = null; + + private final CloseableOaiClient oaiClient; + private final OaiHarvest harvest; + private final RecordOaiHeaderPostProcessing postProcessing; + + /** + * Constructor. + * + * @param oaiClient The client to close when the iterator is closed. + * @param harvest The harvest request to execute. + * @param recordOaiHeaderPostProcessing post processing after harvested header. + */ + protected OaiHarvestingIterator(CloseableOaiClient oaiClient, OaiHarvest harvest, + RecordOaiHeaderPostProcessing recordOaiHeaderPostProcessing) { + this.oaiClient = oaiClient; + this.harvest = harvest; + this.postProcessing = recordOaiHeaderPostProcessing; + } + + private Iterator
getOrCreateSource() throws HarvesterException { + if (this.source != null) { + return source; + } + final ListIdentifiersParameters parameters = prepareListIdentifiersParameters(harvest); + try { + this.source = new ServiceProvider(new Context().withOAIClient(this.oaiClient)) + .listIdentifiers(parameters); + } catch (RuntimeException | BadArgumentException e) { + try { + this.close(); + } catch (IOException ioException) { + LOGGER.info("Could not close connection client.", ioException); + } + throw new HarvesterException(e.getMessage(), e); + } + return this.source; + } + + private static ListIdentifiersParameters prepareListIdentifiersParameters(OaiHarvest harvest) { + ListIdentifiersParameters parameters = ListIdentifiersParameters.request() + .withMetadataPrefix(harvest.getMetadataPrefix()); + if (harvest.getFrom() != null) { + parameters.withFrom(harvest.getFrom()); + } + if (harvest.getUntil() != null) { + parameters.withUntil(harvest.getUntil()); + } + if (harvest.getSetSpec() != null) { + parameters.withSetSpec(harvest.getSetSpec()); + } + return parameters; + } + + @Override + public void forEachFiltered(ReportingIteration action, + Predicate filter) throws HarvesterException { + forEachWithPostProcessing(action, postProcessing, filter); + } + + private void forEachWithPostProcessing(final ReportingIteration action, + final RecordOaiHeaderPostProcessing postProcessing, final Predicate filter) + throws HarvesterException { + final SingleIteration singleIteration = new SingleIteration<>(filter, postProcessing, action, oaiClient, harvest); + try { + while (getOrCreateSource().hasNext()) { + final Header header = Optional.of(getOrCreateSource().next()) + .orElseThrow(() -> new HarvesterException("Unexpected null header.")); + if (singleIteration.process(header) == IterationResult.TERMINATE) { + break; + } + } + } catch (RuntimeException e) { + throw new HarvesterException("Problem while iterating through OAI headers.", e); + } + } + + @Override + public void forEachNonDeleted(ReportingIteration action) throws HarvesterException { + forEachFiltered(action, Predicate.not(OaiRecordHeader::isDeleted)); + } + + @Override + public Integer countRecords() throws HarvesterException { + final Parameters parameters = Parameters.parameters().withVerb(Verb.Type.ListIdentifiers) + .include(prepareListIdentifiersParameters(harvest)); + try (final InputStream listIdentifiersResponse = performThrowingFunction(oaiClient, + client -> client.execute(parameters))) { + return readCompleteListSizeFromXML(listIdentifiersResponse); + } catch (OAIRequestException | IOException e) { + throw new HarvesterException(String.format( + "Problem with counting records for endpoint %1$s because of: %2$s", + harvest.getRepositoryUrl(), e.getMessage()), e); + } + } + + @Override + public void close() throws IOException { + this.oaiClient.close(); + } + + private static Integer readCompleteListSizeFromXML(InputStream stream) throws HarvesterException { + final XPathExpression expr; + try { + final XPathFactory xpathFactory = XPathFactory.newInstance(); + xpathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final XPath xpath = xpathFactory.newXPath(); + expr = xpath.compile(COMPLETE_LIST_SIZE_XPATH); + } catch (XPathExpressionException | XPathFactoryConfigurationException e) { + throw new HarvesterException("Cannot compile xpath expression.", e); + } + try { + final Node resumptionTokenNode = (Node) expr + .evaluate(new InputSource(stream), XPathConstants.NODE); + if (resumptionTokenNode != null) { + final Node node = resumptionTokenNode.getAttributes().getNamedItem(COMPLETE_LIST_SIZE); + if (node != null) { + return Integer.valueOf(node.getNodeValue()); + } + } + } catch (NumberFormatException | XPathExpressionException e) { + LOGGER.debug("Cannot read completeListSize from OAI response ", e); + } + return null; + } + + /** + * Functional interface for record oai header post-processing. + * + * @param the return value of the function + */ + @FunctionalInterface + public interface RecordOaiHeaderPostProcessing { + + /** + * Applies this function to the given arguments. + * + * @param oaiRecordHeader the oai record header + * @param oaiClient the oai client + * @param oaiHarvest the oai harvest + * @return the result of the function + * @throws HarvesterException if something went wrong + */ + O apply(OaiRecordHeader oaiRecordHeader, CloseableOaiClient oaiClient, OaiHarvest oaiHarvest) throws HarvesterException; + } + + private record SingleIteration(Predicate filter, + RecordOaiHeaderPostProcessing recordOaiHeaderPostProcessing, + ReportingIteration action, CloseableOaiClient oaiClient, OaiHarvest harvest) { + + /** + * Process provided header and return. + * + * @param header the header + * @return the iteration result indicating whether there is more items available. + * @throws HarvesterException if something went wrong + */ + public IterationResult process(Header header) throws HarvesterException { + final OaiRecordHeader oaiRecordHeader = OaiRecordHeader.convert(header); + if (filter.test(oaiRecordHeader)) { + final O postProcessResult = Optional.ofNullable(recordOaiHeaderPostProcessing.apply(oaiRecordHeader, oaiClient, harvest)) + .orElseThrow(() -> new HarvesterException("Post processing result cannot be null.")); + try { + return Optional.ofNullable(action.process(postProcessResult)) + .orElseThrow(() -> new HarvesterException("Iteration result cannot be null.")); + } catch (IOException e) { + throw new HarvesterException("Problem while processing: " + oaiRecordHeader.getOaiIdentifier(), e); + } + } + return IterationResult.CONTINUE; + } + } +} diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecord.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecord.java index 9e818ca10..207215af9 100644 --- a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecord.java +++ b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecord.java @@ -1,10 +1,8 @@ package eu.europeana.metis.harvesting.oaipmh; import eu.europeana.metis.harvesting.FullRecord; -import eu.europeana.metis.harvesting.HarvesterException; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.time.Instant; import java.util.function.Supplier; @@ -16,7 +14,7 @@ public class OaiRecord implements FullRecord { private final OaiRecordHeader header; - private final byte[] record; + private final byte[] content; /** * Constructor. @@ -26,7 +24,7 @@ public class OaiRecord implements FullRecord { */ public OaiRecord(OaiRecordHeader header, Supplier recordSupplier) { this.header = header; - this.record = this.header.isDeleted() ? new byte[0] : recordSupplier.get(); + this.content = this.header.isDeleted() ? new byte[0] : recordSupplier.get(); } public OaiRecordHeader getHeader() { @@ -43,7 +41,7 @@ public void writeContent(OutputStream outputStream) throws IOException { if (isDeleted()) { throw new IllegalStateException("Record is deleted at source."); } - outputStream.write(this.record); + outputStream.write(this.content); } @Override @@ -51,7 +49,7 @@ public ByteArrayInputStream getContent() { if (isDeleted()) { throw new IllegalStateException("Record is deleted at source."); } - return new ByteArrayInputStream(record); + return new ByteArrayInputStream(content); } @Override @@ -59,14 +57,6 @@ public boolean isDeleted() { return getHeader().isDeleted(); } - /** - * @deprecated use {@link #getContent()} instead. - */ - @Deprecated - public InputStream getRecord() throws HarvesterException { - return getContent(); - } - @Override public Instant getTimeStamp() { return header.getDatestamp(); diff --git a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecordHeaderIterator.java b/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecordHeaderIterator.java deleted file mode 100644 index ed2e51a74..000000000 --- a/metis-harvesting/src/main/java/eu/europeana/metis/harvesting/oaipmh/OaiRecordHeaderIterator.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.europeana.metis.harvesting.oaipmh; - -import eu.europeana.metis.harvesting.HarvestingIterator; - -/** - * Implementations of this interface allow iterative access to records harvested using OAI-PMH. The - * iterator needs to be closed after use. - * @deprecated Use {@link HarvestingIterator} instead. - */ -@Deprecated -public interface OaiRecordHeaderIterator extends HarvestingIterator { - -} diff --git a/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiHarvesterImplTest.java b/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiHarvesterImplTest.java index 0da56b8b3..268903f0e 100644 --- a/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiHarvesterImplTest.java +++ b/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiHarvesterImplTest.java @@ -53,7 +53,7 @@ void shouldHarvestRecord() throws IOException, HarvesterException { //when final InputStream result = harvester - .harvestRecord(new OaiRepository(OAI_PMH_ENDPOINT, "oai_dc"), recordId).getRecord(); + .harvestRecord(new OaiRepository(OAI_PMH_ENDPOINT, "oai_dc"), recordId).getContent(); //then final String actual = TestHelper.convertToString(result); @@ -74,7 +74,7 @@ void shouldHandleDeletedRecords() throws Exception { final OaiHarvesterImpl harvester = new OaiHarvesterImpl(CONNECTION_CLIENT_FACTORY); final OaiRecord oaiRecord = harvester.harvestRecord(new OaiRepository(OAI_PMH_ENDPOINT, "oai_dc"), recordId); - assertThrows(IllegalStateException.class, oaiRecord::getRecord); + assertThrows(IllegalStateException.class, oaiRecord::getContent); } @Test diff --git a/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiRecordParserTest.java b/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiRecordParserTest.java index d1c52e1ac..e269dcfd9 100644 --- a/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiRecordParserTest.java +++ b/metis-harvesting/src/test/java/eu/europeana/metis/harvesting/OaiRecordParserTest.java @@ -38,7 +38,7 @@ void happyFlowExtantRecords() throws IOException, HarvesterException { assertEquals(LocalDateTime.of(1981, 7, 1, 0, 0).toInstant(ZoneOffset.UTC), result.getHeader().getDatestamp()); assertFalse(result.getHeader().isDeleted()); - final String actual = TestHelper.convertToString(result.getRecord()); + final String actual = TestHelper.convertToString(result.getContent()); assertThat(actual, TestHelper.isSimilarXml(WiremockHelper.getFileContent("/expectedOaiRecord.xml"))); } @@ -59,7 +59,7 @@ void happyFlowDeletedRecords() throws IOException, HarvesterException { assertEquals("oai:mediateka.centrumzamenhofa.pl:20", result.getHeader().getOaiIdentifier()); assertEquals(LocalDateTime.of(2020, 2, 2, 12, 21).toInstant(ZoneOffset.UTC), result.getHeader().getDatestamp()); - assertThrows(IllegalStateException.class, result::getRecord); + assertThrows(IllegalStateException.class, result::getContent); } @Test