From f0f886be92d37c83dc166b08e1c1e6ea64991343 Mon Sep 17 00:00:00 2001 From: Gethin James Date: Tue, 6 Sep 2016 15:36:44 +0000 Subject: [PATCH] Merged searchapi (5.2.1) to 5.2.N (5.2.1) 130028 gjames: SEARCH-120: Moving SearchContext and facets to its own package git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130289 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../api/search/context/FacetQueryContext.java | 51 +++++++++++++++++++ .../search/context}/SearchContext.java | 31 ++--------- .../rest/api/search/impl/ResultMapper.java | 8 +-- .../resource/SerializablePagedCollection.java | 2 +- .../parameters/CollectionWithPagingInfo.java | 1 + .../rest/api/search/ResultMapperTests.java | 2 +- .../search/SearchQuerySerializerTests.java | 6 +-- .../framework/tests/core/SerializeTests.java | 1 - 8 files changed, 65 insertions(+), 37 deletions(-) create mode 100644 source/java/org/alfresco/rest/api/search/context/FacetQueryContext.java rename source/java/org/alfresco/rest/{framework/resource/parameters => api/search/context}/SearchContext.java (72%) diff --git a/source/java/org/alfresco/rest/api/search/context/FacetQueryContext.java b/source/java/org/alfresco/rest/api/search/context/FacetQueryContext.java new file mode 100644 index 0000000000..b371143664 --- /dev/null +++ b/source/java/org/alfresco/rest/api/search/context/FacetQueryContext.java @@ -0,0 +1,51 @@ +/*- + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.api.search.context; + +/** + * The results of a facet query + */ +public class FacetQueryContext +{ + private final String label; + private final int count; + + public FacetQueryContext(String label, int count) + { + this.label = label; + this.count = count; + } + + public String getLabel() + { + return label; + } + + public int getCount() + { + return count; + } +} diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/SearchContext.java b/source/java/org/alfresco/rest/api/search/context/SearchContext.java similarity index 72% rename from source/java/org/alfresco/rest/framework/resource/parameters/SearchContext.java rename to source/java/org/alfresco/rest/api/search/context/SearchContext.java index 90e937a764..180772ff47 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/SearchContext.java +++ b/source/java/org/alfresco/rest/api/search/context/SearchContext.java @@ -23,10 +23,9 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.framework.resource.parameters; +package org.alfresco.rest.api.search.context; import java.util.List; -import java.util.Map; /** * The contextual results of a Search @@ -34,9 +33,9 @@ import java.util.Map; public class SearchContext { private final Consistency consistency; - private final List facetQueries; + private final List facetQueries; - public SearchContext(long lastTxId, List facetQueries) + public SearchContext(long lastTxId, List facetQueries) { if (lastTxId > 0) { @@ -54,33 +53,11 @@ public class SearchContext return consistency; } - public List getFacetQueries() + public List getFacetQueries() { return facetQueries; } - public static class FacetQueryResult - { - private final String label; - private final int count; - - public FacetQueryResult(String label, int count) - { - this.label = label; - this.count = count; - } - - public String getLabel() - { - return label; - } - - public int getCount() - { - return count; - } - } - public class Consistency { private final long lastTxId; diff --git a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java index 91dec4cf88..d80c10d5c6 100644 --- a/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java +++ b/source/java/org/alfresco/rest/api/search/impl/ResultMapper.java @@ -33,8 +33,8 @@ import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.api.search.model.SearchEntry; import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.SearchContext; -import org.alfresco.rest.framework.resource.parameters.SearchContext.FacetQueryResult; +import org.alfresco.rest.api.search.context.SearchContext; +import org.alfresco.rest.api.search.context.FacetQueryContext; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; @@ -134,14 +134,14 @@ public class ResultMapper { SearchContext context = null; Map facetQueries = solrResultSet.getFacetQueries(); - List facetResults = null; + List facetResults = null; if(facetQueries!= null && !facetQueries.isEmpty()) { facetResults = new ArrayList<>(facetQueries.size()); for (Entry fq:facetQueries.entrySet()) { - facetResults.add(new FacetQueryResult(fq.getKey(), fq.getValue())); + facetResults.add(new FacetQueryContext(fq.getKey(), fq.getValue())); } } context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults); diff --git a/source/java/org/alfresco/rest/framework/resource/SerializablePagedCollection.java b/source/java/org/alfresco/rest/framework/resource/SerializablePagedCollection.java index 7ccebca2d2..968b9c6172 100644 --- a/source/java/org/alfresco/rest/framework/resource/SerializablePagedCollection.java +++ b/source/java/org/alfresco/rest/framework/resource/SerializablePagedCollection.java @@ -26,7 +26,7 @@ package org.alfresco.rest.framework.resource; -import org.alfresco.rest.framework.resource.parameters.SearchContext; +import org.alfresco.rest.api.search.context.SearchContext; import org.alfresco.rest.framework.resource.parameters.Paging; import java.util.Collection; diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/CollectionWithPagingInfo.java b/source/java/org/alfresco/rest/framework/resource/parameters/CollectionWithPagingInfo.java index 0d87fc9909..cff6072f6e 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/CollectionWithPagingInfo.java +++ b/source/java/org/alfresco/rest/framework/resource/parameters/CollectionWithPagingInfo.java @@ -25,6 +25,7 @@ */ package org.alfresco.rest.framework.resource.parameters; +import org.alfresco.rest.api.search.context.SearchContext; import org.alfresco.rest.framework.resource.SerializablePagedCollection; import java.util.Arrays; diff --git a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java index ad4cff9541..5709888b90 100644 --- a/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java +++ b/source/test-java/org/alfresco/rest/api/search/ResultMapperTests.java @@ -43,7 +43,7 @@ import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.api.search.impl.ResultMapper; import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.SearchContext; +import org.alfresco.rest.api.search.context.SearchContext; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; diff --git a/source/test-java/org/alfresco/rest/api/search/SearchQuerySerializerTests.java b/source/test-java/org/alfresco/rest/api/search/SearchQuerySerializerTests.java index 83c9b4f20c..3e5624bd73 100644 --- a/source/test-java/org/alfresco/rest/api/search/SearchQuerySerializerTests.java +++ b/source/test-java/org/alfresco/rest/api/search/SearchQuerySerializerTests.java @@ -31,8 +31,8 @@ import org.alfresco.rest.api.search.model.Default; import org.alfresco.rest.api.search.model.SearchQuery; import org.alfresco.rest.framework.jacksonextensions.ExecutionResult; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.SearchContext; -import org.alfresco.rest.framework.resource.parameters.SearchContext.FacetQueryResult; +import org.alfresco.rest.api.search.context.SearchContext; +import org.alfresco.rest.api.search.context.FacetQueryContext; import org.alfresco.rest.framework.tests.api.mocks.Farmer; import org.junit.BeforeClass; import org.junit.Test; @@ -92,7 +92,7 @@ public class SearchQuerySerializerTests public void testSerializeContext() throws IOException { ExecutionResult exec1 = new ExecutionResult(new Farmer("180"),null); - SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryResult("f1", 15), new FacetQueryResult("f2", 20))); + SearchContext searchContext = new SearchContext(23l, Arrays.asList(new FacetQueryContext("f1", 15), new FacetQueryContext("f2", 20))); CollectionWithPagingInfo coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext); String out = helper.writeResponse(coll); assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}")); diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java index 2009ad8d82..76a91ce7c8 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java @@ -49,7 +49,6 @@ import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResource import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.content.BinaryProperty; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.SearchContext; import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Params; import org.alfresco.rest.framework.tests.api.mocks.Farmer;