Skip to content

Commit

Permalink
some *partial* fixes syncing the branch with the latest gdcc/xoai sna…
Browse files Browse the repository at this point in the history
…pshot (#8372)
  • Loading branch information
landreev committed Jun 15, 2022
1 parent 171f2f4 commit 09b6441
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.xml.sax.SAXException;

import io.gdcc.xoai.model.oaipmh.Header;
import io.gdcc.xoai.model.oaipmh.results.record.Header;
import edu.harvard.iq.dataverse.EjbDataverseEngine;
import edu.harvard.iq.dataverse.api.imports.ImportServiceBean;
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package edu.harvard.iq.dataverse.harvest.client.oai;

import io.gdcc.xoai.model.oaipmh.Description;
import io.gdcc.xoai.model.oaipmh.results.Description;
import io.gdcc.xoai.model.oaipmh.Granularity;
import io.gdcc.xoai.model.oaipmh.Header;
import io.gdcc.xoai.model.oaipmh.MetadataFormat;
import io.gdcc.xoai.model.oaipmh.Set;
import io.gdcc.xoai.model.oaipmh.results.record.Header;
import io.gdcc.xoai.model.oaipmh.results.MetadataFormat;
import io.gdcc.xoai.model.oaipmh.results.Set;
import io.gdcc.xoai.serviceprovider.ServiceProvider;
import io.gdcc.xoai.serviceprovider.client.JdkHttpOaiClient; //.HttpOAIClient;
import io.gdcc.xoai.serviceprovider.exceptions.BadArgumentException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
package edu.harvard.iq.dataverse.harvest.server.web.servlet;

import io.gdcc.xoai.xmlio.exceptions.XmlWriteException;
import io.gdcc.xoai.dataprovider.DataProvider;
import io.gdcc.xoai.dataprovider.builder.OAIRequestParametersBuilder;
//import io.gdcc.xoai.dataprovider.builder.OAIRequestParametersBuilder;
import io.gdcc.xoai.dataprovider.repository.Repository;
import io.gdcc.xoai.dataprovider.repository.RepositoryConfiguration;
import io.gdcc.xoai.dataprovider.model.Context;
import io.gdcc.xoai.dataprovider.model.MetadataFormat;
import io.gdcc.xoai.services.impl.SimpleResumptionTokenFormat;
import io.gdcc.xoai.dataprovider.request.RequestBuilder;
import io.gdcc.xoai.dataprovider.request.RequestBuilder.RawRequest;
import io.gdcc.xoai.dataprovider.repository.ItemRepository;
import io.gdcc.xoai.dataprovider.repository.SetRepository;
import io.gdcc.xoai.model.oaipmh.DeletedRecord;
Expand All @@ -29,7 +29,6 @@
import edu.harvard.iq.dataverse.harvest.server.OAISetServiceBean;
import edu.harvard.iq.dataverse.harvest.server.xoai.DataverseXoaiItemRepository;
import edu.harvard.iq.dataverse.harvest.server.xoai.DataverseXoaiSetRepository;
import edu.harvard.iq.dataverse.harvest.server.xoai.conditions.UsePregeneratedMetadataFormat;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.MailUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
Expand Down Expand Up @@ -99,7 +98,7 @@ public void init(ServletConfig config) throws ServletException {
if (isDataverseOaiExtensionsSupported()) {
xoaiContext = addDataverseJsonMetadataFormat(xoaiContext);
}
addMetadataFormatConditions(xoaiContext);
//addMetadataFormatConditions(xoaiContext);

setRepository = new DataverseXoaiSetRepository(setService);
itemRepository = new DataverseXoaiItemRepository(recordService, datasetService, systemConfig.getDataverseSiteUrl()+"/oai");
Expand All @@ -109,7 +108,7 @@ public void init(ServletConfig config) throws ServletException {
xoaiRepository = new Repository()
.withSetRepository(setRepository)
.withItemRepository(itemRepository)
.withResumptionTokenFormatter(new SimpleResumptionTokenFormat())
//.withResumptionTokenFormatter(new SimpleResumptionTokenFormat())
.withConfiguration(repositoryConfiguration);

dataProvider = new DataProvider(getXoaiContext(), getXoaiRepository());
Expand Down Expand Up @@ -159,13 +158,14 @@ private Context addDataverseJsonMetadataFormat(Context context) {
return context;
}

/* No longer needed after the modifications on the gdcc/xoai side
private void addMetadataFormatConditions(Context context) {
for (MetadataFormat metadataFormat : context.getMetadataFormats()) {
UsePregeneratedMetadataFormat condition = new UsePregeneratedMetadataFormat();
condition.withMetadataFormat(metadataFormat);
metadataFormat.withCondition(condition);
}
}
}*/

private boolean isDataverseOaiExtensionsSupported() {
return true;
Expand Down Expand Up @@ -230,7 +230,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
}


private void processRequest(HttpServletRequest request, HttpServletResponse response)
private void processRequest(HttpServletRequest httpServletRequest, HttpServletResponse response)
throws ServletException, IOException {

try {
Expand All @@ -241,16 +241,17 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
return;
}

OAIRequestParametersBuilder parametersBuilder = newXoaiRequest();
//OAIRequestParametersBuilder parametersBuilder = newXoaiRequest();
RawRequest rawRequest = RequestBuilder.buildRawRequest(httpServletRequest.getParameterMap());

for (Object p : request.getParameterMap().keySet()) {
/*for (Object p : httpServletRequest.getParameterMap().keySet()) {
String parameterName = (String)p;
String parameterValue = request.getParameter(parameterName);
String parameterValue = httpServletRequest.getParameter(parameterName);
parametersBuilder = parametersBuilder.with(parameterName, parameterValue);
}
}*/

OAIPMH handle = dataProvider.handle(parametersBuilder);
OAIPMH handle = dataProvider.handle(rawRequest);
response.setContentType("text/xml;charset=UTF-8");

XmlWriter xmlWriter = new XmlWriter(response.getOutputStream());
Expand All @@ -264,9 +265,6 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
} catch (XMLStreamException xse) {
logger.warning("XML Stream exception in Get; "+xse.getMessage());
throw new ServletException ("XML Stream Exception in Get", xse);
} catch (XmlWriteException xwe) {
logger.warning("XML Write exception in Get; "+xwe.getMessage());
throw new ServletException ("XML Write Exception in Get", xwe);
} catch (Exception e) {
logger.warning("Unknown exception in Get; "+e.getMessage());
throw new ServletException ("Unknown servlet exception in Get.", e);
Expand All @@ -282,11 +280,6 @@ protected Repository getXoaiRepository() {
return xoaiRepository;
}

protected OAIRequestParametersBuilder newXoaiRequest() {
return new OAIRequestParametersBuilder();
}


public boolean isHarvestingServerEnabled() {
return systemConfig.isOAIServerEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.gdcc.xoai.dataprovider.model.Item;
import io.gdcc.xoai.dataprovider.model.Set;
import io.gdcc.xoai.model.oaipmh.Metadata;
import io.gdcc.xoai.model.oaipmh.About;
import io.gdcc.xoai.model.oaipmh.results.record.Metadata;
import io.gdcc.xoai.model.oaipmh.results.record.About;
import edu.harvard.iq.dataverse.Dataset;
import edu.harvard.iq.dataverse.harvest.server.OAIRecord;
import edu.harvard.iq.dataverse.util.StringUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package edu.harvard.iq.dataverse.harvest.server.xoai;

import io.gdcc.xoai.dataprovider.exceptions.IdDoesNotExistException;
import io.gdcc.xoai.dataprovider.exceptions.OAIException;
import io.gdcc.xoai.dataprovider.exceptions.handler.IdDoesNotExistException;
import io.gdcc.xoai.exceptions.OAIException;
import io.gdcc.xoai.dataprovider.filter.ScopedFilter;
import io.gdcc.xoai.dataprovider.handlers.results.ListItemIdentifiersResult;
import io.gdcc.xoai.dataprovider.handlers.results.ListItemsResults;
//import io.gdcc.xoai.dataprovider.handlers.results.ListItemIdentifiersResult;
//import io.gdcc.xoai.dataprovider.handlers.results.ListItemsResults;
import io.gdcc.xoai.dataprovider.model.Item;
import io.gdcc.xoai.dataprovider.model.ItemIdentifier;
import io.gdcc.xoai.dataprovider.model.Set;
Expand All @@ -16,11 +16,13 @@
import edu.harvard.iq.dataverse.export.ExportService;
import edu.harvard.iq.dataverse.harvest.server.OAIRecord;
import edu.harvard.iq.dataverse.harvest.server.OAIRecordServiceBean;
import edu.harvard.iq.dataverse.harvest.server.xoai.conditions.UsePregeneratedMetadataFormat;
import edu.harvard.iq.dataverse.util.StringUtil;
import io.gdcc.xoai.dataprovider.exceptions.handler.HandlerException;
import io.gdcc.xoai.dataprovider.exceptions.handler.NoMetadataFormatsException;
import io.gdcc.xoai.dataprovider.filter.Scope;
import io.gdcc.xoai.dataprovider.model.conditions.Condition;
import io.gdcc.xoai.model.oaipmh.Metadata;
import io.gdcc.xoai.dataprovider.repository.ResultsPage;
import io.gdcc.xoai.model.oaipmh.ResumptionToken;
import io.gdcc.xoai.model.oaipmh.results.record.Metadata;
import io.gdcc.xoai.xml.EchoElement;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -55,19 +57,19 @@ public DataverseXoaiItemRepository (OAIRecordServiceBean recordService, DatasetS


@Override
public Item getItem(String identifier) throws IdDoesNotExistException, OAIException {
public Item getItem(String identifier) throws IdDoesNotExistException {
// I'm assuming we don't want to use this version of getItem
// that does not specify the requested metadata format, ever
// in our implementation - ?
throw new OAIException("Metadata Format is Required");
throw new IdDoesNotExistException("Metadata Format is Required");
}

@Override
public Item getItem(String identifier, MetadataFormat metadataFormat) throws IdDoesNotExistException, OAIException {
public Item getItem(String identifier, MetadataFormat metadataFormat) throws HandlerException {
logger.fine("getItem; calling findOaiRecordsByGlobalId, identifier " + identifier);

if (metadataFormat == null) {
throw new OAIException("Metadata Format is Required");
throw new NoMetadataFormatsException("Metadata Format is Required");
}

List<OAIRecord> oaiRecords = recordService.findOaiRecordsByGlobalId(identifier);
Expand Down Expand Up @@ -136,44 +138,15 @@ public Item getItem(String identifier, MetadataFormat metadataFormat) throws IdD
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length) throws OAIException {
return getItemIdentifiers(filters, offset, length, null, null, null);
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, Instant from) throws OAIException {
return getItemIdentifiers(filters, offset, length, null, from, null);
}

@Override
public ListItemIdentifiersResult getItemIdentifiersUntil(List<ScopedFilter> filters, int offset, int length, Instant until) throws OAIException {
return getItemIdentifiers(filters, offset, length, null, null, until);
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, Instant from, Instant until) throws OAIException {
return getItemIdentifiers(filters, offset, length, null, from, until);
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, String setSpec) throws OAIException {
return getItemIdentifiers(filters, offset, length, setSpec, null, null);
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, String setSpec, Instant from) throws OAIException {
return getItemIdentifiers(filters, offset, length, setSpec, from, null);
}

@Override
public ListItemIdentifiersResult getItemIdentifiersUntil(List<ScopedFilter> filters, int offset, int length, String setSpec, Instant until) throws OAIException {
return getItemIdentifiers(filters, offset, length, setSpec, null, until);
}

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, String setSpec, Instant from, Instant until) throws OAIException {
public ResultsPage<ItemIdentifier> getItemIdentifiers(List<ScopedFilter> filters, MetadataFormat metadataFormat, int maxResponseLength, ResumptionToken.Value resumptionToken) throws HandlerException {

int offset = resumptionToken.getOffset().intValue();
String setSpec = resumptionToken.getSetSpec();
Instant from = resumptionToken.getFrom();
Instant until = resumptionToken.getUntil();

logger.fine("calling getItemIdentifiers; offset=" + offset
+ ", length=" + length
+ ", length=" + maxResponseLength
+ ", setSpec=" + setSpec
+ ", from=" + from
+ ", until=" + until);
Expand All @@ -185,7 +158,7 @@ public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters,
List<ItemIdentifier> xoaiItems = new ArrayList<>();
if (oaiRecords != null && !oaiRecords.isEmpty()) {

for (int i = offset; i < offset + length && i < oaiRecords.size(); i++) {
for (int i = offset; i < offset + maxResponseLength && i < oaiRecords.size(); i++) {
OAIRecord record = oaiRecords.get(i);
xoaiItems.add(new DataverseXoaiItem(record));
}
Expand All @@ -195,13 +168,14 @@ public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters,
// formatted output in the header:
addExtraSets(xoaiItems, setSpec, from, until);

boolean hasMore = offset + length < oaiRecords.size();
ListItemIdentifiersResult result = new ListItemIdentifiersResult(hasMore, xoaiItems);
boolean hasMore = offset + maxResponseLength < oaiRecords.size();
//ListItemIdentifiersResult result = new ListItemIdentifiersResult(hasMore, xoaiItems);
ResultsPage<ItemIdentifier> result = new ResultsPage(resumptionToken, hasMore, xoaiItems, oaiRecords.size());
logger.fine("returning result with " + xoaiItems.size() + " items.");
return result;
}

return new ListItemIdentifiersResult(false, xoaiItems);
return new ResultsPage(resumptionToken, false, xoaiItems, 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.gdcc.xoai.model.xoai.Element;
import io.gdcc.xoai.dataprovider.repository.SetRepository;
import io.gdcc.xoai.dataprovider.handlers.results.ListSetsResult;
//import io.gdcc.xoai.dataprovider.handlers.results.ListSetsResult;
import io.gdcc.xoai.dataprovider.model.Set;
import io.gdcc.xoai.model.xoai.XOAIMetadata;
import edu.harvard.iq.dataverse.harvest.server.OAISet;
Expand Down Expand Up @@ -47,7 +47,7 @@ public boolean supportSets() {
}

@Override
public ListSetsResult retrieveSets(int offset, int length) {
public List<Set> getSets() { //int offset, int length) {
logger.fine("calling retrieveSets()");
List<OAISet> dataverseOAISets = setService.findAllNamedSets();
List<Set> XOAISets = new ArrayList<Set>();
Expand All @@ -66,7 +66,7 @@ public ListSetsResult retrieveSets(int offset, int length) {
}
}

return new ListSetsResult(offset + length < XOAISets.size(), XOAISets.subList(offset, Math.min(offset + length, XOAISets.size())));
return XOAISets;
}

@Override
Expand Down

This file was deleted.

0 comments on commit 09b6441

Please sign in to comment.