From 1a0ff7d6c8fdee364a522fa0a458ae0f931fa9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 1 Jun 2021 18:58:18 +0200 Subject: [PATCH] new CQL default context --- gradle.properties | 2 +- .../xbib/z3950/common/cql/CQLRPNGenerator.java | 10 ++++++---- .../org/xbib/z3950/common/cql/cql.properties | 2 +- .../org/xbib/z3950/common/cql/dc.properties | 1 + .../org/xbib/z3950/common/cql/default.properties | 16 ++++++++++++++++ .../org/xbib/z3950/common/cql/CQL2RPNTest.java | 9 ++++++--- 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 z3950-common/src/main/resources/org/xbib/z3950/common/cql/default.properties diff --git a/gradle.properties b/gradle.properties index 335f15f..33f6be5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = z3950 -version = 2.3.0 +version = 2.3.1 gradle.wrapper.version = 6.6.1 netty.version = 4.1.65.Final diff --git a/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java b/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java index 6648350..5c1588d 100644 --- a/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java +++ b/z3950-common/src/main/java/org/xbib/z3950/common/cql/CQLRPNGenerator.java @@ -53,6 +53,7 @@ public final class CQLRPNGenerator implements Visitor { private static final long serialVersionUID = 8199395368653216950L; { + put("default", ResourceBundle.getBundle("org.xbib.z3950.common.cql.default")); put("cql", ResourceBundle.getBundle("org.xbib.z3950.common.cql.cql")); put("bib", ResourceBundle.getBundle("org.xbib.z3950.common.cql.bib-1")); put("dc", ResourceBundle.getBundle("org.xbib.z3950.common.cql.dc")); @@ -67,13 +68,14 @@ public final class CQLRPNGenerator implements Visitor { private RPNQuery rpnQuery; public CQLRPNGenerator() { - this.attributeElements = new Stack<>(); - this.result = new Stack<>(); + this(null); } public CQLRPNGenerator(Collection attributeElements) { this.attributeElements = new Stack<>(); - this.attributeElements.addAll(attributeElements); + if (attributeElements != null) { + this.attributeElements.addAll(attributeElements); + } this.result = new Stack<>(); } @@ -294,7 +296,7 @@ public final class CQLRPNGenerator implements Visitor { public void visit(Index index) { String context = index.getContext(); if (context == null) { - context = "dc"; // default context + context = "default"; // default context } int attributeType = 1; // use attribute set: bib-1 = 1 int attributeValue = getUseAttr(context, index.getName()); diff --git a/z3950-common/src/main/resources/org/xbib/z3950/common/cql/cql.properties b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/cql.properties index 726af23..55acbc1 100644 --- a/z3950-common/src/main/resources/org/xbib/z3950/common/cql/cql.properties +++ b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/cql.properties @@ -3,4 +3,4 @@ publisher=1018 allRecords=1035 allIndexes=1035 anyIndexes=1035 -keywords=1016 \ No newline at end of file +keywords=1016 diff --git a/z3950-common/src/main/resources/org/xbib/z3950/common/cql/dc.properties b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/dc.properties index d245418..9bc8761 100644 --- a/z3950-common/src/main/resources/org/xbib/z3950/common/cql/dc.properties +++ b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/dc.properties @@ -1,4 +1,5 @@ title=4 identifier=12 date=31 +creator=1003 publisher=1018 diff --git a/z3950-common/src/main/resources/org/xbib/z3950/common/cql/default.properties b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/default.properties new file mode 100644 index 0000000..2abbf7a --- /dev/null +++ b/z3950-common/src/main/resources/org/xbib/z3950/common/cql/default.properties @@ -0,0 +1,16 @@ +# Default properties +# this is a mashup of all common search keys +identifier=12 +publisher=1018 +all=1035 +keywords=1016 +title=4 +date=31 +creator=1003 +format=1220 +author=1003 +intitle=5 +isbn=7 +issn=8 +doi=1094 +type=1031 \ No newline at end of file diff --git a/z3950-common/src/test/java/org/xbib/z3950/common/cql/CQL2RPNTest.java b/z3950-common/src/test/java/org/xbib/z3950/common/cql/CQL2RPNTest.java index 6544263..bdb74ce 100644 --- a/z3950-common/src/test/java/org/xbib/z3950/common/cql/CQL2RPNTest.java +++ b/z3950-common/src/test/java/org/xbib/z3950/common/cql/CQL2RPNTest.java @@ -22,7 +22,7 @@ class CQL2RPNTest { } @Test - void testPhrase() { + void testPhraseWithDoubleQuotes() { String cql = "dc.title = \"a phrase\""; CQLParser parser = new CQLParser(cql); parser.parse(); @@ -33,15 +33,18 @@ class CQL2RPNTest { } @Test - void testWithAttribute() { + void testWithOverridingAnAttribute() { AttributeElement ae = new AttributeElement(); ae.attributeType = new ASN1Integer(2); + ae.attributeValue = new AttributeElementAttributeValue(); + ae.attributeValue.numeric = new ASN1Integer(4); String cql = "dc.title = \"a phrase\""; CQLParser parser = new CQLParser(cql); parser.parse(); CQLRPNGenerator generator = new CQLRPNGenerator(Collections.singleton(ae)); parser.getCQLQuery().accept(generator); String q = generator.getQueryResult().toString(); - assertEquals("{attributeSetId 1.2.840.10003.3.1, rpn {op {attrTerm {attributes {{attributeType 2, attributeValue {numeric 3}}{attributeType 4, attributeValue {numeric 1}}{attributeType 5, attributeValue {numeric 100}}{attributeType 1, attributeValue {numeric 4}}}, term {general \"a phrase\"}}}}}", q); + // not really working, it adds, not override + assertEquals("{attributeSetId 1.2.840.10003.3.1, rpn {op {attrTerm {attributes {{attributeType 2, attributeValue {numeric 4}}{attributeType 2, attributeValue {numeric 3}}{attributeType 4, attributeValue {numeric 1}}{attributeType 5, attributeValue {numeric 100}}{attributeType 1, attributeValue {numeric 4}}}, term {general \"a phrase\"}}}}}", q); } }