Skip to content

Commit

Permalink
Fix dateTime values in filter
Browse files Browse the repository at this point in the history
- Fix String value creation for JQL transformations
- Add test for JQLConverter

Resolves: https://www.pivotaltracker.com/story/show/77788512
  • Loading branch information
fasseg authored and Andrew Woods committed Sep 2, 2014
1 parent d66f411 commit 6bcaf3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Expand Up @@ -791,7 +791,7 @@ public void visit(final ExprFunction2 func) {
+ func.getArg1() + "; " + func.getArg2());
} else {
final String op;
String value = func.getArg2().getConstant().getString();
NodeValue value = func.getArg2().getConstant();
switch(funcName) {
case "eq":
op = JCR_OPERATOR_EQUAL_TO;
Expand All @@ -813,15 +813,15 @@ public void visit(final ExprFunction2 func) {
break;
case "contains":
op = JCR_OPERATOR_LIKE;
value = "%" + value + "%";
value = NodeValue.makeString("%" + value.asUnquotedString() + "%");
break;
case "strstarts":
op = JCR_OPERATOR_LIKE;
value = value + "%";
value = NodeValue.makeString(value.asUnquotedString() + "%");
break;
case "strends":
op = JCR_OPERATOR_LIKE;
value = "%" + value;
value = NodeValue.makeString("%" + value.asUnquotedString());
break;
default:
throw new NotImplementedException(funcName);
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.fcrepo.integration;

import org.fcrepo.kernel.RdfLexicon;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.impl.DefaultIdentifierTranslator;
import org.fcrepo.transform.sparql.JQLConverter;
Expand Down Expand Up @@ -270,7 +271,6 @@ public void testStrendsFilter() throws RepositoryException {

}


@Test
public void testComplexQuery() throws RepositoryException {

Expand Down Expand Up @@ -358,4 +358,15 @@ public void testConstantSubjectReferenceQuery() throws RepositoryException {
final JQLConverter testObj = new JQLConverter(session, subjects, sparql);
assertEquals(expectedQuery, testObj.getStatement());
}

@Test
public void testDateConstraintsQuery() throws RepositoryException {
final String sparql = "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?s ?o WHERE {?s <" +
RdfLexicon.LAST_MODIFIED_DATE + "> ?o . FILTER (?o <= \"2013-01-01T00:30Z\"^^xsd:dateTime)}";
final JQLConverter converter = new JQLConverter(session, subjects, sparql);
final String expected = "SELECT [fedoraResource_s].[jcr:path] AS s, [fedoraResource_s].[jcr:lastModified] " +
"AS o FROM [fedora:resource] AS [fedoraResource_s] WHERE ([fedoraResource_s].[jcr:lastModified] IS " +
"NOT NULL AND [fedoraResource_s].[jcr:lastModified] <= '2013-01-01T00:30Z')";
assertEquals(expected, converter.getStatement());
}
}

0 comments on commit 6bcaf3d

Please sign in to comment.