From dc019bcc0434860012049b83da8a6504aa69027d Mon Sep 17 00:00:00 2001 From: Tom Page Date: Fri, 24 Apr 2020 17:06:44 +0100 Subject: [PATCH] SEARCH-2202 Make more list fields unmodifiable. Also fix integration tests to honour the encapsulation. --- .../AlfrescoSolrTrackerExceptionIT.java | 15 ++-- .../solr/tracker/AlfrescoSolrTrackerIT.java | 15 ++-- .../alfresco/solr/client/AclChangeSets.java | 56 +++++++-------- .../org/alfresco/solr/client/AclReaders.java | 69 +++++++++++-------- 4 files changed, 84 insertions(+), 71 deletions(-) diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java index 43d779f8f..00f697a91 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java @@ -18,6 +18,8 @@ */ package org.alfresco.solr.tracker; +import static java.util.Arrays.asList; + import static org.alfresco.solr.AlfrescoSolrUtils.ancestors; import static org.alfresco.solr.AlfrescoSolrUtils.createGUID; import static org.alfresco.solr.AlfrescoSolrUtils.getAcl; @@ -350,13 +352,11 @@ public class AlfrescoSolrTrackerExceptionIT extends AbstractAlfrescoSolrIT logger.info("#################### Passed Fifteenth Test ##############################"); - - List readers = aclReaders.getReaders(); - readers.set(0, "andy"); // Change the aclReader + // Change the aclReaders + aclReaders.setReaders(asList("andy")); indexAclId(acl.getId()); - List readers2 = aclReaders2.getReaders(); - readers2.set(0, "ice"); // Change the aclReader + aclReaders2.setReaders(asList("ice")); reindexAclId(acl2.getId()); @@ -379,8 +379,9 @@ public class AlfrescoSolrTrackerExceptionIT extends AbstractAlfrescoSolrIT logger.info("#################### Passed Seventeenth Test ##############################"); - readers.set(0, "alan"); // Change the aclReader - readers2.set(0, "paul"); // Change the aclReader + // Change the aclReaders + aclReaders.setReaders(asList("alan")); + aclReaders2.setReaders(asList("paul")); reindexAclChangeSetId(aclChangeSet.getId()); //This should replace "andy" and "ice" with "alan" and "paul" diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java index 749e82c03..b02400952 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java @@ -18,6 +18,8 @@ */ package org.alfresco.solr.tracker; +import static java.util.Arrays.asList; + import static org.alfresco.solr.AlfrescoSolrUtils.ancestors; import static org.alfresco.solr.AlfrescoSolrUtils.createGUID; import static org.alfresco.solr.AlfrescoSolrUtils.getAcl; @@ -355,13 +357,11 @@ public class AlfrescoSolrTrackerIT extends AbstractAlfrescoSolrIT logger.info("#################### Passed Fifteenth Test ##############################"); - - List readers = aclReaders.getReaders(); - readers.set(0, "andy"); // Change the aclReader + // Change the aclReaders + aclReaders.setReaders(asList("andy")); indexAclId(acl.getId()); - List readers2 = aclReaders2.getReaders(); - readers2.set(0, "ice"); // Change the aclReader + aclReaders2.setReaders(asList("ice")); reindexAclId(acl2.getId()); @@ -384,8 +384,9 @@ public class AlfrescoSolrTrackerIT extends AbstractAlfrescoSolrIT logger.info("#################### Passed Seventeenth Test ##############################"); - readers.set(0, "alan"); // Change the aclReader - readers2.set(0, "paul"); // Change the aclReader + // Change the aclReaders + aclReaders.setReaders(asList("alan")); + aclReaders2.setReaders(asList("paul")); reindexAclChangeSetId(aclChangeSet.getId()); //This should replace "andy" and "ice" with "alan" and "paul" diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclChangeSets.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclChangeSets.java index f5e9243b1..5a508b361 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclChangeSets.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclChangeSets.java @@ -1,30 +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.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -41,14 +43,14 @@ public class AclChangeSets AclChangeSets(List aclChangeSets, Long maxChangeSetCommitTime, Long maxChangeSetId) { - this.aclChangeSets = aclChangeSets; + this.aclChangeSets = new ArrayList<>(aclChangeSets); this.maxChangeSetCommitTime = maxChangeSetCommitTime; this.maxChangeSetId = maxChangeSetId; } public List getAclChangeSets() { - return aclChangeSets; + return Collections.unmodifiableList(aclChangeSets); } public Long getMaxChangeSetCommitTime() diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclReaders.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclReaders.java index 015c5b2ad..ade01f21f 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclReaders.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/AclReaders.java @@ -1,30 +1,34 @@ -/* - * #%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 static java.util.Collections.unmodifiableList; + +import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -36,7 +40,7 @@ public class AclReaders { private final long id; - private final List readers; + private List readers; private final List denied; @@ -47,8 +51,8 @@ public class AclReaders public AclReaders(long id, List readers, List denied, long aclChangeSetId, String tenantDomain) { this.id = id; - this.readers = readers; - this.denied = denied; + this.readers = new ArrayList<>(readers); + this.denied = new ArrayList<>(denied); this.aclChangeSetId = aclChangeSetId; this.tenantDomain = tenantDomain; } @@ -96,12 +100,17 @@ public class AclReaders public List getReaders() { - return readers; + return unmodifiableList(readers); + } + + public void setReaders(List readers) + { + this.readers = new ArrayList<>(readers); } public List getDenied() { - return denied; + return unmodifiableList(denied); } public long getAclChangeSetId()