Compare commits

...

94 Commits
17.155 ... 14.1

Author SHA1 Message Date
Travis CI User
8e3144a2d1 [maven-release-plugin][skip ci] prepare release 14.1 2021-07-30 16:14:37 +00:00
Andrea Ligios
c0585df456 Merge branch 'feature/ACS-1383_StorageClasses' into release/7.2.0 2021-07-30 17:18:38 +02:00
Andrea Ligios
483b894cb2 ACS-1864 - Fixed the test case with the proper expectations 2021-07-30 12:17:20 +02:00
Travis CI User
e477721406 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-29 16:16:12 +00:00
Travis CI User
1717c909dd [maven-release-plugin][skip ci] prepare release 14.0 2021-07-29 16:16:05 +00:00
Andrea Ligios
6cf6499239 Merge remote-tracking branch 'origin/feature/ACS-1383_StorageClasses' into feature/ACS-1383_StorageClasses 2021-07-29 15:14:25 +02:00
Andrea Ligios
572cb4eb9e ACS-1775 - Consolidated the test, then fixed the bug 2021-07-29 15:13:51 +02:00
Andrea Ligios
9f96809413 ACS-1775 - Fixed test bugs (method name, imports) and changed the HTTP code expected 2021-07-29 15:13:51 +02:00
Roxana Gherghelas
91aec46bce ACS-1585: storage classes e2e tests (#522)
* ACS-1585: add test storage classes

* ACS-1585: Added test for findStorageTransition()

* ACS-1585: update and add tests for updateStorageClass

* ACS-1585: - add storage classes tests for GET /nodes/{nodeId} and PUT /nodes/{nodeId}

* ACS-1585: Add test for issue ACS-1775

* ACS-1585: - cleanup

Co-authored-by: Andrei Forascu <andrei.forascu@ness.com>
2021-07-29 15:13:50 +02:00
Denis Ungureanu
870a9ee4fd ACS-1631 : Storage classes - REST api - POST & GET /nodes/{nodeId}/children (#540) 2021-07-29 15:13:50 +02:00
Lucian Tuca
cf14112626 ACS-1711 : [SPIKE] Update the S3 connector to support Storage Classes (#559)
- update the storage class representation
2021-07-29 15:13:50 +02:00
Denis Ungureanu
1c915e4fb0 ACS-1632 : Storage classes - REST api - PUT /nodes/{nodeId} (#565)
- added update

Co-authored-by: Lucian Tuca <tzclucian@gmail.com>
2021-07-29 15:13:50 +02:00
Ancuta Morarasu
dab6f70936 ACS-1584: REST API storage-classes endpoint (#509) 2021-07-29 15:13:50 +02:00
Lucian Tuca
4a7ea71f4e ACS-1630 : Storage classes - REST api - GET /nodes/{nodeId} (#517)
ACS-1630 : Storage classes - REST api - GET /nodes/{nodeId}
   - updated endpoint to reflect storage classes changes
2021-07-29 15:13:50 +02:00
Denis Ungureanu
22f7f1898f ACS-1602 : Update & tests for AbstractRoutingContentStore (#498) 2021-07-29 15:13:50 +02:00
Lucian Tuca
514ebb4828 ACS-1603 : Update & tests for AbstractTenantRoutingContentStore 2021-07-29 15:13:50 +02:00
Lucian Tuca
e4f39a5d63 ACS-1607 : Update & tests for ContentServiceImpl (#488)
- added impl and tests
2021-07-29 15:13:50 +02:00
Denis Ungureanu
5578cec604 ACS-1605 : Update & tests for CachingContentStore (#475) 2021-07-29 15:13:50 +02:00
Denis Ungureanu
57dbd4d12f ACS-1604 : Update & tests for AggregatingContentStore (#486) 2021-07-29 15:13:50 +02:00
Lucian Tuca
0b840643f9 ACS-1582 : Storage classes - java api (#467)
* ACS-1582 : Storage classes - java api
   - added ContentContext updates
   - added StorageClasses related exception
2021-07-29 15:13:49 +02:00
Andrea Ligios
653ed68bd9 ACS-1775 - Consolidated the test, then fixed the bug 2021-07-29 15:07:22 +02:00
Travis CI User
634602662c [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-28 16:18:26 +02:00
Travis CI User
aeed1e00cb [maven-release-plugin][skip ci] prepare release 11.93 2021-07-28 16:18:26 +02:00
dependabot-preview[bot]
0844539c68 Bump dependency.webscripts.version from 8.19 to 8.22 (#623) 2021-07-28 16:18:26 +02:00
alandavis
aff5ed3953 Create release/7.2.0 branch early so we have somewhere to put ACS 7.2.0 functionality while we finish off 7.1.0 on master (was 11.94-SNAPSHOT). We will merge commits on this branch to master and then delete it when master starts being used for 7.2.0.
[skip ci] as nexus is broken at the moment.
2021-07-28 14:09:29 +01:00
Andrea Ligios
374de2c026 ACS-1775 - Fixed test bugs (method name, imports) and changed the HTTP code expected 2021-07-22 17:16:36 +02:00
Ayman Harake
676ad11681 ATS-952: bump T-engines to version 2.5.2 (#604) 2021-07-22 17:16:36 +02:00
Travis CI User
3a74246523 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:36 +02:00
Travis CI User
8aae69b847 [maven-release-plugin][skip ci] prepare release 11.92 2021-07-22 17:16:36 +02:00
Manpreet Oberoi
402d8dff00 RM-6941 Changes related to retain frozen Records (#590)
* changes related to retain frozen Records

* RM-6941 add Log entries [ags][skip repo]

* RM-6941 Remove final from the variable declaration

Co-authored-by: bdwiwedi <brij.dwiwedi@globallogic.com>
2021-07-22 17:16:36 +02:00
Travis CI User
7e5b3973e9 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:36 +02:00
Travis CI User
33f93a2ad2 [maven-release-plugin][skip ci] prepare release 11.91 2021-07-22 17:16:36 +02:00
Abdul Mohammed
f9ab8425a5 Add friendly name to scheduled jobs that are currently showing class names (#603) 2021-07-22 17:16:36 +02:00
Travis CI User
0ecba230b7 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:36 +02:00
Travis CI User
9f44b21f07 [maven-release-plugin][skip ci] prepare release 11.90 2021-07-22 17:16:35 +02:00
Alan Davis
f217e4e963 PRODENG-67/PRODENG-69 ACS 7.1 Supported Platforms: PostgreSQL 13.3, 12.7, 11.12 / MariaDB 10.6 (#602)
PostgreSQL 13.3 is also now used by default in all non DB test jobs that used 13.1 before.
2021-07-22 17:16:35 +02:00
evasques
99be37185a PRODSEC-4422 - Scripts not in Data Dictionary can be executed by action (#596)
* Added validation to the ScriptActionExecuter class to enforce the existing constraints on parameter script-ref (Repo has the constraint to only allow scripts in Data Dictionary / Scripts and AGS has the constraint to only allow scripts in Data Dictionary / Records Management / Records Management Scripts") by validating if the given scriptRef is in the allowed valued of the constraint set on that param
* Added a new unit test for AGS to make sure that rmscript action still works as expected when the script is in the correct folder and fails when not
* Added new case in ActionServiceImpl2Test#testExecuteScript to assert that the transaction fails when we execute the action with an invalid script
* Moved test testActionResult from ActionServiceImplTest to class ActionServiceImpl2Test - Before it ran with a script not in Data Dictionary so with the added validation it started to fail. I moved the unit test do avoid duplicating the code to create the script in the correct location.
2021-07-22 17:16:35 +02:00
Travis CI User
06b994125a [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
62fa02b1ac [maven-release-plugin][skip ci] prepare release 11.89 2021-07-22 17:16:35 +02:00
evasques
23b99ac6a2 MNT-22481 - Unable to Create Custom Metadata (#598)
* Upgrading org.json:json from version 20090211 to 20201115 introduced the issue as getString method in the newer version does not allow for values other than strings
* Replaced getString for the get method
* Original PR in governance-services: https://github.com/Alfresco/governance-services/pull/1448
2021-07-22 17:16:35 +02:00
Travis CI User
9700668e2f [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
46d1e73054 [maven-release-plugin][skip ci] prepare release 11.88 2021-07-22 17:16:35 +02:00
dependabot-preview[bot]
afd63d0794 Bump docker-java from 3.0.14 to 3.2.11 (#571) 2021-07-22 17:16:35 +02:00
dependabot-preview[bot]
f47dc25be6 Bump dependency.tika.version from 1.26 to 1.27 (#582) 2021-07-22 17:16:35 +02:00
dependabot-preview[bot]
cb46d0e2fa Bump jboss-logging from 3.4.1.Final to 3.4.2.Final (#506) 2021-07-22 17:16:35 +02:00
dependabot-preview[bot]
387bf6847f Bump jackson-databind from 2.12.3 to 2.12.4 (#580) 2021-07-22 17:16:35 +02:00
Travis CI User
b5f6d04ecb [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
5c40ca5e8a [maven-release-plugin][skip ci] prepare release 11.87 2021-07-22 17:16:35 +02:00
Davide
d9fc5efb75 SEARCH-2878 Update the supported for SearchService (#587) 2021-07-22 17:16:35 +02:00
Travis CI User
e1d91fb84f [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
057c93378a [maven-release-plugin][skip ci] prepare release 11.86 2021-07-22 17:16:35 +02:00
Alex Mukha
ae57159820 Revert "Revert "AUTH-532: Upgrade Keycloak client to match IDS-1.5.0""
This reverts commit e7b5d98dba.
2021-07-22 17:16:35 +02:00
Travis CI User
d58e514bab [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
2d075e5af4 [maven-release-plugin][skip ci] prepare release 11.85 2021-07-22 17:16:35 +02:00
Alex Mukha
38b50992c2 Revert "AUTH-532: Upgrade Keycloak client to match IDS-1.5.0"
This reverts commit bd713ffbe9.
2021-07-22 17:16:35 +02:00
Travis CI User
9425f0b200 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:35 +02:00
Travis CI User
4b53c25218 [maven-release-plugin][skip ci] prepare release 11.84 2021-07-22 17:16:35 +02:00
Davide
a3bac54d38 SEARCH-2878 Update the supported for SearchService to 2.0.2-RC2 (#588) 2021-07-22 17:16:34 +02:00
Travis CI User
cd18d3ca8f [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
d00891d6ab [maven-release-plugin][skip ci] prepare release 11.83 2021-07-22 17:16:34 +02:00
Jamal Kaabi-Mofrad
089c359db2 AUTH-532: Upgrade Keycloak client to match IDS-1.5.0 2021-07-22 17:16:34 +02:00
Travis CI User
a0ffffaff2 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
d4bffaf217 [maven-release-plugin][skip ci] prepare release 11.82 2021-07-22 17:16:34 +02:00
CezarLeahu
9098181574 Use LF for Dockerfile(s) and .sh scripts (.gitattributes) [skip ci] (#576) 2021-07-22 17:16:34 +02:00
Travis CI User
4024787e29 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
43530de673 [maven-release-plugin][skip ci] prepare release 11.81 2021-07-22 17:16:34 +02:00
Gloria Camino
a2b3e9a47f LOC-308 Updated UI files in 15 languages inc AGS amps (#574)
Updated Community repo files
2021-07-22 17:16:34 +02:00
Travis CI User
f0def0fb5b [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
8aa74de959 [maven-release-plugin][skip ci] prepare release 11.80 2021-07-22 17:16:34 +02:00
David Edwards
bdb223f472 ACS-1734 Remove libreofficeToPdf + Update libreofficeToPdfBoxViaPdf (#573) 2021-07-22 17:16:34 +02:00
Travis CI User
91f71cca1f [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
7532bed994 [maven-release-plugin][skip ci] prepare release 11.79 2021-07-22 17:16:34 +02:00
David Edwards
a8f56aa447 ACS-1734 Remove broken transformerFailover from libreofficeToPdf (#572) 2021-07-22 17:16:34 +02:00
Travis CI User
cc41f674b4 [maven-release-plugin][skip ci] prepare for next development iteration 2021-07-22 17:16:34 +02:00
Travis CI User
4e6c3ed818 [maven-release-plugin][skip ci] prepare release 11.78 2021-07-22 17:16:34 +02:00
ramunteanu
bae9fe08c2 APPS-986: [AGS] Export of records with size> 4 MB fails (#511)
- Changed deleteTempFileOnClose to false as the temp file deletion is handled in BufferedResponse#writeResponse
2021-07-22 17:16:34 +02:00
Roxana Gherghelas
99694f72de ACS-1585: storage classes e2e tests (#522)
* ACS-1585: add test storage classes

* ACS-1585: Added test for findStorageTransition()

* ACS-1585: update and add tests for updateStorageClass

* ACS-1585: - add storage classes tests for GET /nodes/{nodeId} and PUT /nodes/{nodeId}

* ACS-1585: Add test for issue ACS-1775

* ACS-1585: - cleanup

Co-authored-by: Andrei Forascu <andrei.forascu@ness.com>
2021-07-12 10:32:13 +03:00
Denis Ungureanu
f207006e93 ACS-1631 : Storage classes - REST api - POST & GET /nodes/{nodeId}/children (#540) 2021-06-30 14:24:35 +03:00
DenisGabriela
ff27b13e41 Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-29 11:32:20 +03:00
Lucian Tuca
6a25322fd4 ACS-1711 : [SPIKE] Update the S3 connector to support Storage Classes (#559)
- update the storage class representation
2021-06-29 11:30:03 +03:00
DenisGabriela
d4e76d9f0f Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-28 15:41:39 +03:00
Denis Ungureanu
68a0441772 ACS-1632 : Storage classes - REST api - PUT /nodes/{nodeId} (#565)
- added update

Co-authored-by: Lucian Tuca <tzclucian@gmail.com>
2021-06-28 14:15:28 +03:00
DenisGabriela
3cb43ab429 Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-25 10:15:32 +03:00
Ancuta Morarasu
a8abf4b842 ACS-1584: REST API storage-classes endpoint (#509) 2021-06-10 14:39:02 +03:00
Lucian Tuca
2dd7d3e5d1 ACS-1630 : Storage classes - REST api - GET /nodes/{nodeId} (#517)
ACS-1630 : Storage classes - REST api - GET /nodes/{nodeId}
   - updated endpoint to reflect storage classes changes
2021-06-09 13:01:33 +03:00
DenisGabriela
0833da358e Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-09 09:31:17 +03:00
Lucian Tuca
a822f2010a Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-07 18:43:50 +03:00
DenisGabriela
219296f8ea Merge branch 'master' into feature/ACS-1383_StorageClasses 2021-06-04 12:37:35 +03:00
Denis Ungureanu
379e12e2c7 ACS-1602 : Update & tests for AbstractRoutingContentStore (#498) 2021-06-04 10:43:21 +03:00
Lucian Tuca
c724ed464c ACS-1603 : Update & tests for AbstractTenantRoutingContentStore 2021-05-26 16:23:52 +03:00
Lucian Tuca
e4f9cc1a1b ACS-1607 : Update & tests for ContentServiceImpl (#488)
- added impl and tests
2021-05-25 15:43:31 +03:00
Denis Ungureanu
c88c58fb88 ACS-1605 : Update & tests for CachingContentStore (#475) 2021-05-25 10:02:36 +03:00
Denis Ungureanu
5257865d8e ACS-1604 : Update & tests for AggregatingContentStore (#486) 2021-05-25 10:01:50 +03:00
Lucian Tuca
269f2f82f2 ACS-1582 : Storage classes - java api (#467)
* ACS-1582 : Storage classes - java api
   - added ContentContext updates
   - added StorageClasses related exception
2021-05-20 15:06:25 +03:00
65 changed files with 2611 additions and 427 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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";

View File

@@ -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()));
}
}

View File

@@ -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)

View File

@@ -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
+ "]";
}
}

View File

@@ -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;
}
}

View File

@@ -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());
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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,

View File

@@ -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
})

View File

@@ -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
*

View File

@@ -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());
}
}

View File

@@ -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();
}

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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()
{

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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();
}
}

View File

@@ -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>

View File

@@ -3,7 +3,7 @@
repository.name=Main Repository
# Schema number
version.schema=15001
version.schema=16000
# Directory configuration

View File

@@ -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,

View File

@@ -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

View File

@@ -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.

View File

@@ -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);
}
}

View File

@@ -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");
}
}

View File

@@ -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)
{

View File

@@ -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);
}
}

View File

@@ -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)
{

View File

@@ -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));
}
}

View File

@@ -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();
}
}