Skip to content

Commit

Permalink
Feature/oaipmh without dep max modified (#509)
Browse files Browse the repository at this point in the history
* Make emitRecord take Documents instead of sql resultsets.

* Make both from and until optional again.

* Make the adhoc tests at least possibly reusable.
  • Loading branch information
jannistsiroyannis authored Jan 29, 2020
1 parent 2d2e9eb commit 15658ef
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 162 deletions.
82 changes: 82 additions & 0 deletions oaipmh/adhoc_cmptest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

start=$(date --utc -d "today" +%Y-%m-%dT07:%M:00Z)

echo "?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&set=auth&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=auth&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=auth&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&set=bib:S&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=bib:S&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=bib:S&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&set=hold:S&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=hold:S&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=hold:S&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

# DIFFING A LITTLE, BECAUSE PROD ATM ONLY FOLLOWS LINKS IN ONE STEP
echo "?verb=ListRecords&set=bib:Li&from=$start&metadataPrefix=marcxml_includehold_expanded"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=bib:Li&from=$start&metadataPrefix=marcxml_includehold_expanded" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=bib:Li&from=$start&metadataPrefix=marcxml_includehold_expanded" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is expected:"
diff oldcode newcode

# DIFFING A LITTLE, BECAUSE PROD ATM ONLY FOLLOWS LINKS IN ONE STEP
echo "?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld_expanded"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld_expanded" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=hold&from=$start&metadataPrefix=jsonld_expanded" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is expected:"
diff oldcode newcode

echo "?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=GetRecord&identifier=https://libris.kb.se/6h4rcxkn4fqlm9h5&metadataPrefix=marcxml"
curl -s "localhost:8080/oaipmh/?verb=GetRecord&identifier=https://libris.kb.se/6h4rcxkn4fqlm9h5&metadataPrefix=marcxml" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=GetRecord&identifier=https://libris.kb.se/6h4rcxkn4fqlm9h5&metadataPrefix=marcxml" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&set=bib&from=$start&until=2020-01-11T11:00:00Z&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&until=2020-01-11T11:00:00Z&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&set=bib&from=$start&until=2020-01-11T11:00:00Z&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode

echo "?verb=ListRecords&from=$start&metadataPrefix=jsonld"
curl -s "localhost:8080/oaipmh/?verb=ListRecords&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > newcode &
curl -s "export-prod.libris.kb.se:8080/oaipmh/?verb=ListRecords&from=$start&metadataPrefix=jsonld" | xmllint --format - | wc -l > oldcode &
wait
echo "Diff is:"
diff oldcode newcode
7 changes: 3 additions & 4 deletions oaipmh/src/main/java/whelk/export/servlet/GetRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public static void handleGetRecordRequest(HttpServletRequest request, HttpServle
try (Connection dbconn = OaiPmh.s_whelk.getStorage().getConnection())
{
dbconn.setAutoCommit(false);
try (PreparedStatement preparedStatement = Helpers.getMatchingDocumentsStatement(dbconn, null, null, null, id, false);
ResultSet resultSet = preparedStatement.executeQuery())
try (Helpers.ResultIterator it = Helpers.getMatchingDocuments(dbconn, null, null, null, id, false))
{
if (!resultSet.next())
if (!it.hasNext())
{
failedRequests.labels(OaiPmh.OAIPMH_ERROR_NO_RECORDS_MATCH).inc();
ResponseCommon.sendOaiPmhError(OaiPmh.OAIPMH_ERROR_NO_RECORDS_MATCH, "", request, response);
Expand All @@ -95,7 +94,7 @@ public static void handleGetRecordRequest(HttpServletRequest request, HttpServle
ResponseCommon.writeOaiPmhHeader(writer, request, true);
writer.writeStartElement("GetRecord");

ResponseCommon.emitRecord(resultSet, writer, metadataPrefix, false,
ResponseCommon.emitRecord(it.next(), writer, metadataPrefix, false,
metadataPrefix.contains(OaiPmh.FORMAT_EXPANDED_POSTFIX), withDeletedData);

writer.writeEndElement(); // GetRecord
Expand Down
Loading

0 comments on commit 15658ef

Please sign in to comment.