Skip to content

Commit

Permalink
Issues #542, #549, #552
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Jul 29, 2024
1 parent c112925 commit 234c424
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 19 deletions.
75 changes: 61 additions & 14 deletions sdnnt/src/main/java/cz/inovatika/sdnnt/oai/OAIRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import cz.inovatika.sdnnt.Options;
import static cz.inovatika.sdnnt.index.Indexer.getClient;
import cz.inovatika.sdnnt.indexer.models.MarcRecord;
import cz.inovatika.sdnnt.indexer.models.oai.Format;

import static cz.inovatika.sdnnt.oai.OAIServlet.LOGGER;
import java.io.IOException;
import java.time.LocalDateTime;
Expand All @@ -16,12 +18,16 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Date;
import java.util.logging.Level;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import cz.inovatika.sdnnt.model.DataCollections;
import cz.inovatika.sdnnt.model.PublicItemState;
import cz.inovatika.sdnnt.utils.StringUtils;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
Expand All @@ -40,7 +46,9 @@
*/
public class OAIRequest {

public static String SDNNT_PREFIX_IDENTIFIER = "sdnnt.nkp.cz";
private static final String METADATA_PREFIX_PARAMETER = "metadataPrefix";

public static String SDNNT_PREFIX_IDENTIFIER = "sdnnt.nkp.cz";

// Muze byt indextime nebo datestamp
static String SORT_FIELD = "indextime";
Expand Down Expand Up @@ -94,22 +102,38 @@ public static String listSets(HttpServletRequest req) {
JSONObject sets = Options.getInstance().getJSONObject("OAI").getJSONObject("sets");
for (Object spec: sets.keySet()) {
JSONObject set = sets.getJSONObject((String) spec);
xml += "<set><setSpec>"+spec+"</setSpec><setName>"+set.getString("name")+"</setName></set>\n";
xml += "<set><setSpec>"+((StringUtils.isAnyString(spec.toString()) ? spec.toString():"none")) +"</setSpec><setName>"+set.getString("name")+"</setName></set>\n";
}
xml += "</ListSets>\n"
+ "</OAI-PMH>";
return xml;
}

public static String metadataFormats(HttpServletRequest req) {
String xml = headerOAI() + responseDateTag() + requestTag(req)
+ "<ListMetadataFormats>"
+ "<metadataFormat><metadataPrefix>marc21</metadataPrefix><schema>http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd</schema>"
+ "<metadataNamespace>http://www.loc.gov/MARC21/slim</metadataNamespace>"
+ "</metadataFormat>"
+ "</ListMetadataFormats>"
+ "</OAI-PMH>";
return xml;

String prefixes = Arrays.asList(Format.values()).stream().map(f-> {
StringBuilder builder = new StringBuilder("<metadataFormat>");
builder.append( String.format("<metadataPrefix>%s</metadataPrefix>", f.name()));
if (f.getSchema() != null) {
builder.append(String.format("<schema>%s</schema>", f.getSchema()));
}
if (f.getDefaultNamespace() != null) {
builder.append(String.format("<metadataNamespace>%s</metadataNamespace>", f.getDefaultNamespace()));
}
builder.append("</metadataFormat>");
return builder.toString();
}).collect(Collectors.joining("\n"));


String xml = headerOAI() + responseDateTag() + requestTag(req)+String.format("<ListMetadataFormats>%s</ListMetadataFormats>", prefixes)+ "</OAI-PMH>";
// + "<ListMetadataFormats>"
// + "<metadataFormat><metadataPrefix>marc21</metadataPrefix><schema>http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd</schema>"
// + "<metadataNamespace>http://www.loc.gov/MARC21/slim</metadataNamespace>"
// + "</metadataFormat>"
// + "</ListMetadataFormats>"
// + "</OAI-PMH>";

return xml;
}

public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers) {
Expand All @@ -127,7 +151,7 @@ public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers
.setRows(rows)
.addSort(SORT_FIELD, SolrQuery.ORDER.asc)
.addSort(CURSOR_FIELD, SolrQuery.ORDER.asc)
.setFields(SORT_FIELD, "identifier,id_sdnnt,raw,dntstav,datum_stavu,license,license_history,historie_stavu,granularity");
.setFields(SORT_FIELD, "identifier,id_sdnnt,raw,dntstav,datum_stavu,license,license_history,historie_stavu,granularity,masterlinks,masterlinks_disabled,digital_libraries");
if (req.getParameter("from") != null) {
String from = req.getParameter("from");
String until = "*";
Expand All @@ -142,6 +166,12 @@ public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers
query.addFilterQuery(Options.getInstance().getJSONObject("OAI").getJSONObject("sets").getJSONObject(set).getString("filter"));
}

Format format = Format.marc21;
if (StringUtils.isAnyString(req.getParameter(METADATA_PREFIX_PARAMETER))) {
format = Format.valueOf(req.getParameter(METADATA_PREFIX_PARAMETER));
}


if (req.getParameter("resumptionToken") != null) {
String rt = req.getParameter("resumptionToken").replaceAll(" ", "+");
// Change it by PS; only checks (configurations, aio exceptions etc..)
Expand All @@ -155,13 +185,18 @@ public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers
query.addFilterQuery(Options.getInstance().getJSONObject("OAI").getJSONObject("sets")
.getJSONObject(set).getString("filter"));
}
if (parts.length>=3) {
format=Format.valueOf(parts[2]);
}
}
}
query.setParam(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
} else {
query.setParam(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
}



QueryResponse qr = getClient().query(DataCollections.catalog.name(), query);
String nextCursorMark = qr.getNextCursorMark();
SolrDocumentList docs = qr.getResults();
Expand Down Expand Up @@ -191,7 +226,10 @@ public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers

// Changed identifiers
if (!deletedStatus) {
ret.append(mr.toXml(onlyIdentifiers, false));
if (!onlyIdentifiers) {
ret.append(format.record(mr));
}
//ret.append(mr.toXml(onlyIdentifiers, false));
}
ret.append("</record>");
}
Expand All @@ -201,7 +239,7 @@ public static String listRecords(HttpServletRequest req, boolean onlyIdentifiers

ret.append("<resumptionToken completeListSize=\"" + docs.getNumFound() + "\">")
//.append(DateTimeFormatter.ofPattern("yyyyMMddHHmmss.SSS").withZone(ZoneId.systemDefault()).format(last.toInstant()))
.append(nextCursorMark).append(":").append(set).append(":").append("marc21")
.append(nextCursorMark).append(":").append(set).append(":").append(format.name())
.append("</resumptionToken>");
}
ret.append("</" + verb + ">");
Expand Down Expand Up @@ -234,6 +272,7 @@ private static String sdnntPrefixIdentifier() {
}

