From 4b901e5846a22e1a77c7920296d0bd884242efb5 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Tue, 14 Apr 2020 14:23:34 +0200 Subject: [PATCH] [ SEARCH-2181 ] Use MaxResults in NodeMetaDataParameters --- .../alfresco/solr/SolrInformationServer.java | 29 ++++++---- .../solr/client/NodeMetaDataParameters.java | 57 ++++++++++--------- .../alfresco/solr/client/SOLRAPIClient.java | 9 ++- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index 7b70144db..7191588a6 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -144,7 +144,6 @@ import org.alfresco.solr.content.SolrContentStore; import org.alfresco.solr.logging.Log; import org.alfresco.solr.tracker.IndexHealthReport; import org.alfresco.solr.tracker.TrackerStats; -import org.alfresco.solr.utils.Utils; import org.alfresco.util.ISO9075; import org.alfresco.util.Pair; import org.apache.commons.io.input.BoundedInputStream; @@ -1514,7 +1513,8 @@ public class SolrInformationServer implements InformationServer } else { - nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE); + nmdp.setMaxResults(Integer.MAX_VALUE); + nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); } NodeMetaData nodeMetaData; @@ -1558,8 +1558,8 @@ public class SolrInformationServer implements InformationServer NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); nmdp.setFromNodeId(node.getId()); nmdp.setToNodeId(node.getId()); - - Collection nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE); + nmdp.setMaxResults(Integer.MAX_VALUE); + Collection nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); AddUpdateCommand addDocCmd = new AddUpdateCommand(request); addDocCmd.overwrite = overwrite; @@ -1723,8 +1723,9 @@ public class SolrInformationServer implements InformationServer nmdp.setIncludePaths(true); nmdp.setIncludeProperties(false); nmdp.setIncludeTxnId(true); + nmdp.setMaxResults(1); // Gets only one - Collection nodeMetaDatas = nodesMetaDataFromRepository(nmdp, 1); + Collection nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); allNodeMetaDatas.addAll(nodeMetaDatas); } @@ -1867,7 +1868,8 @@ public class SolrInformationServer implements InformationServer nmdp.setIncludeAspects(false); nmdp.setIncludePaths(false); nmdp.setIncludeParentAssociations(false); - nodeMetaDatas.addAll(nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE)); + nmdp.setMaxResults(Integer.MAX_VALUE); + nodeMetaDatas.addAll(getNodesMetaDataFromRepository(nmdp)); } for (NodeMetaData nodeMetaData : nodeMetaDatas) @@ -1912,7 +1914,8 @@ public class SolrInformationServer implements InformationServer nmdp.setIncludeChildAssociations(false); // Fetches bulk metadata - Collection nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE); + nmdp.setMaxResults(Integer.MAX_VALUE); + Collection nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); NEXT_NODE: for (NodeMetaData nodeMetaData : nodeMetaDatas) @@ -2489,7 +2492,8 @@ public class SolrInformationServer implements InformationServer NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); nmdp.setFromNodeId(dbId); nmdp.setToNodeId(dbId); - Collection nodeMetaDatas = nodesMetaDataFromRepository(nmdp, Integer.MAX_VALUE); + nmdp.setMaxResults(Integer.MAX_VALUE); + Collection nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); SolrInputDocument newDoc = null; if (!nodeMetaDatas.isEmpty()) { @@ -3380,8 +3384,9 @@ public class SolrInformationServer implements InformationServer nmdp.setIncludeProperties(false); nmdp.setIncludeType(false); nmdp.setIncludeTxnId(true); + nmdp.setMaxResults(1); // Gets only one - Collection nodeMetaDatas = nodesMetaDataFromRepository(nmdp, 1); + Collection nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); if (!nodeMetaDatas.isEmpty()) { @@ -3829,11 +3834,11 @@ public class SolrInformationServer implements InformationServer solrContentStore.flushChangeSet(); } - private Collection nodesMetaDataFromRepository(NodeMetaDataParameters parameters, int maxResults) + private Collection getNodesMetaDataFromRepository(NodeMetaDataParameters parameters) { try { - return notNullOrEmpty(repositoryClient.getNodesMetaData(parameters, maxResults)); + return notNullOrEmpty(repositoryClient.getNodesMetaData(parameters)); } catch (JSONException exception) { @@ -3842,7 +3847,7 @@ public class SolrInformationServer implements InformationServer } catch (Exception exception) { - LOGGER.error("Unable to get nodes metadata from repository. See the stacktrace below for further details."); + LOGGER.error("Unable to get nodes metadata from repository. See the stacktrace below for further details.", exception); return Collections.emptyList(); } } diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/NodeMetaDataParameters.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/NodeMetaDataParameters.java index 20f67ceef..303a32af1 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/NodeMetaDataParameters.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/NodeMetaDataParameters.java @@ -1,31 +1,32 @@ -/* - * #%L - * Alfresco Solr Client - * %% - * 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% - */ +/* + * #%L + * Alfresco Solr Client + * %% + * 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.solr.client; import java.util.List; +import java.util.OptionalInt; /** * Stores node meta data query parameters for use in SOLR remote api calls @@ -39,7 +40,7 @@ public class NodeMetaDataParameters private Long toTxnId; // default is 'all' results - private int maxResults = 0; + private OptionalInt maxResults = OptionalInt.empty(); private Long fromNodeId; private Long toNodeId; @@ -147,14 +148,14 @@ public class NodeMetaDataParameters this.includeParentAssociations = includeParentAssociations; } - public int getMaxResults() + public OptionalInt getMaxResults() { return maxResults; } public void setMaxResults(int maxResults) { - this.maxResults = maxResults; + this.maxResults = OptionalInt.of(maxResults); } public List getNodeIds() diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java index 628114700..51864069b 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java @@ -732,7 +732,7 @@ public class SOLRAPIClient return ret; } - public List getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws AuthenticationException, IOException, JSONException + public List getNodesMetaData(NodeMetaDataParameters params) throws AuthenticationException, IOException, JSONException { List nodeIds = params.getNodeIds(); @@ -801,13 +801,16 @@ public class SOLRAPIClient body.put("includeTxnId", params.isIncludeTxnId()); } - body.put("maxResults", maxResults); + if (params.getMaxResults().isPresent()) + { + body.put("maxResults", params.getMaxResults()); + } PostRequest req = new PostRequest(url.toString(), body.toString(), "application/json"); JSONObject json = callRepository(GET_METADATA_URL, req); JSONArray jsonNodes = json.getJSONArray("nodes"); - List nodes = new ArrayList(jsonNodes.length()); + List nodes = new ArrayList<>(jsonNodes.length()); for(int i = 0; i < jsonNodes.length(); i++) { JSONObject jsonNodeInfo = jsonNodes.getJSONObject(i);