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.
This commit is contained in:
mpichura
2021-10-27 13:35:11 +02:00
committed by GitHub
parent 3c928a4928
commit 2d4140ea64
9 changed files with 87 additions and 79 deletions

View File

@@ -340,7 +340,7 @@ public interface ContentStore
* @return Returns a key-value (String-String) collection of storage headers/properties with their respective values. * @return Returns a key-value (String-String) collection of storage headers/properties with their respective values.
*/ */
@Experimental @Experimental
default Map<String, String> getObjectStorageProperties(String contentUrl) default Map<String, String> getStorageProperties(String contentUrl)
{ {
return Collections.emptyMap(); return Collections.emptyMap();
} }

View File

@@ -422,21 +422,21 @@ public abstract class AbstractRoutingContentStore implements ContentStore
@Override @Override
@Experimental @Experimental
public Map<String, String> getObjectStorageProperties(String contentUrl) { public Map<String, String> getStorageProperties(String contentUrl) {
ContentStore contentStore = selectReadStore(contentUrl); ContentStore contentStore = selectReadStore(contentUrl);
if (contentStore == null) { if (contentStore == null) {
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Storage properties not found for content URL: " + contentUrl); logger.trace("Storage properties not found for content URL: " + contentUrl);
} }
return Collections.emptyMap(); return Collections.emptyMap();
} }
if (logger.isTraceEnabled()) {
if (logger.isDebugEnabled()) { logger.trace("Getting storage properties from store: \n" +
logger.debug("Getting storage properties from store: \n" +
" Content URL: " + contentUrl + "\n" + " Content URL: " + contentUrl + "\n" +
" Store: " + contentStore); " Store: " + contentStore);
} }
return contentStore.getObjectStorageProperties(contentUrl);
return contentStore.getStorageProperties(contentUrl);
} }
} }

View File

@@ -664,7 +664,7 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " and property name: " + propertyQName + " has no content."); 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) protected String getFileName(NodeRef nodeRef)

View File