public static String getRecord(HttpServletRequest req) {

Options opts = Options.getInstance();
StringBuilder ret = new StringBuilder();
ret.append(headerOAI())
Expand All @@ -260,6 +299,13 @@ public static String getRecord(HttpServletRequest req) {
} else {
query.addFilterQuery("dntstav:*");
}

Format format = Format.marc21;
if (StringUtils.isAnyString(req.getParameter(METADATA_PREFIX_PARAMETER))) {
Format.valueOf(req.getParameter(METADATA_PREFIX_PARAMETER));
}



SolrDocumentList docs = solr.query(DataCollections.catalog.name(), query).getResults();
if (docs.getNumFound() == 0) {
Expand Down Expand Up @@ -289,7 +335,8 @@ public static String getRecord(HttpServletRequest req) {
}
ret.append("</header>");
if (!deletedStatus) {
ret.append(mr.toXml(false, false));
ret.append(format.record(mr));
//ret.append(mr.toXml(false, false));
}
ret.append("</record>");
}
Expand Down
8 changes: 4 additions & 4 deletions sdnnt/src/main/ui/src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"tooltip": {
"undefined": "Nezařazeno - dílo je nezařazeno na Seznamu, je volně dostupné k návrhu na zařazení",
"NNN": "Není na seznamu",
"NPA": "Dílo bude publikováno jako Návrh k zařazení do seznamu, datum přepnutí 1.3 nebo 1.9",
"NPA": "Dílo bude publikováno jako Návrh k zařazení do seznamu, datum přepnutí 1. den následujícího měsíce",
"PA": "Dílo publikováno jako Návrh k zařazení do seznamu, běží mu 6 měsíců do přeřazení k stavu A",
"A": "Zařazeno - dílo je zařazeno na Seznamu a má přiřazené licence k použití. V případě digitální verze je dostupný prolink na dílo do digitální knihovny (DK) typu Kramerius",
"VN": "Výzva k vyřazení",
Expand Down Expand Up @@ -898,17 +898,17 @@
"zaznamu": "záznamů",

"debug_nzn_0_5wd":"5 pracovních dnů",
"debug_nzn_1_12_18":"1.3 nebo 1.9",
"debug_nzn_1_12_18":"1. den následujícího měsíce",
"debug_nzn_2_6m":"6 měsíců",
"debug_vn_0_28d":"28 dnů",
"debug_vn_0_28d":"15 dnů",
"debug_vnl_0_5wd":"5 pracovních dnů",
"debug_vnl_1_10wd":"10 kalendářních dnů",
"debug_vnl_2_18m":"18 měsíců",
"debug_vnl_3_5wd":"5 pracovních dnů",
"debug_px_0_5wd":"5 pracovních dnů",

"period_nzn_0_5wd":"5 pracovních dnů",
"period_nzn_1_12_18": "1.3 nebo 1.9",
"period_nzn_1_12_18": "1. den následujícího měsíce",
"period_nzn_2_6m": "6 měsíců",
"period_vn_0_28d": "15 dnů",
"period_vln_0_5wd": "5 pracovních dnů",
Expand Down
2 changes: 1 addition & 1 deletion sdnnt/src/main/ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"tooltip": {
"undefined": "Unclassified - the work is not included in the List, it is freely available for proposal for inclusion",
"NNN": "Not in List",
"NPA": "Work will published as Proposal for inclusion in the list, it switches on 1.3 or 1.9",
"NPA": "Work will published as Proposal for inclusion in the list, it switches on the 1st of every month",
"PA": "Work published as Proposal for inclusion in the list, it runs for 6 months until reassignment to status A",
"A": "Included - the work is included in the List and has assigned licenses for use. In the case of the digital version, a link to the work in a Kramerius digital library (DK) is available",
"VN": "Discarded - the work was on the Draft List (PA), but is discarded; the work may be subject to NZN or administrative corrections",
Expand Down

0 comments on commit 234c424

Please sign in to comment.