Commit ab4528ad authored by Oscar Scholten's avatar Oscar Scholten

CMS-9632: processing review comments:

- adding unit test to document expected behavior when combining returnParentNode with selecting properties
- adding reload on startup
- updated getReturnParentNode to isReturnParentNode
= using static imports in JcrQueryNode
parent 34aab44f
......@@ -20,7 +20,7 @@ package org.onehippo.cms7.services.search.query.reflect;
*/
public interface QueryNode {
boolean getReturnParentNode();
boolean isReturnParentNode();
int getLimit();
......
......@@ -79,7 +79,7 @@ public class QueryImpl implements Query, QueryNode {
}
@Override
public final boolean getReturnParentNode() {
public final boolean isReturnParentNode() {
return returnParentNode;
}
......
......@@ -132,6 +132,10 @@ public class JcrQueryBuilder {
query.insert(0, "//*");
}
if (this.returnParentNode) {
query.append("/..");
}
if (!this.selected.isEmpty()) {
boolean first = true;
for (String property : selected) {
......@@ -153,10 +157,6 @@ public class JcrQueryBuilder {
}
}
if (this.returnParentNode) {
query.append("/..");
}
if (orderByList.size() > 0) {
query.append(" order by ");
boolean first = true;
......@@ -202,7 +202,7 @@ public class JcrQueryBuilder {
this.selected.add(property);
}
public boolean getReturnParentNode() {
public boolean isReturnParentNode() {
return returnParentNode;
}
......
......@@ -50,7 +50,7 @@ public class JcrQueryVisitor implements QueryVisitor {
@Override
public void visit(final QueryNode query) {
if (query.getReturnParentNode()) {
if (query.isReturnParentNode()) {
builder.setReturnParentNode();
}
if (query.getLimit() != -1) {
......
......@@ -56,7 +56,7 @@ class JcrPersistingQueryVisitor implements QueryVisitor {
@Override
public void visit(final QueryNode query) {
node.setReturnParentNode(query.getReturnParentNode());
node.setReturnParentNode(query.isReturnParentNode());
node.setLimit(query.getLimit());
node.setOffset(query.getOffset());
}
......
......@@ -111,7 +111,7 @@ public class JcrQueryReader {
}
}
if (node.getReturnParentNode()) {
if (node.isReturnParentNode()) {
query = query.returnParentNode();
}
......
......@@ -17,6 +17,12 @@
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>9.0</sv:value>
</sv:property>
<sv:property sv:name="hippo:reloadonstartup" sv:type="Boolean">
<sv:value>true</sv:value>
</sv:property>
<sv:property sv:name="hippo:version" sv:type="String">
<sv:value>2.2.0</sv:value>
</sv:property>
</sv:node>
</sv:node>
/*
* Copyright 2015 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.cms7.services.search.jcr.query;
import javax.jcr.RepositoryException;
import org.junit.Before;
import org.junit.Test;
import org.onehippo.cms7.services.search.jcr.service.HippoJcrSearchService;
import org.onehippo.cms7.services.search.query.Query;
import org.onehippo.cms7.services.search.result.QueryResult;
import org.onehippo.repository.testutils.RepositoryTestCase;
import static org.junit.Assert.assertEquals;
import static org.onehippo.cms7.services.search.query.QueryUtils.text;
public class TestReturnParentNodeExpectations extends RepositoryTestCase {
private HippoJcrSearchService searchService;
@Before
final public void createTestData() throws RepositoryException {
String[] content = {
"/test", "nt:unstructured",
"/test/content", "hippostd:folder",
"/test/content/document-with-properties", "hippo:handle",
"jcr:mixinTypes", "mix:referenceable,hippostd:relaxed",
"myproperty", "handle",
"/test/content/document-with-properties/document-with-properties", "hippo:document",
"jcr:mixinTypes", "mix:referenceable,hippostd:relaxed",
"hippo:availability", "live",
"myproperty", "live",
"/test/content/document-with-properties/document-with-properties/description", "hippostd:html",
"hippostd:content", "live variant",
"/test/content/document-with-properties/document-with-properties", "hippo:document",
"jcr:mixinTypes", "mix:referenceable,hippostd:relaxed",
"hippo:availability", "preview",
"myproperty", "preview",
"/test/content/document-with-properties/document-with-properties[2]/description", "hippostd:html",
"hippostd:content", "preview variant",
};
build(content, session);
session.save();
}
@Before
final public void createSearchService() {
searchService = new HippoJcrSearchService();
searchService.setSession(session);
}
@Test
public void expect_properties_of_variant_to_be_returned() {
Query searchQuery = searchService.createQuery()
.ofType("hippo:document")
.select("myproperty")
.where(text("hippo:availability").contains("live"));
QueryResult queryResult = searchService.search(searchQuery);
assertEquals("live", queryResult.getHits().nextHit().getSearchDocument().getFieldValue("myproperty"));
}
@Test
public void expect_properties_of_handle_to_be_returned() {
Query searchQuery = searchService.createQuery()
.ofType("hippo:document")
.select("myproperty")
.where(text("hippo:availability").contains("live"))
.returnParentNode();
QueryResult queryResult = searchService.search(searchQuery);
assertEquals("handle", queryResult.getHits().nextHit().getSearchDocument().getFieldValue("myproperty"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment