From 2d4140ea64726d149a9154382303e3fd65713bb6 Mon Sep 17 00:00:00 2001 From: mpichura <41297682+mpichura@users.noreply.github.com> Date: Wed, 27 Oct 2021 13:35:11 +0200 Subject: [PATCH] ACS-2147 renaming method which gets storage props (#778) * ACS-2147: Adding missing ContentStore implementation, switching some logging to trace. * ACS-2147: Renaming getObjectStorageProperties to getStorageProperties * [maven-release-plugin][skip ci] prepare release 14.20 * [maven-release-plugin][skip ci] prepare for next development iteration * Fix/mnt 21506 sanitation create people (#756) * MNT-21506: sanitize username on nodeBrowser Repo * [maven-release-plugin][skip ci] prepare release 14.21 * [maven-release-plugin][skip ci] prepare for next development iteration * ACS-2148: Adding get StorageObjectProps to ContentService (#773) * ACS-2148: Adding get StorageObjectProps to ContentService and implementation. * ACS-2148: Adding propertyQName param to get storage property method. * ACS-2148: Security config for added method. * ACS-2148: Renaming getObjectStorageProperties to getStorageProperties * ACS-2148: Javadoc fix * ACS-2148: Fixing security context after method renaming. * ACS-2148: ContentService with new method names. * ACS-2147: Adding missing ContentStore implementation, switching some logging to trace. * ACS-2147: Renaming getObjectStorageProperties to getStorageProperties * ACS-2148: ContentService with new method names. * ACS-2148: Small fixes after code review. --- .../alfresco/repo/content/ContentStore.java | 2 +- .../content/AbstractRoutingContentStore.java | 14 +-- .../repo/content/ContentServiceImpl.java | 2 +- .../content/caching/CachingContentStore.java | 4 +- .../replication/AggregatingContentStore.java | 6 +- .../AbstractTenantRoutingContentStore.java | 102 ++++++++++-------- .../content/ContentServiceImplUnitTest.java | 4 +- .../caching/CachingContentStoreTest.java | 6 +- .../AggregatingContentStoreTest.java | 26 ++--- 9 files changed, 87 insertions(+), 79 deletions(-) diff --git a/data-model/src/main/java/org/alfresco/repo/content/ContentStore.java b/data-model/src/main/java/org/alfresco/repo/content/ContentStore.java index b754afb79b..fe01a1d55e 100644 --- a/data-model/src/main/java/org/alfresco/repo/content/ContentStore.java +++ b/data-model/src/main/java/org/alfresco/repo/content/ContentStore.java @@ -340,7 +340,7 @@ public interface ContentStore * @return Returns a key-value (String-String) collection of storage headers/properties with their respective values. */ @Experimental - default Map getObjectStorageProperties(String contentUrl) + default Map getStorageProperties(String contentUrl) { return Collections.emptyMap(); } diff --git a/repository/src/main/java/org/alfresco/repo/content/AbstractRoutingContentStore.java b/repository/src/main/java/org/alfresco/repo/content/AbstractRoutingContentStore.java index 942f8e4d52..24b0e722ba 100644 --- a/repository/src/main/java/org/alfresco/repo/content/AbstractRoutingContentStore.java +++ b/repository/src/main/java/org/alfresco/repo/content/AbstractRoutingContentStore.java @@ -422,21 +422,21 @@ public abstract class AbstractRoutingContentStore implements ContentStore @Override @Experimental - public Map getObjectStorageProperties(String contentUrl) { + public Map getStorageProperties(String contentUrl) { ContentStore contentStore = selectReadStore(contentUrl); if (contentStore == null) { - if (logger.isDebugEnabled()) { - logger.debug("Storage properties not found for content URL: " + contentUrl); + if (logger.isTraceEnabled()) { + logger.trace("Storage properties not found for content URL: " + contentUrl); } return Collections.emptyMap(); } - - if (logger.isDebugEnabled()) { - logger.debug("Getting storage properties from store: \n" + + if (logger.isTraceEnabled()) { + logger.trace("Getting storage properties from store: \n" + " Content URL: " + contentUrl + "\n" + " Store: " + contentStore); } - return contentStore.getObjectStorageProperties(contentUrl); + + return contentStore.getStorageProperties(contentUrl); } } diff --git a/repository/src/main/java/org/alfresco/repo/content/ContentServiceImpl.java b/repository/src/main/java/org/alfresco/repo/content/ContentServiceImpl.java index 97fd92350f..f535a97a48 100644 --- a/repository/src/main/java/org/alfresco/repo/content/ContentServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/content/ContentServiceImpl.java @@ -664,7 +664,7 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " and property name: " + propertyQName + " has no content."); } - return store.getObjectStorageProperties(contentData.getContentUrl()); + return store.getStorageProperties(contentData.getContentUrl()); } protected String getFileName(NodeRef nodeRef) diff --git a/repository/src/main/java/org/alfresco/repo/content/caching/CachingContentStore.java b/repository/src/main/java/org/alfresco/repo/content/caching/CachingContentStore.java index 8901041663..b1329574e4 100644 --- a/repository/src/main/java/org/alfresco/repo/content/caching/CachingContentStore.java +++ b/repository/src/main/java/org/alfresco/repo/content/caching/CachingContentStore.java @@ -384,9 +384,9 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis @Override @Experimental - public Map getObjectStorageProperties(final String contentUrl) + public Map getStorageProperties(final String contentUrl) { - return backingStore.getObjectStorageProperties(contentUrl); + return backingStore.getStorageProperties(contentUrl); } /** diff --git a/repository/src/main/java/org/alfresco/repo/content/replication/AggregatingContentStore.java b/repository/src/main/java/org/alfresco/repo/content/replication/AggregatingContentStore.java index 0c48588391..4c98583b3c 100644 --- a/repository/src/main/java/org/alfresco/repo/content/replication/AggregatingContentStore.java +++ b/repository/src/main/java/org/alfresco/repo/content/replication/AggregatingContentStore.java @@ -407,7 +407,7 @@ public class AggregatingContentStore extends AbstractContentStore @Override @Experimental - public Map getObjectStorageProperties(String contentUrl) + public Map getStorageProperties(String contentUrl) { if (primaryStore == null) { throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED); @@ -419,7 +419,7 @@ public class AggregatingContentStore extends AbstractContentStore Optional> objectStoragePropertiesMap = Optional.empty(); // Check the primary store try { - objectStoragePropertiesMap = Optional.of(primaryStore.getObjectStorageProperties(contentUrl)); + objectStoragePropertiesMap = Optional.of(primaryStore.getStorageProperties(contentUrl)); } catch (UnsupportedContentUrlException e) { if (logger.isTraceEnabled()) { logger.trace("Primary store could not handle content URL: " + contentUrl); @@ -429,7 +429,7 @@ public class AggregatingContentStore extends AbstractContentStore if (objectStoragePropertiesMap.isEmpty()) {// the content is not in the primary store so we have to go looking for it for (ContentStore store : secondaryStores) { try { - objectStoragePropertiesMap = Optional.of(store.getObjectStorageProperties(contentUrl)); + objectStoragePropertiesMap = Optional.of(store.getStorageProperties(contentUrl)); } catch (UnsupportedContentUrlException e) { if (logger.isTraceEnabled()) { logger.trace("Secondary store " + store + " could not handle content URL: " + contentUrl); diff --git a/repository/src/main/java/org/alfresco/repo/tenant/AbstractTenantRoutingContentStore.java b/repository/src/main/java/org/alfresco/repo/tenant/AbstractTenantRoutingContentStore.java index 02c61a1563..a2d2a70718 100644 --- a/repository/src/main/java/org/alfresco/repo/tenant/AbstractTenantRoutingContentStore.java +++ b/repository/src/main/java/org/alfresco/repo/tenant/AbstractTenantRoutingContentStore.java @@ -1,51 +1,52 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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 Repository + * %% + * Copyright (C) 2005 - 2021 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.repo.tenant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; -import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; - -import org.alfresco.repo.content.AbstractRoutingContentStore; -import org.alfresco.repo.content.ContentContext; -import org.alfresco.repo.content.ContentStore; -import org.alfresco.repo.domain.tenant.TenantAdminDAO; -import org.alfresco.repo.domain.tenant.TenantEntity; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.transaction.TransactionService; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; + +import org.alfresco.repo.content.AbstractRoutingContentStore; +import org.alfresco.repo.content.ContentContext; +import org.alfresco.repo.content.ContentStore; +import org.alfresco.repo.domain.tenant.TenantAdminDAO; +import org.alfresco.repo.domain.tenant.TenantEntity; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.Experimental; +import org.alfresco.service.transaction.TransactionService; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; /** * Content Store that supports tenant routing, if multi-tenancy is enabled. @@ -270,6 +271,13 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC return -1; } } - + + @Experimental + @Override + public Map getStorageProperties(String contentUrl) + { + return getTenantContentStore().getStorageProperties(contentUrl); + } + protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot); } diff --git a/repository/src/test/java/org/alfresco/repo/content/ContentServiceImplUnitTest.java b/repository/src/test/java/org/alfresco/repo/content/ContentServiceImplUnitTest.java index b5440bc5f1..212c27f92c 100644 --- a/repository/src/test/java/org/alfresco/repo/content/ContentServiceImplUnitTest.java +++ b/repository/src/test/java/org/alfresco/repo/content/ContentServiceImplUnitTest.java @@ -168,7 +168,7 @@ public class ContentServiceImplUnitTest public void shouldReturnStoragePropertiesWhenTheyExist() { final Map storageObjectPropsMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2); - when(mockContentStore.getObjectStorageProperties(SOME_CONTENT_URL)).thenReturn(storageObjectPropsMap); + when(mockContentStore.getStorageProperties(SOME_CONTENT_URL)).thenReturn(storageObjectPropsMap); final Map objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT); assertFalse(objectStorageProperties.isEmpty()); @@ -178,7 +178,7 @@ public class ContentServiceImplUnitTest @Test public void shouldReturnEmptyStoragePropertiesWhenTheyDontExist() { - when(mockContentStore.getObjectStorageProperties(SOME_CONTENT_URL)).thenReturn(Collections.emptyMap()); + when(mockContentStore.getStorageProperties(SOME_CONTENT_URL)).thenReturn(Collections.emptyMap()); final Map objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT); assertTrue(objectStorageProperties.isEmpty()); diff --git a/repository/src/test/java/org/alfresco/repo/content/caching/CachingContentStoreTest.java b/repository/src/test/java/org/alfresco/repo/content/caching/CachingContentStoreTest.java index 07037f4915..b61db5d123 100644 --- a/repository/src/test/java/org/alfresco/repo/content/caching/CachingContentStoreTest.java +++ b/repository/src/test/java/org/alfresco/repo/content/caching/CachingContentStoreTest.java @@ -528,8 +528,8 @@ public class CachingContentStoreTest { final Map propertiesMap = Map.of("x-amz-header1", "value1", "x-amz-header2", "value2"); final String contentUrl = "url"; - when(backingStore.getObjectStorageProperties(contentUrl)).thenReturn(propertiesMap); - final Map storageProperties = cachingStore.getObjectStorageProperties(contentUrl); + when(backingStore.getStorageProperties(contentUrl)).thenReturn(propertiesMap); + final Map storageProperties = cachingStore.getStorageProperties(contentUrl); assertFalse(storageProperties.isEmpty()); assertEquals(propertiesMap, storageProperties); } @@ -537,7 +537,7 @@ public class CachingContentStoreTest @Test public void shouldReturnEmptyStorageProperties() { - Map storageProperties = cachingStore.getObjectStorageProperties("url"); + Map storageProperties = cachingStore.getStorageProperties("url"); assertTrue(storageProperties.isEmpty()); } } diff --git a/repository/src/test/java/org/alfresco/repo/content/replication/AggregatingContentStoreTest.java b/repository/src/test/java/org/alfresco/repo/content/replication/AggregatingContentStoreTest.java index 77299026f2..3fdb1b3245 100644 --- a/repository/src/test/java/org/alfresco/repo/content/replication/AggregatingContentStoreTest.java +++ b/repository/src/test/java/org/alfresco/repo/content/replication/AggregatingContentStoreTest.java @@ -321,13 +321,13 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes { final String contentUrl = "url"; final Map primaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);; - when(primaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(primaryStorePropertiesMap); + when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(primaryStorePropertiesMap); - final Map storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); + final Map storageProperties = aggregatingStore.getStorageProperties(contentUrl); assertFalse(storageProperties.isEmpty()); assertEquals(primaryStorePropertiesMap, storageProperties); - verify(secondaryStoreMock, times(0)).getObjectStorageProperties(contentUrl); + verify(secondaryStoreMock, times(0)).getStorageProperties(contentUrl); } @Test @@ -335,29 +335,29 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes { final String contentUrl = "url"; final Map secondaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);; - when(primaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); - when(secondaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap); + when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); + when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap); - final Map storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); + final Map storageProperties = aggregatingStore.getStorageProperties(contentUrl); assertFalse(storageProperties.isEmpty()); assertEquals(secondaryStorePropertiesMap, storageProperties); - verify(secondaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); - verify(primaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); + verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl); + verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl); } @Test public void shouldReturnEmptyStorageProperties() { final String contentUrl = "url"; - when(primaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); - when(secondaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); + when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); + when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); - final Map storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); + final Map storageProperties = aggregatingStore.getStorageProperties(contentUrl); assertTrue(storageProperties.isEmpty()); - verify(secondaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); - verify(primaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); + verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl); + verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl); } }