mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
Compare commits
94 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8e3144a2d1 | ||
|
c0585df456 | ||
|
483b894cb2 | ||
|
e477721406 | ||
|
1717c909dd | ||
|
6cf6499239 | ||
|
572cb4eb9e | ||
|
9f96809413 | ||
|
91aec46bce | ||
|
870a9ee4fd | ||
|
cf14112626 | ||
|
1c915e4fb0 | ||
|
dab6f70936 | ||
|
4a7ea71f4e | ||
|
22f7f1898f | ||
|
514ebb4828 | ||
|
e4f39a5d63 | ||
|
5578cec604 | ||
|
57dbd4d12f | ||
|
0b840643f9 | ||
|
653ed68bd9 | ||
|
634602662c | ||
|
aeed1e00cb | ||
|
0844539c68 | ||
|
aff5ed3953 | ||
|
374de2c026 | ||
|
676ad11681 | ||
|
3a74246523 | ||
|
8aae69b847 | ||
|
402d8dff00 | ||
|
7e5b3973e9 | ||
|
33f93a2ad2 | ||
|
f9ab8425a5 | ||
|
0ecba230b7 | ||
|
9f44b21f07 | ||
|
f217e4e963 | ||
|
99be37185a | ||
|
06b994125a | ||
|
62fa02b1ac | ||
|
23b99ac6a2 | ||
|
9700668e2f | ||
|
46d1e73054 | ||
|
afd63d0794 | ||
|
f47dc25be6 | ||
|
cb46d0e2fa | ||
|
387bf6847f | ||
|
b5f6d04ecb | ||
|
5c40ca5e8a | ||
|
d9fc5efb75 | ||
|
e1d91fb84f | ||
|
057c93378a | ||
|
ae57159820 | ||
|
d58e514bab | ||
|
2d075e5af4 | ||
|
38b50992c2 | ||
|
9425f0b200 | ||
|
4b53c25218 | ||
|
a3bac54d38 | ||
|
cd18d3ca8f | ||
|
d00891d6ab | ||
|
089c359db2 | ||
|
a0ffffaff2 | ||
|
d4bffaf217 | ||
|
9098181574 | ||
|
4024787e29 | ||
|
43530de673 | ||
|
a2b3e9a47f | ||
|
f0def0fb5b | ||
|
8aa74de959 | ||
|
bdb223f472 | ||
|
91f71cca1f | ||
|
7532bed994 | ||
|
a8f56aa447 | ||
|
cc41f674b4 | ||
|
4e6c3ed818 | ||
|
bae9fe08c2 | ||
|
99694f72de | ||
|
f207006e93 | ||
|
ff27b13e41 | ||
|
6a25322fd4 | ||
|
d4e76d9f0f | ||
|
68a0441772 | ||
|
3cb43ab429 | ||
|
a8abf4b842 | ||
|
2dd7d3e5d1 | ||
|
0833da358e | ||
|
a822f2010a | ||
|
219296f8ea | ||
|
379e12e2c7 | ||
|
c724ed464c | ||
|
e4f9cc1a1b | ||
|
c88c58fb88 | ||
|
5257865d8e | ||
|
269f2f82f2 |
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-parent</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-amps</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class ContentContext implements Serializable
|
||||
|
||||
private ContentReader existingContentReader;
|
||||
private String contentUrl;
|
||||
private Set<String> storageClasses;
|
||||
|
||||
/**
|
||||
* Construct the instance with the content URL.
|
||||
@@ -61,7 +63,20 @@ public class ContentContext implements Serializable
|
||||
this.existingContentReader = existingContentReader;
|
||||
this.contentUrl = contentUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the instance with the content URL.
|
||||
*
|
||||
* @param existingContentReader content with which to seed the new writer - may be <tt>null</tt>
|
||||
* @param contentUrl the content URL - may be <tt>null</tt>
|
||||
* @param storageClasses the storage classes specific to the provided content URL - may be <tt>null</tt>
|
||||
*/
|
||||
public ContentContext(ContentReader existingContentReader, String contentUrl, Set<String> storageClasses)
|
||||
{
|
||||
this(existingContentReader, contentUrl);
|
||||
this.storageClasses = storageClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -88,5 +103,22 @@ public class ContentContext implements Serializable
|
||||
{
|
||||
return contentUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the storage classes for the content- may be <tt>null</tt>
|
||||
*/
|
||||
public Set<String> getStorageClasses()
|
||||
{
|
||||
return storageClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the storage classes for the content- may be <tt>null</tt>
|
||||
*
|
||||
* @param storageClasses
|
||||
*/
|
||||
public void setStorageClasses(Set<String> storageClasses)
|
||||
{
|
||||
this.storageClasses = storageClasses;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,11 @@
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.alfresco.service.cmr.repository.ContentAccessor;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
@@ -33,8 +38,6 @@ import org.alfresco.service.cmr.repository.ContentStreamListener;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.DirectAccessUrl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Provides low-level retrieval of content
|
||||
* {@link org.alfresco.service.cmr.repository.ContentReader readers} and
|
||||
@@ -88,7 +91,23 @@ public interface ContentStore
|
||||
* The delimiter that must be found in all URLS, i.e <b>://</b>
|
||||
*/
|
||||
public static final String PROTOCOL_DELIMITER = "://";
|
||||
|
||||
|
||||
public static final String STORAGE_CLASS_DEFAULT = "default";
|
||||
public static final String STORAGE_CLASS_ARCHIVE = "archive";
|
||||
public static final String STORAGE_CLASS_WORM = "worm";
|
||||
|
||||
/**
|
||||
* The 'default' storage class
|
||||
*
|
||||
* A content is considered to have a default storage class if:
|
||||
* the value is a Set.of("default")
|
||||
* the value is an empty set
|
||||
* the value is null
|
||||
*/
|
||||
public static final StorageClassSet SCS_DEFAULT = new StorageClassSet(STORAGE_CLASS_DEFAULT);
|
||||
public static final StorageClassSet SCS_ARCHIVE = new StorageClassSet(STORAGE_CLASS_ARCHIVE);
|
||||
public static final StorageClassSet SCS_WORM = new StorageClassSet(STORAGE_CLASS_WORM);
|
||||
|
||||
/**
|
||||
* Check if the content URL format is supported by the store.
|
||||
*
|
||||
@@ -263,4 +282,65 @@ public interface ContentStore
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the current {@link ContentStore} supports the provided {@link Set} storage classes
|
||||
*
|
||||
* @param storageClassSet The storage classes that will be checked whether or not are supported
|
||||
* @return true if the storage classes are supported, false otherwise.
|
||||
*/
|
||||
default boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
return storageClassSet == null ||
|
||||
storageClassSet.isEmpty() ||
|
||||
(1 == storageClassSet.size() && storageClassSet.equals(SCS_DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the complete {@link Set} of supported storage classes by this {@link ContentStore}
|
||||
*/
|
||||
default Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return Set.of(ContentStore.STORAGE_CLASS_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the storage class for content
|
||||
*
|
||||
* @param contentUrl The URL of the content that will have its storage classes updated
|
||||
* @param storageClassSet The new storage class
|
||||
* @param parameters extra parameters
|
||||
*/
|
||||
default void updateStorageClasses(String contentUrl, StorageClassSet storageClassSet, Map<String, Object> parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentUrl the URL of the content for which the storage classes are to be requested
|
||||
* @return Returns the current storage classes for the content found at the contentUrl
|
||||
*/
|
||||
default StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
return SCS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the complete collection of allowed storage classes transitions.
|
||||
* The key represents the source storage classes while the value (as a {@link Set}) represents all the possible target storage classes.
|
||||
*/
|
||||
default Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentUrl the URL of the content for which the storage classes transitions are to be requested
|
||||
* @return Returns the complete collection of allowed storage classes transitions for the content found at content URL
|
||||
*/
|
||||
default Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(String contentUrl)
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Data model classes
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Represents the state of the content and it is internally represented as a set.
|
||||
* It can have none, one, or multiple storage classes to specify the state
|
||||
* e.g. [default], [archive], [archive, encrypted]
|
||||
*
|
||||
* @author Lucian Tuca
|
||||
*/
|
||||
public class StorageClassSet extends HashSet<String>
|
||||
{
|
||||
public StorageClassSet()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public StorageClassSet(String... storageClasses)
|
||||
{
|
||||
super();
|
||||
Collections.addAll(this, storageClasses);
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Data model classes
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
|
||||
/**
|
||||
* Thrown when an operation regarding the storage classes of the content failed to execute.
|
||||
*
|
||||
* @author Lucian Tuca
|
||||
*/
|
||||
public class UnsupportedStorageClassException extends AlfrescoRuntimeException
|
||||
{
|
||||
private final ContentStore contentStore;
|
||||
private final Set<String> storageClasses;
|
||||
|
||||
public UnsupportedStorageClassException(ContentStore contentStore, Set<String> storageClasses, String msg)
|
||||
{
|
||||
super(msg);
|
||||
this.contentStore = contentStore;
|
||||
this.storageClasses = storageClasses;
|
||||
}
|
||||
|
||||
public ContentStore getContentStore()
|
||||
{
|
||||
return contentStore;
|
||||
}
|
||||
|
||||
public Set<String> getStorageClasses()
|
||||
{
|
||||
return storageClasses;
|
||||
}
|
||||
}
|
@@ -9,6 +9,6 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
</project>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package org.alfresco.rest.nodes;
|
||||
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObject;
|
||||
@@ -18,12 +21,16 @@ import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.data.DataUser;
|
||||
import org.alfresco.utility.model.ContentModel;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.alfresco.utility.report.Bug;
|
||||
import org.alfresco.utility.testrail.ExecutionType;
|
||||
import org.alfresco.utility.testrail.annotation.TestRail;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
@@ -33,6 +40,20 @@ import io.restassured.RestAssured;
|
||||
*/
|
||||
public class NodesTests extends RestTest
|
||||
{
|
||||
private UserModel user1;
|
||||
private SiteModel site1;
|
||||
private FolderModel folder1;
|
||||
private FileModel file1;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void dataPreparation() throws Exception
|
||||
{
|
||||
user1 = dataUser.createRandomTestUser();
|
||||
site1 = dataSite.usingUser(user1).createPublicRandomSite();
|
||||
folder1 = dataContent.usingUser(user1).usingSite(site1).createFolder();
|
||||
file1 = dataContent.usingUser(user1).usingResource(folder1).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify files can be moved from one folder to another")
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
|
||||
@@ -126,4 +147,61 @@ public class NodesTests extends RestTest
|
||||
logger.info("CMIS API call response status code is: " + cmisApiStatusCode);
|
||||
assertEquals(HttpStatus.FORBIDDEN.value(), cmisApiStatusCode);
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.SANITY }, executionType = ExecutionType.SANITY,
|
||||
description = "Check that the default node storage classes are retrieved - GET /nodes/{nodeId}.")
|
||||
@Test(groups = { TestGroup.SANITY })
|
||||
public void getNodeStorageClass() throws Exception
|
||||
{
|
||||
STEP("1. Get storage classes for a node with content.");
|
||||
RestNodeModel restResponse = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("include=storageClasses").getNode();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
assertTrue(restResponse.getContent().getStorageClasses().contains("default"));
|
||||
|
||||
STEP("2. Check that storage classes for a node with content are not displayed by default.");
|
||||
restResponse = restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).getNode();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
assertNull(restResponse.getContent().getStorageClasses());
|
||||
|
||||
STEP("3. Check that the request for storage classes on a node without content (e.g folder) is gracefully ignored.");
|
||||
restClient.authenticateUser(user1).withCoreAPI().usingNode(folder1).usingParams("include=storageClasses").getNode();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
assertNull(restResponse.getContent().getStorageClasses());
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.SANITY }, executionType = ExecutionType.SANITY,
|
||||
description = "Check that the storage classes default behavior of PUT /nodes/{nodeId}.")
|
||||
@Test(groups = { TestGroup.SANITY })
|
||||
public void updateNodeStorageClass() throws Exception
|
||||
{
|
||||
STEP("1. Update storage classes for a node with existing storage class.");
|
||||
JsonObject updateStorageClass = Json.createObjectBuilder().add("content",
|
||||
Json.createObjectBuilder().add("storageClasses", Json.createArrayBuilder().add("default")))
|
||||
.build();
|
||||
RestNodeModel restResponse = restClient.authenticateUser(user1).withCoreAPI()
|
||||
.usingNode(file1).usingParams("include=storageClasses").updateNode(updateStorageClass.toString());
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
assertTrue(restResponse.getContent().getStorageClasses().contains("default"));
|
||||
|
||||
STEP("2. Update storage classes for a node and check that storageClass is not displayed by default.");
|
||||
// Use existing update body
|
||||
restResponse = restClient.authenticateUser(user1).withCoreAPI()
|
||||
.usingNode(file1).updateNode(updateStorageClass.toString());
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
assertNull(restResponse.getContent().getStorageClasses());
|
||||
}
|
||||
|
||||
@TestRail(section = { TestGroup.SANITY }, executionType = ExecutionType.SANITY,
|
||||
description = "Verify that the BAD_REQUEST is returned when updating storage classes for a node with an invalid storage class")
|
||||
@Test(groups = { TestGroup.SANITY })
|
||||
public void updateNodeStorageClassWithInvalidStorageClassShouldReturn400() throws Exception
|
||||
{
|
||||
STEP("1. Update storage classes for a node with an invalid storage class.");
|
||||
JsonObject updateStorageClass = Json.createObjectBuilder().add("content",
|
||||
Json.createObjectBuilder().add("storageClasses", Json.createArrayBuilder().add("storageClassThatDoesntExist")))
|
||||
.build();
|
||||
RestNodeModel restResponse = restClient.authenticateUser(user1).withCoreAPI()
|
||||
.usingNode(file1).usingParams("include=storageClasses").updateNode(updateStorageClass.toString());
|
||||
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-tests</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<developers>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo-packaging</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
|
6
pom.xml
6
pom.xml
@@ -2,7 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Alfresco Community Repo Parent</name>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<properties>
|
||||
<acs.version.major>7</acs.version.major>
|
||||
<acs.version.minor>1</acs.version.minor>
|
||||
<acs.version.minor>2</acs.version.minor>
|
||||
<acs.version.revision>0</acs.version.revision>
|
||||
<acs.version.label />
|
||||
<amp.min.version>${acs.version.major}.0.0</amp.min.version>
|
||||
@@ -142,7 +142,7 @@
|
||||
<connection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Alfresco/alfresco-community-repo.git</developerConnection>
|
||||
<url>https://github.com/Alfresco/alfresco-community-repo</url>
|
||||
<tag>HEAD</tag>
|
||||
<tag>14.1</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
|
||||
/**
|
||||
* Storage Classes API
|
||||
*/
|
||||
public interface ContentStorageClasses
|
||||
{
|
||||
/**
|
||||
* Lists supported storage classes
|
||||
*/
|
||||
CollectionWithPagingInfo<StorageClass> getStorageClasses(Paging paging);
|
||||
}
|
@@ -375,6 +375,7 @@ public interface Nodes
|
||||
|
||||
String PARAM_INCLUDE_ASSOCIATION = "association";
|
||||
String PARAM_INCLUDE_DEFINITION = "definition";
|
||||
String PARAM_INCLUDE_STORAGECLASSES = "storageClasses";
|
||||
|
||||
String PARAM_ISFOLDER = "isFolder";
|
||||
String PARAM_ISFILE = "isFile";
|
||||
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.rest.api.ContentStorageClasses;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
|
||||
/**
|
||||
* Centralises access to storage classes functionality
|
||||
*/
|
||||
public class ContentStorageClassesImpl implements ContentStorageClasses
|
||||
{
|
||||
private ContentService contentService;
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<StorageClass> getStorageClasses(Paging paging)
|
||||
{
|
||||
Set<String> storageClasses = contentService.getSupportedStorageClasses();
|
||||
return CollectionWithPagingInfo.asPaged(paging, storageClasses.stream().map(StorageClass::new).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
@@ -56,6 +56,8 @@ import org.alfresco.repo.action.executer.ContentMetadataExtracter;
|
||||
import org.alfresco.repo.activities.ActivityType;
|
||||
import org.alfresco.repo.content.ContentLimitViolationException;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.content.UnsupportedStorageClassException;
|
||||
import org.alfresco.repo.domain.node.AuditablePropertiesEntity;
|
||||
import org.alfresco.repo.lock.mem.Lifetime;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
@@ -105,6 +107,7 @@ import org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeExceptio
|
||||
import org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.ContentInfoImpl;
|
||||
import org.alfresco.rest.framework.resource.content.NodeBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
@@ -1048,6 +1051,12 @@ public class NodesImpl implements Nodes
|
||||
node.setNodeType(nodeTypeQName.toPrefixString(namespaceService));
|
||||
node.setPath(pathInfo);
|
||||
|
||||
if (includeParam.contains(PARAM_INCLUDE_STORAGECLASSES) && node.getIsFile()
|
||||
&& node.getContent().getSizeInBytes() > 0)
|
||||
{
|
||||
node.getContent().setStorageClasses(contentService.findStorageClasses(nodeRef));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -1877,7 +1886,8 @@ public class NodesImpl implements Nodes
|
||||
if (isContent)
|
||||
{
|
||||
// create empty file node - note: currently will be set to default encoding only (UTF-8)
|
||||
nodeRef = createNewFile(parentNodeRef, nodeName, nodeTypeQName, null, props, assocTypeQName, parameters, versionMajor, versionComment);
|
||||
nodeRef = createNewFile(parentNodeRef, nodeName, nodeTypeQName, null, null, props,
|
||||
assocTypeQName, parameters, versionMajor, versionComment);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2362,7 +2372,16 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
processNodePermissions(nodeRef, nodeInfo);
|
||||
|
||||
|
||||
if (nodeInfo.getContent() != null && nodeInfo.getContent().getStorageClasses() != null)
|
||||
{
|
||||
try {
|
||||
contentService.updateStorageClasses(nodeRef, nodeInfo.getContent().getStorageClasses(), null);
|
||||
} catch (UnsupportedStorageClassException usce) {
|
||||
throw new IllegalArgumentException(usce.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
@@ -2767,7 +2786,13 @@ public class NodesImpl implements Nodes
|
||||
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
|
||||
try
|
||||
{
|
||||
writeContent(nodeRef, fileName, stream, true);
|
||||
writeContent(nodeRef,
|
||||
fileName,
|
||||
stream,
|
||||
true,
|
||||
contentInfo instanceof ContentInfo ?
|
||||
((ContentInfo) contentInfo).getStorageClasses() :
|
||||
null);
|
||||
|
||||
if ((isVersioned) || (versionMajor != null) || (versionComment != null) )
|
||||
{
|
||||
@@ -2806,10 +2831,17 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
private void writeContent(NodeRef nodeRef, String fileName, InputStream stream, boolean guessEncoding)
|
||||
{
|
||||
writeContent(nodeRef, fileName, stream, guessEncoding, null);
|
||||
}
|
||||
|
||||
private void writeContent(NodeRef nodeRef, String fileName, InputStream stream,
|
||||
boolean guessEncoding, StorageClassSet storageClassSet)
|
||||
{
|
||||
try
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
ContentWriter writer = contentService
|
||||
.getWriter(nodeRef, ContentModel.PROP_CONTENT, true, storageClassSet);
|
||||
|
||||
String mimeType = mimetypeService.guessMimetype(fileName);
|
||||
if ((mimeType != null) && (!mimeType.equals(MimetypeMap.MIMETYPE_BINARY)))
|
||||
@@ -2936,6 +2968,7 @@ public class NodesImpl implements Nodes
|
||||
String relativePath = null;
|
||||
String renditionNames = null;
|
||||
boolean versioningEnabled = true;
|
||||
String storageClassesParam = null;
|
||||
|
||||
Map<String, Object> qnameStrProps = new HashMap<>();
|
||||
Map<QName, Serializable> properties = null;
|
||||
@@ -2973,6 +3006,10 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
break;
|
||||
|
||||
case "storageclasses":
|
||||
storageClassesParam = getStringOrNull(field.getValue());
|
||||
break;
|
||||
|
||||
case "overwrite":
|
||||
overwrite = Boolean.valueOf(field.getValue());
|
||||
break;
|
||||
@@ -3041,8 +3078,9 @@ public class NodesImpl implements Nodes
|
||||
parentNodeRef = getOrCreatePath(parentNodeRef, relativePath);
|
||||
final QName assocTypeQName = ContentModel.ASSOC_CONTAINS;
|
||||
final Set<String> renditions = getRequestedRenditions(renditionNames);
|
||||
final StorageClassSet storageClasses = getRequestedStorageClasses(storageClassesParam);
|
||||
|
||||
validateProperties(qnameStrProps, EXCLUDED_NS, Arrays.asList());
|
||||
validateProperties(qnameStrProps, EXCLUDED_NS, Collections.emptyList());
|
||||
try
|
||||
{
|
||||
// Map the given properties, if any.
|
||||
@@ -3068,8 +3106,13 @@ public class NodesImpl implements Nodes
|
||||
else if (overwrite && nodeService.hasAspect(existingFile, ContentModel.ASPECT_VERSIONABLE))
|
||||
{
|
||||
// overwrite existing (versionable) file
|
||||
BasicContentInfo contentInfo = new ContentInfoImpl(content.getMimetype(), content.getEncoding(), -1, null);
|
||||
return updateExistingFile(parentNodeRef, existingFile, fileName, contentInfo, content.getInputStream(), parameters, versionMajor, versionComment);
|
||||
|
||||
BasicContentInfo contentInfo = new ContentInfoImpl(content.getMimetype(),
|
||||
content.getEncoding(), -1,
|
||||
null, storageClasses);
|
||||
return updateExistingFile(parentNodeRef, existingFile, fileName, contentInfo,
|
||||
content.getInputStream(), parameters, versionMajor,
|
||||
versionComment);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3087,7 +3130,9 @@ public class NodesImpl implements Nodes
|
||||
versionMajor = versioningEnabled ? versionMajor : null;
|
||||
|
||||
// Create a new file.
|
||||
NodeRef nodeRef = createNewFile(parentNodeRef, fileName, nodeTypeQName, content, properties, assocTypeQName, parameters, versionMajor, versionComment);
|
||||
NodeRef nodeRef = createNewFile(parentNodeRef, fileName, nodeTypeQName, content,
|
||||
storageClasses, properties, assocTypeQName, parameters,
|
||||
versionMajor, versionComment);
|
||||
|
||||
// Create the response
|
||||
final Node fileNode = getFolderOrDocumentFullInfo(nodeRef, parentNodeRef, nodeTypeQName, parameters);
|
||||
@@ -3104,6 +3149,10 @@ public class NodesImpl implements Nodes
|
||||
{
|
||||
throw new PermissionDeniedException(ade.getMessage());
|
||||
}
|
||||
catch (UnsupportedStorageClassException usce)
|
||||
{
|
||||
throw new InvalidArgumentException(usce.getMessage());
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: Do not clean formData temp files to allow for retries. It's
|
||||
@@ -3112,8 +3161,9 @@ public class NodesImpl implements Nodes
|
||||
*/
|
||||
}
|
||||
|
||||
private NodeRef createNewFile(NodeRef parentNodeRef, String fileName, QName nodeType, Content content, Map<QName, Serializable> props, QName assocTypeQName, Parameters params,
|
||||
Boolean versionMajor, String versionComment)
|
||||
private NodeRef createNewFile(NodeRef parentNodeRef, String fileName, QName nodeType,
|
||||
Content content, StorageClassSet storageClassSet, Map<QName, Serializable> props,
|
||||
QName assocTypeQName, Parameters params, Boolean versionMajor, String versionComment)
|
||||
{
|
||||
NodeRef nodeRef = createNodeImpl(parentNodeRef, fileName, nodeType, props, assocTypeQName);
|
||||
|
||||
@@ -3125,7 +3175,7 @@ public class NodesImpl implements Nodes
|
||||
else
|
||||
{
|
||||
// Write content
|
||||
writeContent(nodeRef, fileName, content.getInputStream(), true);
|
||||
writeContent(nodeRef, fileName, content.getInputStream(), true, storageClassSet);
|
||||
}
|
||||
|
||||
if ((versionMajor != null) || (versionComment != null))
|
||||
@@ -3203,6 +3253,21 @@ public class NodesImpl implements Nodes
|
||||
return renditions;
|
||||
}
|
||||
|
||||
static StorageClassSet getRequestedStorageClasses(String storageClassesParam)
|
||||
{
|
||||
if (storageClassesParam == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] storageClasses = Arrays.stream(storageClassesParam.split(","))
|
||||
.map(String::trim)
|
||||
.filter(sc -> !sc.isEmpty())
|
||||
.toArray(String[]::new);
|
||||
|
||||
return new StorageClassSet(storageClasses);
|
||||
}
|
||||
|
||||
private void requestRenditions(Set<String> renditionNames, Node fileNode)
|
||||
{
|
||||
if (renditionNames != null)
|
||||
|
@@ -25,6 +25,10 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
|
||||
/**
|
||||
* Representation of content info
|
||||
*
|
||||
@@ -37,6 +41,7 @@ public class ContentInfo
|
||||
private String mimeTypeName;
|
||||
private Long sizeInBytes;
|
||||
private String encoding;
|
||||
private StorageClassSet storageClassSet;
|
||||
|
||||
public ContentInfo()
|
||||
{
|
||||
@@ -50,6 +55,15 @@ public class ContentInfo
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public ContentInfo(String mimeType, String mimeTypeName, Long sizeInBytes, String encoding, StorageClassSet storageClassSet)
|
||||
{
|
||||
this.mimeType = mimeType;
|
||||
this.mimeTypeName = mimeTypeName;
|
||||
this.sizeInBytes = sizeInBytes;
|
||||
this.encoding = encoding;
|
||||
this.storageClassSet = storageClassSet;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
@@ -70,10 +84,21 @@ public class ContentInfo
|
||||
return encoding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet getStorageClasses()
|
||||
{
|
||||
return storageClassSet;
|
||||
}
|
||||
|
||||
public void setStorageClasses(StorageClassSet storageClassSet)
|
||||
{
|
||||
this.storageClassSet = storageClassSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ContentInfo [mimeType=" + mimeType + ", mimeTypeName=" + mimeTypeName
|
||||
+ ", encoding=" + encoding + ", sizeInBytes=" + sizeInBytes + "]";
|
||||
+ ", encoding=" + encoding + ", sizeInBytes=" + sizeInBytes + ", storageClasses=" + storageClassSet
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
/**
|
||||
* Represents a storage class.
|
||||
*/
|
||||
public class StorageClass
|
||||
{
|
||||
private String id;
|
||||
|
||||
public StorageClass(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public StorageClass()
|
||||
{
|
||||
}
|
||||
|
||||
public void setId(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.storageclasses;
|
||||
|
||||
import org.alfresco.rest.api.ContentStorageClasses;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
/**
|
||||
* An implementation of an Entity Resource for handling storage classes.
|
||||
*/
|
||||
@EntityResource(name = "storage-classes", title = "Storage Classes")
|
||||
public class StorageClassesEntityResource implements EntityResourceAction.Read<StorageClass>
|
||||
{
|
||||
private ContentStorageClasses contentStorageClasses;
|
||||
|
||||
public void setContentStorageClasses(ContentStorageClasses contentStorageClasses)
|
||||
{
|
||||
this.contentStorageClasses = contentStorageClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Get List of Storage Classes", description = "Get List of Storage Classes")
|
||||
public CollectionWithPagingInfo<StorageClass> readAll(Parameters params)
|
||||
{
|
||||
return contentStorageClasses.getStorageClasses(params.getPaging());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@WebApi(name="alfresco", scope= Api.SCOPE.PUBLIC, version=1)
|
||||
package org.alfresco.rest.api.storageclasses;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.WebApi;
|
@@ -25,12 +25,16 @@
|
||||
*/
|
||||
package org.alfresco.rest.framework.resource.content;
|
||||
|
||||
import static org.alfresco.repo.content.ContentStore.SCS_DEFAULT;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* A POJO property that is of type "Binary"
|
||||
*
|
||||
@@ -47,6 +51,7 @@ public class BinaryProperty implements ContentInfo, Serializable
|
||||
private final String encoding;
|
||||
private final long length;
|
||||
private final Locale locale;
|
||||
private final StorageClassSet storageClassSet;
|
||||
|
||||
/**
|
||||
* Sets the content length to zero, Locale to null, no stream and no caching
|
||||
@@ -55,11 +60,7 @@ public class BinaryProperty implements ContentInfo, Serializable
|
||||
*/
|
||||
public BinaryProperty(String mimeType, String encoding)
|
||||
{
|
||||
super();
|
||||
this.mimeType = mimeType;
|
||||
this.encoding = encoding;
|
||||
this.length = 0;
|
||||
this.locale = null;
|
||||
this(mimeType, encoding, 0, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +74,7 @@ public class BinaryProperty implements ContentInfo, Serializable
|
||||
this.encoding = reader.getEncoding();
|
||||
this.length = reader.getSize();
|
||||
this.locale = reader.getLocale();
|
||||
this.storageClassSet = SCS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,12 +85,18 @@ public class BinaryProperty implements ContentInfo, Serializable
|
||||
* @param locale Locale
|
||||
*/
|
||||
public BinaryProperty(String mimeType, String encoding, long length, Locale locale)
|
||||
{
|
||||
this(mimeType, encoding, length, locale, null);
|
||||
}
|
||||
|
||||
public BinaryProperty(String mimeType, String encoding, long length, Locale locale, StorageClassSet storageClassSet)
|
||||
{
|
||||
super();
|
||||
this.mimeType = mimeType;
|
||||
this.encoding = encoding;
|
||||
this.length = length;
|
||||
this.locale = locale;
|
||||
this.storageClassSet = storageClassSet;
|
||||
}
|
||||
|
||||
public String getMimeType()
|
||||
@@ -123,5 +131,10 @@ public class BinaryProperty implements ContentInfo, Serializable
|
||||
{
|
||||
return this.locale;
|
||||
}
|
||||
@JsonIgnore
|
||||
public StorageClassSet getStorageClasses()
|
||||
{
|
||||
return storageClassSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,14 +23,18 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.framework.resource.content;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Basic information about content. Typically used with HTTPServletResponse
|
||||
*/
|
||||
public interface ContentInfo extends BasicContentInfo{
|
||||
public long getLength();
|
||||
public Locale getLocale();
|
||||
}
|
||||
package org.alfresco.rest.framework.resource.content;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
|
||||
/**
|
||||
* Basic information about content. Typically used with HTTPServletResponse
|
||||
*/
|
||||
public interface ContentInfo extends BasicContentInfo{
|
||||
public long getLength();
|
||||
public Locale getLocale();
|
||||
public StorageClassSet getStorageClasses();
|
||||
}
|
||||
|
@@ -1,32 +1,34 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.framework.resource.content;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
|
||||
/**
|
||||
* Basic implementation of information about the returned content.
|
||||
*/
|
||||
@@ -36,16 +38,23 @@ public class ContentInfoImpl implements ContentInfo
|
||||
private final String encoding;
|
||||
private final long length;
|
||||
private final Locale locale;
|
||||
|
||||
private final StorageClassSet storageClassSet;
|
||||
|
||||
public ContentInfoImpl(String mimeType, String encoding, long length, Locale locale)
|
||||
{
|
||||
this(mimeType, encoding, length, locale, null);
|
||||
}
|
||||
|
||||
public ContentInfoImpl(String mimeType, String encoding, long length, Locale locale, StorageClassSet storageClassSet)
|
||||
{
|
||||
super();
|
||||
this.mimeType = mimeType;
|
||||
this.encoding = encoding;
|
||||
this.length = length;
|
||||
this.locale = locale;
|
||||
this.storageClassSet = storageClassSet;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMimeType()
|
||||
{
|
||||
@@ -66,4 +75,10 @@ public class ContentInfoImpl implements ContentInfo
|
||||
{
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet getStorageClasses()
|
||||
{
|
||||
return this.storageClassSet;
|
||||
}
|
||||
}
|
||||
|
@@ -798,6 +798,24 @@
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="contentStorageClasses" class="org.alfresco.rest.api.impl.ContentStorageClassesImpl">
|
||||
<property name="contentService" ref="ContentService" />
|
||||
</bean>
|
||||
|
||||
<bean id="ContentStorageClasses" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces">
|
||||
<value>org.alfresco.rest.api.ContentStorageClasses</value>
|
||||
</property>
|
||||
<property name="target">
|
||||
<ref bean="contentStorageClasses" />
|
||||
</property>
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
<idref bean="legacyExceptionInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tags" class="org.alfresco.rest.api.impl.TagsImpl">
|
||||
<property name="nodes" ref="nodes" />
|
||||
@@ -987,6 +1005,10 @@
|
||||
<property name="actions" ref="Actions"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.storageclasses.StorageClassesEntityResource">
|
||||
<property name="contentStorageClasses" ref="ContentStorageClasses" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.trashcan.TrashcanEntityResource">
|
||||
<property name="deletedNodes" ref="DeletedNodes" />
|
||||
</bean>
|
||||
|
@@ -55,6 +55,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.rest.api.tests.QueriesNodesApiTest.class,
|
||||
org.alfresco.rest.api.tests.QueriesPeopleApiTest.class,
|
||||
org.alfresco.rest.api.tests.QueriesSitesApiTest.class,
|
||||
org.alfresco.rest.api.tests.StorageClassesTest.class,
|
||||
org.alfresco.rest.api.tests.TestActivities.class,
|
||||
org.alfresco.rest.api.tests.TestDownloads.class,
|
||||
org.alfresco.rest.api.tests.TestFavouriteSites.class,
|
||||
|
@@ -78,7 +78,8 @@ import org.junit.runners.Suite;
|
||||
TestPublicApi128.class,
|
||||
TestPublicApiCaching.class,
|
||||
TestDownloads.class,
|
||||
AuditAppTest.class,
|
||||
AuditAppTest.class,
|
||||
StorageClassesTest.class,
|
||||
TempOutputStreamTest.class,
|
||||
BufferedResponseTest.class
|
||||
})
|
||||
|
@@ -55,6 +55,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
@@ -2799,6 +2800,80 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
post(postUrl, toJsonAsStringNonNull(d1), "?"+Nodes.PARAM_AUTO_RENAME+"=false", 409);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadFileWithStorageClasses() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
String title = "test title";
|
||||
Map<String,String> docProps = new HashMap<>();
|
||||
docProps.put("cm:title", title);
|
||||
docProps.put("cm:owner", user1);
|
||||
docProps.put("storageClasses", "unsupported-storage-classes");
|
||||
docProps.put("include", "storageClasses");
|
||||
String contentName = "content " + RUNID + ".txt";
|
||||
|
||||
// Upload text with unsupported storage classes
|
||||
createTextFile(Nodes.PATH_MY, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps, 400);
|
||||
|
||||
// Upload text content with "default" storage classes
|
||||
docProps.put("storageClasses", "default");
|
||||
Document document = createTextFile(Nodes.PATH_MY, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps);
|
||||
|
||||
assertTrue(Set.of("default").containsAll(document.getContent().getStorageClasses()));
|
||||
|
||||
// Upload new version with "default" storage classes
|
||||
docProps.put("overwrite", "true");
|
||||
createTextFile(Nodes.PATH_MY, contentName, "New content - The quick brown fox jumps over the lazy dog.", "UTF-8", docProps);
|
||||
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), getPaging(0, 100), Map.of("include", "storageClasses"), 200);
|
||||
List<Node> children = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
|
||||
assertEquals(1, children.size());
|
||||
assertTrue(Set.of("default").containsAll(children.get(0).getContent().getStorageClasses()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetChildrenWithNoStorageClasses() throws Exception
|
||||
{
|
||||
setRequestContext(networkOne.getId(), user1, null);
|
||||
|
||||
// Create folder
|
||||
createFolder(Nodes.PATH_MY, "testFolder");
|
||||
|
||||
Map params = new HashMap<>();
|
||||
params.put("storageClasses", "default");
|
||||
params.put("include", "storageClasses");
|
||||
|
||||
// Create empty file
|
||||
Document emptyTextFile = createEmptyTextFile(Nodes.PATH_MY, "empty-file.txt", params, 201);
|
||||
|
||||
assertNotNull(emptyTextFile.getContent());
|
||||
assertNull(
|
||||
emptyTextFile.getContent().getStorageClasses()); // no storage classes for empty files
|
||||
|
||||
// Create file with content - default storage classes
|
||||
Document fileWithContent = createTextFile(Nodes.PATH_MY, "file-with-content.txt",
|
||||
"The quick brown fox jumps over the lazy dog.",
|
||||
"UTF-8", params);
|
||||
|
||||
assertNotNull(fileWithContent.getContent());
|
||||
assertTrue(Set.of("default").containsAll(fileWithContent.getContent().getStorageClasses()));
|
||||
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(Nodes.PATH_MY), getPaging(0, 100),
|
||||
Map.of("include", "storageClasses"), 200);
|
||||
List<Node> children = RestApiUtil
|
||||
.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
|
||||
assertEquals(3, children.size());
|
||||
long childrenWithStorageClasses = children
|
||||
.stream()
|
||||
.filter(child -> child.getContent() != null &&
|
||||
child.getContent().getStorageClasses() != null)
|
||||
.count();
|
||||
assertEquals(1, childrenWithStorageClasses);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNodeConcurrentlyUsingInMemoryBacked() throws Exception
|
||||
{
|
||||
@@ -4778,6 +4853,36 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
assertTrue("Incorrect list of settable permissions returned!", documentResp.getPermissions().getSettable().containsAll(expectedSettable));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveNodeStorageClasses() throws Exception
|
||||
{
|
||||
setRequestContext(user1);
|
||||
|
||||
Document document = createTextFile(Nodes.PATH_MY, "file.txt",
|
||||
"The quick brown fox jumps over the lazy dog.");
|
||||
|
||||
Map params = new HashMap<>();
|
||||
params.put("include", "storageClasses");
|
||||
|
||||
// Update node
|
||||
Document dUpdate = new Document();
|
||||
HttpResponse response = put(URL_NODES, document.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
|
||||
// Check if storageClasses are retrieved if 'include=storageClasses' is not sent in the request
|
||||
response = getSingle(NodesEntityResource.class, documentResp.getId(), null, 200);
|
||||
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
assertNull("StorageClasses should not be retrieved unless included!", documentResp.getContent().getStorageClasses());
|
||||
|
||||
// Call again with 'include=storageClasses'
|
||||
response = getSingle(NodesEntityResource.class, documentResp.getId(), params, 200);
|
||||
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
|
||||
// Check that all storage classes are retrieved
|
||||
assertNotNull(documentResp.getContent().getStorageClasses());
|
||||
assertEquals(ContentStore.SCS_DEFAULT, documentResp.getContent().getStorageClasses());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests set permissions on a new node
|
||||
*
|
||||
|
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.alfresco.rest.api.tests.util.RestApiUtil.parseRestApiEntries;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.model.StorageClass;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* V1 REST API tests for Storage Classes
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/storage-classes} </li>
|
||||
* </ul>
|
||||
*/
|
||||
public class StorageClassesTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String STORAGE_CLASSES = "storage-classes";
|
||||
private ContentService contentService;
|
||||
private ContentStore originalStore;
|
||||
@Mock
|
||||
private ContentStore mockStore;
|
||||
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
contentService = applicationContext.getBean("contentService", ContentService.class);
|
||||
originalStore = (ContentStore) ReflectionTestUtils.getField(contentService, "store");
|
||||
|
||||
setRequestContext(user1);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
ReflectionTestUtils.setField(contentService, "store", originalStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultStorageClasses() throws Exception
|
||||
{
|
||||
PublicApiClient.Paging paging = getPaging(0, 100);
|
||||
|
||||
HttpResponse response = getAll(STORAGE_CLASSES, paging, 200);
|
||||
List<StorageClass> nodes = parseRestApiEntries(response.getJsonResponse(), StorageClass.class);
|
||||
|
||||
assertNotNull(nodes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorageClasses() throws Exception
|
||||
{
|
||||
ReflectionTestUtils.setField(contentService, "store", mockStore);
|
||||
|
||||
Set<String> expectedStorageClass =
|
||||
Set.of(ContentStore.STORAGE_CLASS_DEFAULT, ContentStore.STORAGE_CLASS_ARCHIVE);
|
||||
when(mockStore.getSupportedStorageClasses()).thenReturn(expectedStorageClass);
|
||||
|
||||
PublicApiClient.Paging paging = getPaging(0, 100);
|
||||
HttpResponse response = getAll(STORAGE_CLASSES, paging, 200);
|
||||
List<StorageClass> nodes = parseRestApiEntries(response.getJsonResponse(), StorageClass.class);
|
||||
|
||||
assertNotNull(nodes);
|
||||
assertEquals(2, nodes.size());
|
||||
}
|
||||
}
|
@@ -28,6 +28,10 @@ package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
|
||||
/**
|
||||
* Representation of content info (initially for client tests for File Folder API)
|
||||
*
|
||||
@@ -40,6 +44,7 @@ public class ContentInfo
|
||||
private String mimeTypeName;
|
||||
private Long sizeInBytes;
|
||||
private String encoding;
|
||||
private StorageClassSet storageClassSet;
|
||||
|
||||
public ContentInfo()
|
||||
{
|
||||
@@ -77,6 +82,16 @@ public class ContentInfo
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public StorageClassSet getStorageClasses()
|
||||
{
|
||||
return storageClassSet;
|
||||
}
|
||||
|
||||
public void setStorageClasses(StorageClassSet storageClassSet)
|
||||
{
|
||||
this.storageClassSet = storageClassSet;
|
||||
}
|
||||
|
||||
public void expected(Object o)
|
||||
{
|
||||
assertTrue(o instanceof ContentInfo);
|
||||
@@ -87,6 +102,7 @@ public class ContentInfo
|
||||
AssertUtil.assertEquals("mimeTypeName", mimeTypeName, other.getMimeTypeName());
|
||||
AssertUtil.assertEquals("sizeInBytes", sizeInBytes, other.getSizeInBytes());
|
||||
AssertUtil.assertEquals("encoding", encoding, other.getEncoding());
|
||||
AssertUtil.assertEquals("storageClasses", storageClassSet, other.storageClassSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,6 +113,7 @@ public class ContentInfo
|
||||
.append(", mimeTypeName=").append(mimeTypeName)
|
||||
.append(", sizeInBytes=").append(sizeInBytes)
|
||||
.append(", encoding=").append(encoding)
|
||||
.append(", storageClasses=").append(storageClassSet)
|
||||
.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-community-repo</artifactId>
|
||||
<version>11.94-SNAPSHOT</version>
|
||||
<version>14.1</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -1,44 +1,48 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* A store providing support for content store implementations that provide
|
||||
@@ -416,4 +420,163 @@ public abstract class AbstractRoutingContentStore implements ContentStore
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
boolean supported = false;
|
||||
for (ContentStore store : getAllStores())
|
||||
{
|
||||
if (store.isStorageClassesSupported(storageClassSet))
|
||||
{
|
||||
supported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("The storage classes " + storageClassSet + (supported ? "are" : "are not") + " supported by at least one store.");
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
Set<String> supportedStorageClassSets = new HashSet<>();
|
||||
for (ContentStore store : getAllStores())
|
||||
{
|
||||
supportedStorageClassSets.addAll(store.getSupportedStorageClasses());
|
||||
}
|
||||
return supportedStorageClassSets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(String contentUrl, StorageClassSet storageClassSet,
|
||||
Map<String, Object> parameters)
|
||||
{
|
||||
ContentStore store;
|
||||
Pair<String, String> cacheKey = new Pair<String, String>(instanceKey, contentUrl);
|
||||
// Get the read lock
|
||||
storesCacheReadLock.lock();
|
||||
try
|
||||
{
|
||||
// Check if the store is in the cache
|
||||
store = storesByContentUrl.get(cacheKey);
|
||||
}
|
||||
finally
|
||||
{
|
||||
storesCacheReadLock.unlock();
|
||||
}
|
||||
|
||||
if (store == null || !store.exists(contentUrl) || !store.isWriteSupported())
|
||||
{
|
||||
store = selectWriteStore(new ContentContext(getReader(contentUrl), contentUrl));
|
||||
// Check that we were given a valid store
|
||||
if (store == null)
|
||||
{
|
||||
throw new NullPointerException(
|
||||
"Unable to find a write store. 'selectWriteStore' may not return null: \n" +
|
||||
" Router: " + this + "\n" +
|
||||
" Chose: " + store);
|
||||
}
|
||||
else if (!store.isWriteSupported())
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"A write store was chosen that doesn't support writes: \n" +
|
||||
" Router: " + this + "\n" +
|
||||
" Chose: " + store);
|
||||
}
|
||||
}
|
||||
|
||||
if (!store.exists(contentUrl) || !store.isStorageClassesSupported(storageClassSet))
|
||||
{
|
||||
store = null;
|
||||
|
||||
for (ContentStore storeInList : getAllStores())
|
||||
{
|
||||
if (storeInList.isWriteSupported() &&
|
||||
storeInList.exists(contentUrl) &&
|
||||
storeInList.isStorageClassesSupported(storageClassSet))
|
||||
{
|
||||
store = storeInList;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (store == null)
|
||||
{
|
||||
throw new UnsupportedOperationException(
|
||||
"Unable to find a write store to update the storage classes for content URL: \n" +
|
||||
" Content URL: " + contentUrl + "\n" +
|
||||
" StorageClasses: " + storageClassSet);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Updating storage classes for content URL: \n" +
|
||||
" Content URL: " + contentUrl + "\n" +
|
||||
" Store: " + store);
|
||||
}
|
||||
store.updateStorageClasses(contentUrl, storageClassSet, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
ContentStore contentStore = selectReadStore(contentUrl);
|
||||
|
||||
if (contentStore == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Storage classes not found for content URL: " + contentUrl);
|
||||
}
|
||||
return new StorageClassSet();
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Getting storage classes from store: \n" +
|
||||
" Content URL: " + contentUrl + "\n" +
|
||||
" Store: " + contentStore);
|
||||
}
|
||||
return contentStore.findStorageClasses(contentUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
Map<StorageClassSet, Set<StorageClassSet>> supportedTransitions = new HashMap<>();
|
||||
for (ContentStore store : getAllStores())
|
||||
{
|
||||
supportedTransitions.putAll(store.getStorageClassesTransitions());
|
||||
}
|
||||
return supportedTransitions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(String contentUrl)
|
||||
{
|
||||
ContentStore contentStore = selectReadStore(contentUrl);
|
||||
|
||||
if (contentStore == null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Storage classes transitions not found for content URL: " + contentUrl);
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Getting storage classes transitions from store: \n" +
|
||||
" Content URL: " + contentUrl + "\n" +
|
||||
" Store: " + contentStore);
|
||||
}
|
||||
return contentStore.findStorageClassesTransitions(contentUrl);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,13 @@
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentServicePolicies.OnContentPropertyUpdatePolicy;
|
||||
@@ -62,13 +69,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service implementation acting as a level of indirection between the client
|
||||
* and the underlying content store.
|
||||
@@ -449,9 +449,21 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
|
||||
public ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update)
|
||||
{
|
||||
return getWriter(nodeRef,propertyQName, update, null);
|
||||
}
|
||||
|
||||
public ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update,
|
||||
StorageClassSet storageClassSet)
|
||||
{
|
||||
if (!isStorageClassesSupported(storageClassSet))
|
||||
{
|
||||
throw new UnsupportedStorageClassException(store, storageClassSet,
|
||||
"The supplied storage classes are not supported");
|
||||
}
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
ContentContext ctx = new ContentContext(null, null);
|
||||
ContentContext ctx = new ContentContext(null, null, storageClassSet);
|
||||
// for this case, we just give back a valid URL into the content store
|
||||
ContentWriter writer = store.getWriter(ctx);
|
||||
// Register the new URL for rollback cleanup
|
||||
@@ -462,10 +474,38 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
|
||||
// check for an existing URL - the get of the reader will perform type checking
|
||||
ContentReader existingContentReader = getReader(nodeRef, propertyQName, false);
|
||||
|
||||
if (storageClassSet != null)
|
||||
{
|
||||
if (existingContentReader != null &&
|
||||
existingContentReader.getContentData() != null &&
|
||||
existingContentReader.getContentData().getContentUrl() != null)
|
||||
{
|
||||
Set<String> currentStorageClasses = findStorageClasses(nodeRef);
|
||||
if (currentStorageClasses != null &&
|
||||
!currentStorageClasses.equals(storageClassSet))
|
||||
{
|
||||
Set<StorageClassSet> possibleTransitions = findStorageClassesTransitions(nodeRef)
|
||||
.get(currentStorageClasses);
|
||||
|
||||
if (possibleTransitions == null ||
|
||||
!possibleTransitions.contains(storageClassSet))
|
||||
{
|
||||
throw new UnsupportedStorageClassException(store, storageClassSet,
|
||||
"Transition from "
|
||||
+ currentStorageClasses
|
||||
+ " storage classes to "
|
||||
+ storageClassSet
|
||||
+ " is not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get the content using the (potentially) existing content - the new content
|
||||
// can be wherever the store decides.
|
||||
ContentContext ctx = new NodeContentContext(existingContentReader, null, nodeRef, propertyQName);
|
||||
ContentContext ctx = new NodeContentContext(existingContentReader, null, nodeRef,
|
||||
propertyQName, storageClassSet);
|
||||
ContentWriter writer = store.getWriter(ctx);
|
||||
// Register the new URL for rollback cleanup
|
||||
eagerContentStoreCleaner.registerNewContentUrl(writer.getContentUrl());
|
||||
@@ -586,4 +626,69 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
return store.isStorageClassesSupported(storageClassSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return store.getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(NodeRef nodeRef, StorageClassSet storageClassSet, Map<String, Object> parameters)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
if (!isStorageClassesSupported(storageClassSet))
|
||||
{
|
||||
throw new UnsupportedStorageClassException(store, storageClassSet, "The supplied storage classes are not supported");
|
||||
}
|
||||
|
||||
store.updateStorageClasses(contentData.getContentUrl(), storageClassSet, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet findStorageClasses(NodeRef nodeRef)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
return store.findStorageClasses(contentData.getContentUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
return store.getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(NodeRef nodeRef)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
return store.findStorageClassesTransitions(contentData.getContentUrl());
|
||||
}
|
||||
}
|
@@ -1,30 +1,32 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -63,6 +65,29 @@ public class NodeContentContext extends ContentContext
|
||||
this.propertyQName = propertyQName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the instance with the content URL.
|
||||
*
|
||||
* @param existingContentReader content with which to seed the new writer - may be <tt>null</tt>
|
||||
* @param contentUrl the content URL - may be <tt>null</tt>
|
||||
* @param nodeRef the node holding the content metadata - may not be <tt>null</tt>
|
||||
* @param propertyQName the property holding the content metadata - may not be <tt>null</tt>
|
||||
* @param storageClasses the storage classes specific to the provided content URL - may be <tt>null</tt>
|
||||
*/
|
||||
public NodeContentContext(
|
||||
ContentReader existingContentReader,
|
||||
String contentUrl,
|
||||
NodeRef nodeRef,
|
||||
QName propertyQName,
|
||||
Set<String> storageClasses)
|
||||
{
|
||||
super(existingContentReader, contentUrl, storageClasses);
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
ParameterCheck.mandatory("propertyQName", propertyQName);
|
||||
this.nodeRef = nodeRef;
|
||||
this.propertyQName = propertyQName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@@ -26,12 +26,15 @@
|
||||
package org.alfresco.repo.content.caching;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
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.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.content.caching.quota.QuotaManagerStrategy;
|
||||
import org.alfresco.repo.content.caching.quota.UnlimitedQuotaStrategy;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
@@ -487,4 +490,40 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
|
||||
{
|
||||
return backingStore.getDirectAccessUrl(contentUrl, expiresAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
return backingStore.isStorageClassesSupported(storageClassSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return backingStore.getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(String contentUrl, StorageClassSet storageClassSet, Map<String, Object> parameters)
|
||||
{
|
||||
backingStore.updateStorageClasses(contentUrl, storageClassSet, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
return backingStore.findStorageClasses(contentUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
return backingStore.getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(String contentUrl)
|
||||
{
|
||||
return backingStore.findStorageClassesTransitions(contentUrl);
|
||||
}
|
||||
}
|
||||
|
@@ -1,58 +1,58 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content.filestore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.ContentStoreCreatedEvent;
|
||||
import org.alfresco.repo.content.EmptyContentReader;
|
||||
import org.alfresco.repo.content.UnsupportedContentUrlException;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.Deleter;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.ContentStoreCreatedEvent;
|
||||
import org.alfresco.repo.content.EmptyContentReader;
|
||||
import org.alfresco.repo.content.UnsupportedContentUrlException;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.util.Deleter;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
|
||||
/**
|
||||
* Provides a store of node content directly to the file system. The writers
|
||||
@@ -206,7 +206,7 @@ public class FileContentStore
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public void setFileContentUrlProvider(FileContentUrlProvider fileContentUrlProvider)
|
||||
public void setFileContentUrlProvider(FileContentUrlProvider fileContentUrlProvider)
|
||||
{
|
||||
this.fileContentUrlProvider = fileContentUrlProvider;
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@ package org.alfresco.repo.content.replication;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
@@ -35,6 +37,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.content.AbstractContentStore;
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.content.UnsupportedContentUrlException;
|
||||
import org.alfresco.repo.content.caching.CachingContentStore;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
@@ -64,9 +67,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
* @see CachingContentStore
|
||||
*/
|
||||
public class AggregatingContentStore extends AbstractContentStore
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(AggregatingContentStore.class);
|
||||
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(AggregatingContentStore.class);
|
||||
private static final String REPLICATING_CONTENT_STORE_NOT_INITIALISED = "ReplicatingContentStore not initialised";
|
||||
|
||||
private ContentStore primaryStore;
|
||||
private List<ContentStore> secondaryStores;
|
||||
|
||||
@@ -134,7 +138,7 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
{
|
||||
if (primaryStore == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
|
||||
throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED);
|
||||
}
|
||||
|
||||
// get a read lock so that we are sure that no replication is underway
|
||||
@@ -169,11 +173,12 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String contentUrl)
|
||||
{
|
||||
if (primaryStore == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
|
||||
throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED);
|
||||
}
|
||||
|
||||
// get a read lock so that we are sure that no replication is underway
|
||||
@@ -239,6 +244,7 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentWriter getWriter(ContentContext ctx)
|
||||
{
|
||||
// get the writer
|
||||
@@ -253,6 +259,7 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
*
|
||||
* @return Returns the value returned by the delete on the primary store.
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String contentUrl) throws ContentIOException
|
||||
{
|
||||
// delete on the primary store
|
||||
@@ -268,6 +275,7 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
/**
|
||||
* @return Returns <tt>true</tt> if at least one store supports direct access
|
||||
*/
|
||||
@Override
|
||||
public boolean isDirectAccessSupported()
|
||||
{
|
||||
// Check the primary store
|
||||
@@ -292,11 +300,12 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
return isDirectAccessSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectAccessUrl getDirectAccessUrl(String contentUrl, Date expiresAt)
|
||||
{
|
||||
if (primaryStore == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
|
||||
throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED);
|
||||
}
|
||||
|
||||
// get a read lock so that we are sure that no replication is underway
|
||||
@@ -375,4 +384,107 @@ public class AggregatingContentStore extends AbstractContentStore
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(StorageClassSet storageClassesSet)
|
||||
{
|
||||
// We only need to provide info about the primary store,
|
||||
// because the aggregating CS only allows to be written in the primary
|
||||
return primaryStore.isStorageClassesSupported(storageClassesSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
// We only need to provide info about the primary store,
|
||||
// because the aggregating CS only allows to be written in the primary
|
||||
return primaryStore.getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(String contentUrl, StorageClassSet storageClassSet, Map<String, Object> parameters)
|
||||
{
|
||||
primaryStore.updateStorageClasses(contentUrl, storageClassSet, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
if (primaryStore == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException(REPLICATING_CONTENT_STORE_NOT_INITIALISED);
|
||||
}
|
||||
|
||||
// get a read lock so that we are sure that no replication is underway
|
||||
readLock.lock();
|
||||
try
|
||||
{
|
||||
// Keep track of the unsupported state of the content URL - it might be a rubbish URL
|
||||
boolean contentUrlSupported = true;
|
||||
StorageClassSet storageClassesSet = null;
|
||||
|
||||
// Check the primary store
|
||||
try
|
||||
{
|
||||
storageClassesSet = primaryStore.findStorageClasses(contentUrl);
|
||||
}
|
||||
catch (UnsupportedContentUrlException e)
|
||||
{
|
||||
// The store can't handle the content URL
|
||||
contentUrlSupported = false;
|
||||
}
|
||||
|
||||
if (storageClassesSet != null)
|
||||
{
|
||||
return storageClassesSet;
|
||||
}
|
||||
|
||||
// the content is not in the primary store so we have to go looking for it
|
||||
for (ContentStore store : secondaryStores)
|
||||
{
|
||||
try
|
||||
{
|
||||
storageClassesSet = store.findStorageClasses(contentUrl);
|
||||
}
|
||||
catch (UnsupportedContentUrlException e)
|
||||
{
|
||||
// The store can't handle the content URL
|
||||
contentUrlSupported = false;
|
||||
}
|
||||
|
||||
if (storageClassesSet != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (storageClassesSet == null && !contentUrlSupported)
|
||||
{
|
||||
// The content URL was not supported
|
||||
throw new UnsupportedContentUrlException(this, contentUrl);
|
||||
}
|
||||
|
||||
return storageClassesSet;
|
||||
}
|
||||
finally
|
||||
{
|
||||
readLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
// We only need to provide info about the primary store,
|
||||
// because the aggregating CS only allows to be written in the primary
|
||||
return primaryStore.getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(String contentUrl)
|
||||
{
|
||||
// We only need to provide info about the primary store,
|
||||
// because the aggregating CS only allows to be written in the primary
|
||||
return primaryStore.findStorageClassesTransitions(contentUrl);
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +1,53 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #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.Set;
|
||||
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.content.StorageClassSet;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Content Store that supports tenant routing, if multi-tenancy is enabled.
|
||||
@@ -270,6 +272,43 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
return getTenantContentStore().isStorageClassesSupported(storageClassSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return getTenantContentStore().getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(String contentUrl, StorageClassSet storageClassSet,
|
||||
Map<String, Object> parameters)
|
||||
{
|
||||
getTenantContentStore().updateStorageClasses(contentUrl, storageClassSet, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
return getTenantContentStore().findStorageClasses(contentUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
return getTenantContentStore().getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(String contentUrl)
|
||||
{
|
||||
return getTenantContentStore().findStorageClassesTransitions(contentUrl);
|
||||
}
|
||||
|
||||
protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot);
|
||||
}
|
||||
|
@@ -25,13 +25,18 @@
|
||||
*/
|
||||
package org.alfresco.service.cmr.repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.service.Auditable;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Provides methods for accessing and transforming content.
|
||||
* <p>
|
||||
@@ -146,6 +151,40 @@ public interface ContentService
|
||||
public ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update)
|
||||
throws InvalidNodeRefException, InvalidTypeException;
|
||||
|
||||
/**
|
||||
* Get a content writer for the given node property, choosing to optionally have
|
||||
* the node property updated automatically when the content stream closes.
|
||||
* <p>
|
||||
* If the update flag is off, then the state of the node property will remain unchanged
|
||||
* regardless of the state of the written binary data. If the flag is on, then the node
|
||||
* property will be updated on the same thread as the code that closed the write
|
||||
* channel.
|
||||
* <p>
|
||||
* If no node is supplied, then the writer will provide a stream into the backing content
|
||||
* store, but will not be associated with any new or previous content.
|
||||
* <p/>
|
||||
* <b>NOTE: </b>The content URL provided will be registered for automatic cleanup in the event
|
||||
* that the transaction, in which this method was called, rolls back. If the transaction
|
||||
* is successful, the writer may still be open and available for use but the underlying binary
|
||||
* will not be cleaned up subsequently. The recommended pattern is to group calls to retrieve
|
||||
* the writer in the same transaction as the calls to subsequently update and close the
|
||||
* write stream - including setting of the related content properties.
|
||||
*
|
||||
* @param nodeRef a reference to a node having a content property, or <tt>null</tt>
|
||||
* to just get a valid writer into a backing content store.
|
||||
* @param propertyQName the name of the property, which must be of type <b>content</b>
|
||||
* @param update true if the property must be updated atomically when the content write
|
||||
* stream is closed (attaches a listener to the stream); false if the client code
|
||||
* will perform the updates itself.
|
||||
* @param storageClassSet storage classes for the content associated with the node property
|
||||
* @return Returns a writer for the content associated with the node property
|
||||
* @throws InvalidNodeRefException if the node doesn't exist
|
||||
* @throws InvalidTypeException if the node property is not of type <b>content</b>
|
||||
*/
|
||||
@Auditable(parameters = {"nodeRef", "propertyQName", "update", "storageClasses"})
|
||||
public ContentWriter getWriter(NodeRef nodeRef, QName propertyQName, boolean update,
|
||||
StorageClassSet storageClassSet) throws InvalidNodeRefException, InvalidTypeException;
|
||||
|
||||
/**
|
||||
* Gets a writer to a temporary location. The longevity of the stored
|
||||
* temporary content is determined by the system.
|
||||
@@ -170,4 +209,62 @@ public interface ContentService
|
||||
*/
|
||||
@Auditable(parameters = {"nodeRef", "expiresAt"})
|
||||
public DirectAccessUrl getDirectAccessUrl(NodeRef nodeRef, Date expiresAt);
|
||||
|
||||
/**
|
||||
* Checks whether or not the current {@link ContentService} supports the provided {@link Set} storage classes
|
||||
*
|
||||
* @param storageClassSet The storage classes that will be checked whether or not are supported
|
||||
* @return true if the storage classes are supported, false otherwise.
|
||||
*/
|
||||
default boolean isStorageClassesSupported(StorageClassSet storageClassSet)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the complete {@link Set} of supported storage classes by this {@link ContentService}
|
||||
*/
|
||||
default Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the storage class for a {@link NodeRef}
|
||||
*
|
||||
* @param nodeRef The ref of the node that will have its storage classes updated
|
||||
* @param storageClassSet The new storage classes
|
||||
* @param parameters extra parameters
|
||||
*/
|
||||
default void updateStorageClasses(NodeRef nodeRef, StorageClassSet storageClassSet, Map<String, Object> parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeRef the {@link NodeRef} for which the storage classes are to be requested
|
||||
* @return Returns the current storage classes for the given {@link NodeRef}
|
||||
*/
|
||||
default StorageClassSet findStorageClasses(NodeRef nodeRef)
|
||||
{
|
||||
return ContentStore.SCS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the complete collection of allowed storage classes transitions.
|
||||
* The key represents the source storage classes while the value (as a {@link Set}) represents all the possible target storage classes.
|
||||
*/
|
||||
default Map<StorageClassSet, Set<StorageClassSet>> getStorageClassesTransitions()
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeRef the {@link NodeRef} for which the storage classes transitions are to be requested
|
||||
* @return Returns the complete collection of allowed storage classes transitions for the content found at content URL
|
||||
*/
|
||||
default Map<StorageClassSet, Set<StorageClassSet>> findStorageClassesTransitions(NodeRef nodeRef)
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
@@ -481,7 +481,7 @@
|
||||
<!-- =========================== -->
|
||||
|
||||
<!-- Reading requires the permission to read content -->
|
||||
<!-- Writing required the permission to write conent -->
|
||||
<!-- Writing required the permission to write content -->
|
||||
|
||||
<bean id="ContentService_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
|
||||
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
|
||||
@@ -490,12 +490,17 @@
|
||||
<property name="objectDefinitionSource">
|
||||
<value>
|
||||
org.alfresco.service.cmr.repository.ContentService.getStoreTotalSpace=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getStoreFreeSpace=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getStoreFreeSpace=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getSupportedStorageClasses=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.isStorageClassesSupported=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getStorageClassesTransitions=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.getRawReader=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||
org.alfresco.service.cmr.repository.ContentService.getReader=ACL_NODE.0.sys:base.ReadContent
|
||||
org.alfresco.service.cmr.repository.ContentService.getWriter=ACL_NODE.0.sys:base.WriteContent
|
||||
org.alfresco.service.cmr.repository.ContentService.getDirectAccessUrl=ACL_NODE.0.sys:base.ReadContent
|
||||
org.alfresco.service.cmr.repository.ContentService.getTempWriter=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.findStorageClasses=ACL_NODE.0.sys:base.ReadContent
|
||||
org.alfresco.service.cmr.repository.ContentService.updateStorageClasses=ACL_ALLOW
|
||||
org.alfresco.service.cmr.repository.ContentService.*=ACL_DENY
|
||||
</value>
|
||||
</property>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
repository.name=Main Repository
|
||||
|
||||
# Schema number
|
||||
version.schema=15001
|
||||
version.schema=16000
|
||||
|
||||
# Directory configuration
|
||||
|
||||
|
@@ -192,6 +192,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.content.caching.quota.StandardQuotaStrategyMockTest.class,
|
||||
org.alfresco.repo.content.caching.quota.UnlimitedQuotaStrategyTest.class,
|
||||
org.alfresco.repo.content.caching.CachingContentStoreTest.class,
|
||||
org.alfresco.repo.version.ContentServiceImplWithMockedContentStoreTest.class,
|
||||
org.alfresco.repo.content.caching.ContentCacheImplTest.class,
|
||||
org.alfresco.repo.domain.permissions.FixedAclUpdaterUnitTest.class,
|
||||
org.alfresco.repo.domain.propval.PropertyTypeConverterTest.class,
|
||||
|
@@ -49,6 +49,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.RepositoryStartupTest.class,
|
||||
org.alfresco.repo.content.cleanup.ContentStoreCleanerTest.class,
|
||||
org.alfresco.repo.content.RoutingContentServiceTest.class,
|
||||
org.alfresco.repo.content.StorageClassTest.class,
|
||||
org.alfresco.repo.exporter.ExporterComponentTest.class,
|
||||
|
||||
// the following two tests fail on windows
|
||||
|
@@ -1,52 +1,54 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.cache.DefaultSimpleCache;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.cache.DefaultSimpleCache;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* Ensures that the routing of URLs based on context is working. A combination
|
||||
@@ -65,6 +67,7 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
private ContentStore storeB;
|
||||
private ContentStore storeC;
|
||||
private ContentStore storeD;
|
||||
private ContentStore storeE;
|
||||
private ContentStore routingStore;
|
||||
|
||||
@Before
|
||||
@@ -82,8 +85,11 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
storeC = new DumbReadOnlyFileStore(new FileContentStore(ctx, storeCDir));
|
||||
// No subdirectory for D
|
||||
storeD = new SupportsNoUrlFormatStore();
|
||||
// Create a subdirectory for E
|
||||
File storeEDir = new File(tempDir, "E");
|
||||
storeE = new AnyStorageClassesSupportedStore(new FileContentStore(ctx, storeEDir));
|
||||
// Create the routing store
|
||||
routingStore = new RandomRoutingContentStore(storeA, storeB, storeC, storeD);
|
||||
routingStore = new RandomRoutingContentStore(storeA, storeB, storeC, storeD, storeE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,7 +106,8 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
|
||||
private void checkForContent(String contentUrl, String content)
|
||||
{
|
||||
for (ContentStore store : new ContentStore[] {storeA, storeB})
|
||||
// Check on all write stores
|
||||
for (ContentStore store : new ContentStore[] {storeA, storeB, storeE})
|
||||
{
|
||||
// Does the store have it
|
||||
if (store.exists(contentUrl))
|
||||
@@ -156,6 +163,30 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
assertTrue("Reader should be onto live content", reader.exists());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsStorageClassesSupported()
|
||||
{
|
||||
assertTrue(routingStore.isStorageClassesSupported(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStorageClassesForGivenContentUrl()
|
||||
{
|
||||
// Ensure content is created on storeE, the store that supports "a-storage-class"
|
||||
ContentContext contentContext = new ContentContext(null, null);
|
||||
ContentWriter writer = storeE.getWriter(contentContext);
|
||||
String content = "This was generated by " + this.getClass().getName()
|
||||
+ "#testUpdateStorageClassesForGivenContentUrl";
|
||||
writer.putContent(content);
|
||||
|
||||
String contentUrl = writer.getContentUrl();
|
||||
|
||||
// Update storage classes
|
||||
routingStore.updateStorageClasses(contentUrl, ContentStore.SCS_DEFAULT, null);
|
||||
|
||||
assertEquals(ContentStore.SCS_DEFAULT, routingStore.findStorageClasses(contentUrl));
|
||||
}
|
||||
|
||||
/**
|
||||
* A test routing store that directs content writes to a randomly-chosen store.
|
||||
@@ -203,6 +234,57 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A test content store that supports any String as storage class.
|
||||
*
|
||||
*/
|
||||
private static class AnyStorageClassesSupportedStore extends AbstractContentStore
|
||||
{
|
||||
FileContentStore fileStore;
|
||||
StorageClassSet storageClasses = new StorageClassSet();
|
||||
|
||||
public AnyStorageClassesSupportedStore(FileContentStore fileStore)
|
||||
{
|
||||
this.fileStore = fileStore;
|
||||
}
|
||||
|
||||
public boolean isWriteSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public ContentReader getReader(String contentUrl)
|
||||
{
|
||||
return fileStore.getReader(contentUrl);
|
||||
}
|
||||
|
||||
protected ContentWriter getWriterInternal(ContentReader existingContentReader,
|
||||
String newContentUrl)
|
||||
{
|
||||
return fileStore.getWriterInternal(existingContentReader, newContentUrl);
|
||||
}
|
||||
|
||||
public boolean delete(String contentUrl)
|
||||
{
|
||||
return fileStore.delete(contentUrl);
|
||||
}
|
||||
|
||||
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateStorageClasses(String contentUrl, StorageClassSet storageClasses, Map<String, Object> parameters)
|
||||
{
|
||||
this.storageClasses = storageClasses;
|
||||
}
|
||||
|
||||
public StorageClassSet findStorageClasses(String contentUrl)
|
||||
{
|
||||
return this.storageClasses;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The simplest possible store.
|
||||
|
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Spy;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.SystemException;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
public class StorageClassTest extends BaseSpringTest
|
||||
{
|
||||
private static final String DEFAULT_SC = "Default1";
|
||||
private static final String TEST_NAMESPACE = "TestNameSpace";
|
||||
private TransactionService transactionService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
private NodeService nodeService;
|
||||
private NodeRef rootNode;
|
||||
@Spy
|
||||
ContentStore mockContentStore;
|
||||
ContentService contentService;
|
||||
ContentStore contentStore;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
nodeService = (NodeService) applicationContext.getBean("NodeService");
|
||||
transactionService = (TransactionService) applicationContext.getBean("TransactionService");
|
||||
this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
|
||||
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
|
||||
this.contentStore = (ContentStore) ReflectionTestUtils.getField(contentService, "store");
|
||||
|
||||
FileContentStore fileContentStore = new FileContentStore(applicationContext, this.contentStore.getRootLocation());
|
||||
mockContentStore = spy(fileContentStore);
|
||||
|
||||
when(mockContentStore.getSupportedStorageClasses()).thenReturn(Set.of(DEFAULT_SC, "Azure", "S3"));
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "testStoreRef");
|
||||
if (!nodeService.exists(storeRef))
|
||||
{
|
||||
storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
|
||||
}
|
||||
rootNode = nodeService.getRootNode(storeRef);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTestMethod()
|
||||
{
|
||||
ReflectionTestUtils.setField(contentService, "store", contentStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSupportedStorageClasses()
|
||||
{
|
||||
assertTrue("Currently supported storage classes:" + contentService.getSupportedStorageClasses(), contentService.getSupportedStorageClasses().contains(DEFAULT_SC));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkDefaultStorageClassTransitions() throws NotSupportedException, SystemException
|
||||
{
|
||||
ReflectionTestUtils.setField(contentService, "store", contentStore);
|
||||
NodeRef contentNodeRef = createNode("testNode1" + GUID.generate(), "testContent2");
|
||||
|
||||
// Check default storage classes transition
|
||||
assertTrue("Expected DEFAULT_SC ", contentService.getStorageClassesTransitions().isEmpty());
|
||||
assertTrue("Found default storage transition: ", contentService.findStorageClassesTransitions(contentNodeRef).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStorageClassesTransitions()
|
||||
{
|
||||
StorageClassSet key1 = new StorageClassSet("Default");
|
||||
StorageClassSet key2 = new StorageClassSet("WORM");
|
||||
Set<StorageClassSet> value1 = Set.of(new StorageClassSet("Archive"));
|
||||
Map<StorageClassSet, Set<StorageClassSet>> map = new HashMap<>();
|
||||
map.put(key1, value1);
|
||||
map.put(key2, value1);
|
||||
|
||||
when(mockContentStore.getStorageClassesTransitions()).thenReturn(map);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
assertTrue("Obtained" + contentService.getStorageClassesTransitions(), contentService.getStorageClassesTransitions().containsKey(key1));
|
||||
assertTrue("Obtained" + contentService.getStorageClassesTransitions(), contentService.getStorageClassesTransitions().containsValue(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findStorageClasses() throws NotSupportedException, SystemException
|
||||
{
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), "testContent");
|
||||
String contentUrl = contentService.getReader(contentNodeRef, ContentModel.TYPE_CONTENT).getContentUrl();
|
||||
|
||||
when(mockContentStore.findStorageClasses(contentUrl)).thenReturn(new StorageClassSet("Azure"));
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
assertTrue("Found storage classes: " + contentService.findStorageClasses(contentNodeRef),
|
||||
contentService.findStorageClasses(contentNodeRef).contains("Azure"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findStorageClassesTransitions() throws NotSupportedException, SystemException
|
||||
{
|
||||
StorageClassSet key1 = new StorageClassSet("Default");
|
||||
StorageClassSet key2 = new StorageClassSet("WORM");
|
||||
Set<StorageClassSet> value1 = Set.of(new StorageClassSet("Archive"));
|
||||
Map<StorageClassSet, Set<StorageClassSet>> map = new HashMap<>();
|
||||
map.put(key1, value1);
|
||||
map.put(key2, value1);
|
||||
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), "testContent");
|
||||
String contentUrl = contentService.getReader(contentNodeRef, ContentModel.TYPE_CONTENT).getContentUrl();
|
||||
|
||||
when(mockContentStore.findStorageClassesTransitions(contentUrl)).thenReturn(map);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
assertTrue("Obtained" + contentService.findStorageClassesTransitions(contentNodeRef),
|
||||
contentService.findStorageClassesTransitions(contentNodeRef).containsKey(key1));
|
||||
assertTrue("Obtained" + contentService.findStorageClassesTransitions(contentNodeRef),
|
||||
contentService.findStorageClassesTransitions(contentNodeRef).containsValue(value1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUpdateStorageClasses() throws NotSupportedException, SystemException
|
||||
{
|
||||
final StorageClassSet storageClasses = new StorageClassSet("Azure");
|
||||
final StorageClassSet storageClasses2 = new StorageClassSet("S3");
|
||||
final StorageClassSet storageClasses3 = new StorageClassSet("test1", "test2");
|
||||
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), "testContent");
|
||||
String contentUrl = contentService.getReader(contentNodeRef, ContentModel.TYPE_CONTENT).getContentUrl();
|
||||
|
||||
when(mockContentStore.isStorageClassesSupported(storageClasses)).thenReturn(true);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
mockContentStore.updateStorageClasses(contentUrl, storageClasses, null);
|
||||
assertTrue("Storage classes not supported: ", contentService.isStorageClassesSupported(storageClasses));
|
||||
assertFalse("Storage classes not supported: ", contentService.isStorageClassesSupported(storageClasses2));
|
||||
|
||||
when(mockContentStore.isStorageClassesSupported(storageClasses3)).thenReturn(true);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
assertTrue("Storage classes not supported: ", contentService.isStorageClassesSupported(storageClasses3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUpdateStorageClassesNotSupported() throws NotSupportedException, SystemException
|
||||
{
|
||||
|
||||
final StorageClassSet storageClasses = new StorageClassSet("test");
|
||||
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), "testContent");
|
||||
|
||||
when(mockContentStore.isStorageClassesSupported(storageClasses)).thenReturn(false);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
try
|
||||
{
|
||||
contentService.updateStorageClasses(contentNodeRef, storageClasses, null);
|
||||
fail("The supplied storage classes are not supported");
|
||||
}
|
||||
catch (UnsupportedStorageClassException expectedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUpdateStorageEmptyContent() throws NotSupportedException, SystemException
|
||||
{
|
||||
final StorageClassSet storageClasses = new StorageClassSet("Azure");
|
||||
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), "");
|
||||
String contentUrl = contentService.getReader(contentNodeRef, ContentModel.TYPE_CONTENT).getContentUrl();
|
||||
|
||||
when(mockContentStore.isStorageClassesSupported(storageClasses)).thenReturn(true);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
mockContentStore.updateStorageClasses(contentUrl, storageClasses, null);
|
||||
assertTrue("Storage classes not supported: ", contentService.isStorageClassesSupported(storageClasses));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUpdateStorageClassesWithoutContent() throws NotSupportedException, SystemException
|
||||
{
|
||||
final StorageClassSet storageClasses = new StorageClassSet("Azure");
|
||||
|
||||
NodeRef contentNodeRef = createNode("testNode" + GUID.generate(), null);
|
||||
when(mockContentStore.isStorageClassesSupported(storageClasses)).thenReturn(true);
|
||||
ReflectionTestUtils.setField(contentService, "store", mockContentStore);
|
||||
|
||||
try
|
||||
{
|
||||
contentService.updateStorageClasses(contentNodeRef, storageClasses, null);
|
||||
fail("The supplied nodeRef" + contentNodeRef + "has no content");
|
||||
}
|
||||
catch (IllegalArgumentException expectedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private NodeRef createNode(String name, String testContent) throws SystemException, NotSupportedException
|
||||
{
|
||||
// start the transaction
|
||||
RetryingTransactionHelper.RetryingTransactionCallback<NodeRef> makeContentCallback = new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
|
||||
{
|
||||
public NodeRef execute() throws Throwable
|
||||
{
|
||||
Map<QName, Serializable> nodeProperties = new HashMap<>();
|
||||
nodeProperties.put(ContentModel.PROP_NAME, name);
|
||||
|
||||
ChildAssociationRef assocRef = nodeService
|
||||
.createNode(rootNode, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()),
|
||||
ContentModel.TYPE_CONTENT, nodeProperties);
|
||||
NodeRef contentNodeRef = assocRef.getChildRef();
|
||||
|
||||
// Add the content to the node
|
||||
if (testContent != null)
|
||||
{
|
||||
ContentWriter contentWriter = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.putContent(testContent);
|
||||
}
|
||||
return contentNodeRef;
|
||||
}
|
||||
};
|
||||
|
||||
return transactionService.getRetryingTransactionHelper().doInTransaction(makeContentCallback);
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -26,11 +26,12 @@
|
||||
package org.alfresco.repo.content.caching;
|
||||
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -48,6 +50,7 @@ import java.util.Locale;
|
||||
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.content.caching.quota.QuotaManagerStrategy;
|
||||
import org.alfresco.repo.content.caching.quota.UnlimitedQuotaStrategy;
|
||||
import org.alfresco.repo.content.filestore.SpoofedTextContentReader;
|
||||
@@ -520,4 +523,61 @@ public class CachingContentStoreTest
|
||||
when(backingStore.getDirectAccessUrl(anyString(), any())).thenReturn(new DirectAccessUrl());
|
||||
cachingStore.getDirectAccessUrl("url", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackingStoreIsCalledForSupportedStorageClasses()
|
||||
{
|
||||
when(backingStore.isStorageClassesSupported(new StorageClassSet("a-certain-storage-class"))).thenReturn(true);
|
||||
|
||||
final StorageClassSet storageClassSet = new StorageClassSet("a-certain-storage-class");
|
||||
assertTrue(cachingStore.isStorageClassesSupported(storageClassSet));
|
||||
verify(backingStore, times(1)).isStorageClassesSupported(storageClassSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackingStoreIsCalledForGetSupportedStorageClasses()
|
||||
{
|
||||
when(backingStore.getSupportedStorageClasses()).thenReturn(emptySet());
|
||||
assertTrue(cachingStore.getSupportedStorageClasses().isEmpty());
|
||||
verify(backingStore, times(1)).getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStorageClassesForGivenContentUrl()
|
||||
{
|
||||
String contentUrl = "contentUrl";
|
||||
final StorageClassSet storageClassSet = new StorageClassSet("a-certain-storage-class");
|
||||
|
||||
cachingStore.updateStorageClasses(contentUrl, storageClassSet, null);
|
||||
|
||||
verify(backingStore, times(1)).updateStorageClasses(contentUrl, storageClassSet, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesForGivenContentUrl()
|
||||
{
|
||||
final StorageClassSet storageClassSet = new StorageClassSet();
|
||||
when(backingStore.findStorageClasses(anyString())).thenReturn(storageClassSet);
|
||||
|
||||
assertTrue(cachingStore.findStorageClasses("a-contentUrl").isEmpty());
|
||||
verify(backingStore, times(1)).findStorageClasses("a-contentUrl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorageClassesTransitions()
|
||||
{
|
||||
when(backingStore.getStorageClassesTransitions()).thenReturn(emptyMap());
|
||||
|
||||
assertTrue(cachingStore.getStorageClassesTransitions().isEmpty());
|
||||
verify(backingStore, times(1)).getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesTransitionsForGivenContentUrl()
|
||||
{
|
||||
when(backingStore.findStorageClassesTransitions(anyString())).thenReturn(emptyMap());
|
||||
|
||||
assertTrue(cachingStore.findStorageClassesTransitions("contentUrl").isEmpty());
|
||||
verify(backingStore, times(1)).findStorageClassesTransitions("contentUrl");
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +1,40 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.content.filestore;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentExistsException;
|
||||
@@ -36,6 +42,7 @@ import org.alfresco.repo.content.ContentLimitProvider;
|
||||
import org.alfresco.repo.content.ContentLimitProvider.SimpleFixedLimitProvider;
|
||||
import org.alfresco.repo.content.ContentLimitViolationException;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
@@ -45,12 +52,6 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests read and write functionality for the store.
|
||||
@@ -347,6 +348,18 @@ public class FileContentStoreTest extends AbstractWritableContentStoreTest
|
||||
assertTrue(reader instanceof SpoofedTextContentReader);
|
||||
assertEquals(1024L, reader.getContentString().getBytes("UTF-8").length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsDefaultStorageClass()
|
||||
{
|
||||
assertTrue(store.isStorageClassesSupported(ContentStore.SCS_DEFAULT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotSupportUnknownStorageClass()
|
||||
{
|
||||
assertFalse(store.isStorageClassesSupported(new StorageClassSet("unknown")));
|
||||
}
|
||||
|
||||
private void assertDirExists(File root, String dir)
|
||||
{
|
||||
|
@@ -25,6 +25,22 @@
|
||||
*/
|
||||
package org.alfresco.repo.content.replication;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,6 +48,7 @@ import java.util.List;
|
||||
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
||||
import org.alfresco.repo.content.ContentContext;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.content.UnsupportedContentUrlException;
|
||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
@@ -42,24 +59,11 @@ import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.alfresco.util.testing.category.NeverRunsTests;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Tests read and write functionality for the aggregating store.
|
||||
@@ -71,6 +75,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Mark Rogers
|
||||
*/
|
||||
@Category({OwnJVMTestsCategory.class, NeverRunsTests.class})
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AggregatingContentStoreTest extends AbstractWritableContentStoreTest
|
||||
{
|
||||
private static final String SOME_CONTENT = "The No. 1 Ladies' Detective Agency";
|
||||
@@ -83,12 +88,9 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
ContentStore primaryStoreMock;
|
||||
@Mock
|
||||
ContentStore secondaryStoreMock;
|
||||
@Mock
|
||||
|
||||
AggregatingContentStore aggregatingContentStoreMock;
|
||||
|
||||
@Rule
|
||||
public MockitoRule rule = MockitoJUnit.rule();
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
@@ -104,10 +106,15 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
FileContentStore store = new FileContentStore(ctx, storeDir);
|
||||
secondaryStores.add(store);
|
||||
}
|
||||
// Create the aggregating store
|
||||
// Create the aggregating store for Spring tests
|
||||
aggregatingStore = new AggregatingContentStore();
|
||||
aggregatingStore.setPrimaryStore(primaryStore);
|
||||
aggregatingStore.setSecondaryStores(secondaryStores);
|
||||
|
||||
// Create a mocked aggregating store
|
||||
aggregatingContentStoreMock = new AggregatingContentStore();
|
||||
aggregatingContentStoreMock.setPrimaryStore(primaryStoreMock);
|
||||
aggregatingContentStoreMock.setSecondaryStores(List.of(secondaryStoreMock));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +149,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
return writer.getContentUrl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddContent() throws Exception
|
||||
{
|
||||
ContentWriter writer = getWriter();
|
||||
@@ -163,6 +171,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
assertEquals("Reader state differs from expected: " + reader, mustExist, reader.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception
|
||||
{
|
||||
|
||||
@@ -179,6 +188,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
checkForUrl(contentUrl, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromSecondaryStore()
|
||||
{
|
||||
// pick a secondary store and write some content to it
|
||||
@@ -191,45 +201,43 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDirectAccessSupported()
|
||||
public void testDirectAccessUnsupportedByDefault()
|
||||
{
|
||||
// Create the aggregating store
|
||||
AggregatingContentStore aggStore = new AggregatingContentStore();
|
||||
aggStore.setPrimaryStore(primaryStoreMock);
|
||||
aggStore.setSecondaryStores(List.of(secondaryStoreMock));
|
||||
|
||||
// By default it is unsupported
|
||||
assertFalse(aggStore.isDirectAccessSupported());
|
||||
|
||||
// Supported if at least one store supports direct access
|
||||
{
|
||||
when(primaryStoreMock.isDirectAccessSupported()).thenReturn(false);
|
||||
when(secondaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
assertTrue(aggStore.isDirectAccessSupported());
|
||||
|
||||
when(primaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
when(secondaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
assertTrue(aggStore.isDirectAccessSupported());
|
||||
|
||||
when(primaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
when(secondaryStoreMock.isDirectAccessSupported()).thenReturn(false);
|
||||
assertTrue(aggStore.isDirectAccessSupported());
|
||||
}
|
||||
assertFalse(aggregatingContentStoreMock.isDirectAccessSupported());
|
||||
verify(primaryStoreMock, times(1)).isDirectAccessSupported();
|
||||
verify(secondaryStoreMock, times(1)).isDirectAccessSupported();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDirectAccessSupportedByPrimaryStore()
|
||||
{
|
||||
when(primaryStoreMock.isDirectAccessSupported()).thenReturn(false);
|
||||
when(secondaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.isDirectAccessSupported());
|
||||
verify(primaryStoreMock, times(1)).isDirectAccessSupported();
|
||||
verify(secondaryStoreMock, times(1)).isDirectAccessSupported();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDirectAccessSupportedBySecondaryStore()
|
||||
{
|
||||
when(primaryStoreMock.isDirectAccessSupported()).thenReturn(true);
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.isDirectAccessSupported());
|
||||
verify(primaryStoreMock, times(1)).isDirectAccessSupported();
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDirectAccessUrl()
|
||||
{
|
||||
// Create the aggregating store
|
||||
AggregatingContentStore aggStore = new AggregatingContentStore();
|
||||
aggStore.setPrimaryStore(primaryStoreMock);
|
||||
aggStore.setSecondaryStores(List.of(secondaryStoreMock));
|
||||
|
||||
UnsupportedOperationException unsupportedExc = new UnsupportedOperationException();
|
||||
UnsupportedContentUrlException unsupportedContentUrlExc = new UnsupportedContentUrlException(aggStore, "");
|
||||
UnsupportedContentUrlException unsupportedContentUrlExc = new UnsupportedContentUrlException(aggregatingContentStoreMock, "");
|
||||
|
||||
// By default it is unsupported
|
||||
DirectAccessUrl directAccessUrl = aggStore.getDirectAccessUrl("url", null);
|
||||
DirectAccessUrl directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("url", null);
|
||||
assertNull(directAccessUrl);
|
||||
|
||||
// Direct access not supported
|
||||
@@ -237,7 +245,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
{
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
|
||||
aggStore.getDirectAccessUrl("urlDANotSupported", null);
|
||||
aggregatingContentStoreMock.getDirectAccessUrl("urlDANotSupported", null);
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
@@ -249,7 +257,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
{
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
|
||||
aggStore.getDirectAccessUrl("urlDANotSupported", null);
|
||||
aggregatingContentStoreMock.getDirectAccessUrl("urlDANotSupported", null);
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
@@ -261,7 +269,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
{
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
aggStore.getDirectAccessUrl("urlDANotSupported", null);
|
||||
aggregatingContentStoreMock.getDirectAccessUrl("urlDANotSupported", null);
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
@@ -274,7 +282,7 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
{
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
aggStore.getDirectAccessUrl("urlNotSupported", null);
|
||||
aggregatingContentStoreMock.getDirectAccessUrl("urlNotSupported", null);
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedContentUrlException e)
|
||||
@@ -283,30 +291,145 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
||||
}
|
||||
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedExc);
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlPriSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlPriSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlSecSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedContentUrlExc);
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlSecSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
|
||||
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlPriSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
|
||||
directAccessUrl = aggregatingContentStoreMock.getDirectAccessUrl("urlSecSupported", null);
|
||||
assertNotNull(directAccessUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsStorageClassesSupported()
|
||||
{
|
||||
final StorageClassSet sc = new StorageClassSet("a-certain-storage-class");
|
||||
when(primaryStoreMock.isStorageClassesSupported(sc)).thenReturn(true);
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.isStorageClassesSupported(sc));
|
||||
verify(primaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStorageClassesIsNotSupported()
|
||||
{
|
||||
final StorageClassSet sc = new StorageClassSet("a-certain-storage-class");
|
||||
when(primaryStoreMock.isStorageClassesSupported(sc)).thenReturn(false);
|
||||
|
||||
assertFalse(aggregatingContentStoreMock.isStorageClassesSupported(sc));
|
||||
verify(primaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSupportedStorageClasses()
|
||||
{
|
||||
when(primaryStoreMock.getSupportedStorageClasses()).thenReturn(emptySet());
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.getSupportedStorageClasses().isEmpty());
|
||||
verify(primaryStoreMock, times(1)).getSupportedStorageClasses();
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStorageClassesForGivenContentUrl()
|
||||
{
|
||||
String contentUrl = "contentUrl";
|
||||
final StorageClassSet sc = new StorageClassSet("a-certain-storage-class");
|
||||
|
||||
aggregatingContentStoreMock.updateStorageClasses(contentUrl, sc, null);
|
||||
|
||||
verify(primaryStoreMock, times(1)).updateStorageClasses(contentUrl, sc, null);
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesForGivenContentUrlInPrimaryStore()
|
||||
{
|
||||
final StorageClassSet sc = new StorageClassSet();
|
||||
when(primaryStoreMock.findStorageClasses(anyString())).thenReturn(sc);
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.findStorageClasses("a-contentUrl").isEmpty());
|
||||
verify(primaryStoreMock, times(1)).findStorageClasses("a-contentUrl");
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesForGivenContentUrlInSecondaryStore()
|
||||
{
|
||||
final StorageClassSet sc = new StorageClassSet();
|
||||
UnsupportedContentUrlException unsupportedContentUrlExc = new UnsupportedContentUrlException(
|
||||
aggregatingContentStoreMock, "");
|
||||
|
||||
when(primaryStoreMock.findStorageClasses(anyString())).thenThrow(unsupportedContentUrlExc);
|
||||
when(secondaryStoreMock.findStorageClasses(anyString())).thenReturn(sc);
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.findStorageClasses("a-contentUrl").isEmpty());
|
||||
verify(primaryStoreMock, times(1)).findStorageClasses("a-contentUrl");
|
||||
verify(secondaryStoreMock, times(1)).findStorageClasses("a-contentUrl");
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedContentUrlException.class)
|
||||
public void testFindStorageClassesForInvalidContentUrl()
|
||||
{
|
||||
when(primaryStoreMock.findStorageClasses(anyString()))
|
||||
.thenThrow(new UnsupportedContentUrlException(aggregatingContentStoreMock, ""));
|
||||
when(secondaryStoreMock.findStorageClasses(anyString()))
|
||||
.thenThrow(new UnsupportedContentUrlException(aggregatingContentStoreMock, ""));
|
||||
|
||||
aggregatingContentStoreMock.findStorageClasses("a-contentUrl");
|
||||
|
||||
verify(primaryStoreMock, times(1)).findStorageClasses("a-contentUrl");
|
||||
verify(secondaryStoreMock, times(1)).findStorageClasses("a-contentUrl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorageClassesTransitions()
|
||||
{
|
||||
when(primaryStoreMock.getStorageClassesTransitions()).thenReturn(emptyMap());
|
||||
|
||||
assertTrue(aggregatingContentStoreMock.getStorageClassesTransitions().isEmpty());
|
||||
verify(primaryStoreMock, times(1)).getStorageClassesTransitions();
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesTransitionsForGivenContentUrl()
|
||||
{
|
||||
when(primaryStoreMock.findStorageClassesTransitions(anyString())).thenReturn(emptyMap());
|
||||
|
||||
assertTrue(
|
||||
aggregatingContentStoreMock.findStorageClassesTransitions("contentUrl").isEmpty());
|
||||
verify(primaryStoreMock, times(1)).findStorageClassesTransitions("contentUrl");
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedContentUrlException.class)
|
||||
public void testFindStorageClassesTransitionsForUnsupportedContentUrl()
|
||||
{
|
||||
when(primaryStoreMock.findStorageClassesTransitions(anyString()))
|
||||
.thenThrow(new UnsupportedContentUrlException(aggregatingContentStoreMock, ""));
|
||||
|
||||
aggregatingContentStoreMock.findStorageClassesTransitions("contentUrl");
|
||||
|
||||
verify(primaryStoreMock, times(1)).findStorageClassesTransitions("contentUrl");
|
||||
verifyNoInteractions(secondaryStoreMock);
|
||||
}
|
||||
}
|
||||
|
@@ -30,12 +30,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
@@ -59,6 +58,8 @@ import org.alfresco.util.testing.category.NeverRunsTests;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test checking the behaviour of the MT {@link ContentStore} routing
|
||||
*
|
||||
@@ -117,6 +118,21 @@ public class AbstractTenantRoutingContentStoreTest extends TestCase
|
||||
assertFalse("getAllStores method returned the list with null entry", isNullEntry);
|
||||
}
|
||||
|
||||
public void testIsStorageClassesSupported()
|
||||
{
|
||||
assertTrue(fileContentStore.isStorageClassesSupported(new StorageClassSet()));
|
||||
}
|
||||
|
||||
public void testGetSupportedStorageClasses()
|
||||
{
|
||||
assertTrue(fileContentStore.getSupportedStorageClasses().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetStorageClassesTransitions()
|
||||
{
|
||||
assertNotNull(fileContentStore.getStorageClassesTransitions());
|
||||
}
|
||||
|
||||
// helper methods and listener
|
||||
private void checkStores(List<ContentStore> stores)
|
||||
{
|
||||
|
@@ -25,30 +25,24 @@
|
||||
*/
|
||||
package org.alfresco.repo.version;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.EmptyContentReader;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.MimetypeMapTest;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NoTransformerException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Tests for getting content readers and writers.
|
||||
*
|
||||
@@ -179,4 +173,20 @@ public class ContentServiceImplTest extends BaseVersionStoreTest
|
||||
assertEquals(null, contentService.getDirectAccessUrl(nodeRef, null));
|
||||
assertEquals(null, contentService.getDirectAccessUrl(nodeRef, expiresAt));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClasses()
|
||||
{
|
||||
final NodeRef newNode = createNewNode();
|
||||
final Set<String> storageClasses = contentService.findStorageClasses(newNode);
|
||||
assertEquals(1, storageClasses.size());
|
||||
assertEquals(storageClasses, ContentStore.SCS_DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesTransitions()
|
||||
{
|
||||
final NodeRef newNode = createNewNode();
|
||||
assertNotNull(contentService.findStorageClassesTransitions(newNode));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.version;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.alfresco.repo.content.ContentServiceImpl;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.StorageClassSet;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* Tests for the CachingContentStore class. Tests use mock backing store and cache.
|
||||
*
|
||||
* @author Lucian Tuca
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ContentServiceImplWithMockedContentStoreTest
|
||||
{
|
||||
@Mock
|
||||
private ContentStore store;
|
||||
|
||||
private ContentService contentService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
contentService = new ContentServiceImpl();
|
||||
ReflectionTestUtils.setField(contentService, "store", store);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForIsStorageClassesSupported()
|
||||
{
|
||||
final StorageClassSet sc = new StorageClassSet();
|
||||
when(store.isStorageClassesSupported(sc)).thenReturn(true);
|
||||
assertTrue(contentService.isStorageClassesSupported(sc));
|
||||
verify(store, times(1)).isStorageClassesSupported(sc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForGetSupportedStorageClasses()
|
||||
{
|
||||
when(store.getSupportedStorageClasses()).thenReturn(emptySet());
|
||||
assertTrue(contentService.getSupportedStorageClasses().isEmpty());
|
||||
verify(store, times(1)).getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForGetStorageClassesTransitions()
|
||||
{
|
||||
when(store.getStorageClassesTransitions()).thenReturn(emptyMap());
|
||||
assertTrue(contentService.getStorageClassesTransitions().isEmpty());
|
||||
verify(store, times(1)).getStorageClassesTransitions();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user