@@ -384,9 +384,9 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
@Override @Override
@Experimental @Experimental
public Map<String, String> getObjectStorageProperties(final String contentUrl) public Map<String, String> getStorageProperties(final String contentUrl)
{ {
return backingStore.getObjectStorageProperties(contentUrl); return backingStore.getStorageProperties(contentUrl);
} }
/** /**

View File

@@ -407,7 +407,7 @@ public class AggregatingContentStore extends AbstractContentStore
@Override @Override
@Experimental @Experimental
public Map<String, String> getObjectStorageProperties(String contentUrl) public Map<String, String> getStorageProperties(String contentUrl)
{ {
if (primaryStore == null) { if (primaryStore == null) {
throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED); throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED);
@@ -419,7 +419,7 @@ public class AggregatingContentStore extends AbstractContentStore
Optional<Map<String, String>> objectStoragePropertiesMap = Optional.empty(); Optional<Map<String, String>> objectStoragePropertiesMap = Optional.empty();
// Check the primary store // Check the primary store
try { try {
objectStoragePropertiesMap = Optional.of(primaryStore.getObjectStorageProperties(contentUrl)); objectStoragePropertiesMap = Optional.of(primaryStore.getStorageProperties(contentUrl));
} catch (UnsupportedContentUrlException e) { } catch (UnsupportedContentUrlException e) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Primary store could not handle content URL: " + contentUrl); 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 if (objectStoragePropertiesMap.isEmpty()) {// the content is not in the primary store so we have to go looking for it
for (ContentStore store : secondaryStores) { for (ContentStore store : secondaryStores) {
try { try {
objectStoragePropertiesMap = Optional.of(store.getObjectStorageProperties(contentUrl)); objectStoragePropertiesMap = Optional.of(store.getStorageProperties(contentUrl));
} catch (UnsupportedContentUrlException e) { } catch (UnsupportedContentUrlException e) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Secondary store " + store + " could not handle content URL: " + contentUrl); logger.trace("Secondary store " + store + " could not handle content URL: " + contentUrl);

View File

@@ -1,51 +1,52 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2021 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.tenant; package org.alfresco.repo.tenant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.alfresco.repo.content.AbstractRoutingContentStore; import org.alfresco.repo.content.AbstractRoutingContentStore;
import org.alfresco.repo.content.ContentContext; import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.domain.tenant.TenantAdminDAO; import org.alfresco.repo.domain.tenant.TenantAdminDAO;
import org.alfresco.repo.domain.tenant.TenantEntity; import org.alfresco.repo.domain.tenant.TenantEntity;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.Experimental;
import org.springframework.beans.BeansException; import org.alfresco.service.transaction.TransactionService;
import org.springframework.context.ApplicationContext; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/** /**
* Content Store that supports tenant routing, if multi-tenancy is enabled. * Content Store that supports tenant routing, if multi-tenancy is enabled.
@@ -270,6 +271,13 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC
return -1; return -1;
} }
} }
@Experimental
@Override
public Map<String, String> getStorageProperties(String contentUrl)
{
return getTenantContentStore().getStorageProperties(contentUrl);
}
protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot); protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot);
} }

View File

@@ -168,7 +168,7 @@ public class ContentServiceImplUnitTest
public void shouldReturnStoragePropertiesWhenTheyExist() public void shouldReturnStoragePropertiesWhenTheyExist()
{ {
final Map<String, String> storageObjectPropsMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2); final Map<String, String> 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<String, String> objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT); final Map<String, String> objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT);
assertFalse(objectStorageProperties.isEmpty()); assertFalse(objectStorageProperties.isEmpty());
@@ -178,7 +178,7 @@ public class ContentServiceImplUnitTest
@Test @Test
public void shouldReturnEmptyStoragePropertiesWhenTheyDontExist() public void shouldReturnEmptyStoragePropertiesWhenTheyDontExist()
{ {
when(mockContentStore.getObjectStorageProperties(SOME_CONTENT_URL)).thenReturn(Collections.emptyMap()); when(mockContentStore.getStorageProperties(SOME_CONTENT_URL)).thenReturn(Collections.emptyMap());
final Map<String, String> objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT); final Map<String, String> objectStorageProperties = contentService.getStorageProperties(NODE_REF, ContentModel.PROP_CONTENT);
assertTrue(objectStorageProperties.isEmpty()); assertTrue(objectStorageProperties.isEmpty());

View File

@@ -528,8 +528,8 @@ public class CachingContentStoreTest
{ {
final Map<String, String> propertiesMap = Map.of("x-amz-header1", "value1", "x-amz-header2", "value2"); final Map<String, String> propertiesMap = Map.of("x-amz-header1", "value1", "x-amz-header2", "value2");
final String contentUrl = "url"; final String contentUrl = "url";
when(backingStore.getObjectStorageProperties(contentUrl)).thenReturn(propertiesMap); when(backingStore.getStorageProperties(contentUrl)).thenReturn(propertiesMap);
final Map<String, String> storageProperties = cachingStore.getObjectStorageProperties(contentUrl); final Map<String, String> storageProperties = cachingStore.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty()); assertFalse(storageProperties.isEmpty());
assertEquals(propertiesMap, storageProperties); assertEquals(propertiesMap, storageProperties);
} }
@@ -537,7 +537,7 @@ public class CachingContentStoreTest
@Test @Test
public void shouldReturnEmptyStorageProperties() public void shouldReturnEmptyStorageProperties()
{ {
Map<String, String> storageProperties = cachingStore.getObjectStorageProperties("url"); Map<String, String> storageProperties = cachingStore.getStorageProperties("url");
assertTrue(storageProperties.isEmpty()); assertTrue(storageProperties.isEmpty());
} }
} }

View File

@@ -321,13 +321,13 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
{ {
final String contentUrl = "url"; final String contentUrl = "url";
final Map<String, String> primaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);; final Map<String, String> 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<String, String> storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty()); assertFalse(storageProperties.isEmpty());
assertEquals(primaryStorePropertiesMap, storageProperties); assertEquals(primaryStorePropertiesMap, storageProperties);
verify(secondaryStoreMock, times(0)).getObjectStorageProperties(contentUrl); verify(secondaryStoreMock, times(0)).getStorageProperties(contentUrl);
} }
@Test @Test
@@ -335,29 +335,29 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
{ {
final String contentUrl = "url"; final String contentUrl = "url";
final Map<String, String> secondaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);; final Map<String, String> secondaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);;
when(primaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap); when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap);
final Map<String, String> storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty()); assertFalse(storageProperties.isEmpty());
assertEquals(secondaryStorePropertiesMap, storageProperties); assertEquals(secondaryStorePropertiesMap, storageProperties);
verify(secondaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl);
verify(primaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl);
} }
@Test @Test
public void shouldReturnEmptyStorageProperties() public void shouldReturnEmptyStorageProperties()
{ {
final String contentUrl = "url"; final String contentUrl = "url";
when(primaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStoreMock.getObjectStorageProperties(contentUrl)).thenReturn(Collections.emptyMap()); when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
final Map<String, String> storageProperties = aggregatingStore.getObjectStorageProperties(contentUrl); final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertTrue(storageProperties.isEmpty()); assertTrue(storageProperties.isEmpty());
verify(secondaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl);
verify(primaryStoreMock, times(1)).getObjectStorageProperties(contentUrl); verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl);
} }
} }