Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MET-4463 update oai library #626

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions metis-harvesting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.dspace</groupId>
<groupId>io.gdcc</groupId>
<artifactId>xoai-service-provider</artifactId>
</dependency>
<dependency>
Expand Down Expand Up @@ -78,4 +78,4 @@
<version>4.5.13</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.dspace.xoai.serviceprovider.exceptions.HttpException;
import org.dspace.xoai.serviceprovider.parameters.Parameters;
import io.gdcc.xoai.serviceprovider.exceptions.HttpException;
import io.gdcc.xoai.serviceprovider.parameters.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is an implementation of {@link org.dspace.xoai.serviceprovider.client.OAIClient} that needs
* This is an implementation of {@link io.gdcc.xoai.serviceprovider.client.OAIClient} that needs
* to be closed.
*
* @see org.dspace.xoai.serviceprovider.client.HttpOAIClient
* @see io.gdcc.xoai.serviceprovider.client.OAIClient
*/
public class CloseableHttpOaiClient implements CloseableOaiClient {
public class CloseableHttpOaiClient extends CloseableOaiClient {

private static final Logger LOGGER = LoggerFactory.getLogger(CloseableHttpOaiClient.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package eu.europeana.metis.harvesting.oaipmh;

import io.gdcc.xoai.serviceprovider.client.OAIClient;

import java.io.Closeable;
import org.dspace.xoai.serviceprovider.client.OAIClient;

/**
* Implementations of this interface provide OAI access and need to be closed.
*/
public interface CloseableOaiClient extends OAIClient, Closeable {
public abstract class CloseableOaiClient extends OAIClient implements Closeable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.apache.commons.io.IOUtils;
import org.dspace.xoai.model.oaipmh.Header;
import org.dspace.xoai.model.oaipmh.Verb;
import org.dspace.xoai.serviceprovider.ServiceProvider;
import org.dspace.xoai.serviceprovider.exceptions.BadArgumentException;
import org.dspace.xoai.serviceprovider.exceptions.OAIRequestException;
import org.dspace.xoai.serviceprovider.model.Context;
import org.dspace.xoai.serviceprovider.parameters.GetRecordParameters;
import org.dspace.xoai.serviceprovider.parameters.ListIdentifiersParameters;
import org.dspace.xoai.serviceprovider.parameters.Parameters;
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.GetRecordParameters;
import io.gdcc.xoai.serviceprovider.parameters.ListIdentifiersParameters;
import io.gdcc.xoai.serviceprovider.parameters.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -81,10 +81,10 @@ private static ListIdentifiersParameters prepareListIdentifiersParameters(OaiHar
ListIdentifiersParameters parameters = ListIdentifiersParameters.request()
.withMetadataPrefix(harvest.getMetadataPrefix());
if (harvest.getFrom() != null) {
parameters.withFrom(Date.from(harvest.getFrom()));
parameters.withFrom(Date.from(harvest.getFrom()).toInstant());
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
}
if (harvest.getUntil() != null) {
parameters.withUntil(Date.from(harvest.getUntil()));
parameters.withUntil(Date.from(harvest.getUntil()).toInstant());
}
if (harvest.getSetSpec() != null) {
parameters.withSetSpec(harvest.getSetSpec());
Expand All @@ -99,18 +99,18 @@ public OaiRecord harvestRecord(OaiRepository repository, String oaiIdentifier)
.withIdentifier(oaiIdentifier).withMetadataFormatPrefix(repository.getMetadataPrefix());
final Parameters parameters = Parameters.parameters().withVerb(Verb.Type.GetRecord)
.include(getRecordParameters);
final byte[] record;
final byte[] byteArrayRecord;
try (final CloseableOaiClient oaiClient = connectionClientFactory
.createConnectionClient(repository.getRepositoryUrl());
final InputStream recordStream = performThrowingFunction(oaiClient,
client -> client.execute(parameters))) {
record = IOUtils.toByteArray(recordStream);
byteArrayRecord = IOUtils.toByteArray(recordStream);
} catch (OAIRequestException | IOException e) {
throw new HarvesterException(String.format(
"Problem with harvesting record %1$s for endpoint %2$s because of: %3$s",
oaiIdentifier, repository.getRepositoryUrl(), e.getMessage()), e);
}
return new OaiRecordParser().parseOaiRecord(record);
return new OaiRecordParser().parseOaiRecord(byteArrayRecord);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.time.Instant;
import java.util.Date;
import java.util.Optional;
import org.dspace.xoai.model.oaipmh.Header;
import io.gdcc.xoai.model.oaipmh.results.record.Header;

/**
* This is a immutable class representing an OAI-PMH record header.
Expand Down Expand Up @@ -37,7 +37,7 @@ public OaiRecordHeader(String oaiIdentifier, boolean isDeleted, Instant datestam
*/
static OaiRecordHeader convert(Header header) {
return new OaiRecordHeader(header.getIdentifier(), header.isDeleted(),
Optional.ofNullable(header.getDatestamp()).map(Date::toInstant).orElse(null));
Optional.ofNullable(header.getDatestamp()).orElse(null));
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
}

public String getOaiIdentifier() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package eu.europeana.metis.harvesting.oaipmh;

import com.lyncode.xml.XmlReader;
import com.lyncode.xml.exceptions.XmlReaderException;
import com.lyncode.xml.matchers.XmlEventMatchers;
import eu.europeana.metis.harvesting.HarvesterException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -24,9 +21,13 @@
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;

import io.gdcc.xoai.xmlio.XmlReader;
import io.gdcc.xoai.xmlio.exceptions.XmlReaderException;
import io.gdcc.xoai.xmlio.matchers.XmlEventMatchers;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.xpath.XPathFactoryImpl;
import org.dspace.xoai.serviceprovider.parsers.HeaderParser;
import io.gdcc.xoai.serviceprovider.parsers.HeaderParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import eu.europeana.metis.network.NetworkUtil;
import java.io.IOException;
import java.util.function.Supplier;
import org.dspace.xoai.serviceprovider.exceptions.HttpException;
import org.dspace.xoai.serviceprovider.parameters.Parameters;
import io.gdcc.xoai.serviceprovider.exceptions.HttpException;
import io.gdcc.xoai.serviceprovider.parameters.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down
Loading