Compare commits

...

78 Commits

Author SHA1 Message Date
mohit-singh4
d1cb0f98c6 [APPS-3242] Fix for facet field aggregation 2025-03-12 20:00:16 +05:30
mohit-singh4
9877b8a9f1 Merge branch 'master' of github.com:Alfresco/alfresco-community-repo into fix/MNT-24172-fixRecreationOfRendition2 2025-03-10 11:56:06 +05:30
alfresco-build
e58df0ab6f [maven-release-plugin][skip ci] prepare for next development iteration 2025-03-09 00:07:02 +00:00
alfresco-build
1ef208546f [maven-release-plugin][skip ci] prepare release 25.1.0.67 2025-03-09 00:07:00 +00:00
Alfresco CI User
28307d7c91 [force] Force release for 2025-03-09. 2025-03-09 00:03:54 +00:00
alfresco-build
0c0a95d095 [maven-release-plugin][skip ci] prepare for next development iteration 2025-03-06 13:29:01 +00:00
alfresco-build
41db40b6a2 [maven-release-plugin][skip ci] prepare release 25.1.0.66 2025-03-06 13:28:59 +00:00
Tiago Salvado
ec78a1486c [MNT-24913] Added fallback method to obtain deployment category in order to check if workflow is secure (#3236) 2025-03-06 12:35:03 +00:00
alfresco-build
7749f7b80d [maven-release-plugin][skip ci] prepare for next development iteration 2025-03-06 10:25:57 +00:00
alfresco-build
1cec73b176 [maven-release-plugin][skip ci] prepare release 25.1.0.65 2025-03-06 10:25:55 +00:00
dependabot[bot]
58902c77f1 Bump org.alfresco:alfresco-transform-model from 5.1.7-A.3 to 5.1.7-A.4 (#3242)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-06 10:39:37 +01:00
alfresco-build
b1f689ed42 [maven-release-plugin][skip ci] prepare for next development iteration 2025-03-03 08:58:23 +00:00
alfresco-build
68ff2e8b43 [maven-release-plugin][skip ci] prepare release 25.1.0.64 2025-03-03 08:58:20 +00:00
Kacper Magdziarz
e5559d544f [ACS-9356] Bump Solr to 2.0.15-A.1 (#3233) 2025-03-03 09:12:10 +01:00
alfresco-build
b618aaf874 [maven-release-plugin][skip ci] prepare for next development iteration 2025-03-02 00:07:51 +00:00
alfresco-build
8260867f49 [maven-release-plugin][skip ci] prepare release 25.1.0.63 2025-03-02 00:07:49 +00:00
Alfresco CI User
ca0c0b54b5 [force] Force release for 2025-03-02. 2025-03-02 00:04:43 +00:00
alfresco-build
c44ff3b5cb [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-28 10:03:00 +00:00
alfresco-build
102a442c66 [maven-release-plugin][skip ci] prepare release 25.1.0.62 2025-02-28 10:02:58 +00:00
dependabot[bot]
c00d1a2f38 Bump net.minidev:json-smart from 2.5.1 to 2.5.2 (#3197)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-28 09:53:03 +01:00
alfresco-build
c6f957d005 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-27 10:32:16 +00:00
alfresco-build
078195379d [maven-release-plugin][skip ci] prepare release 25.1.0.61 2025-02-27 10:32:13 +00:00
rrajoria
2da46a6659 Revert Unlock Document Changes (#3212) 2025-02-27 14:50:15 +05:30
alfresco-build
4846007eb2 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-26 21:30:28 +00:00
alfresco-build
2ddeb8ef80 [maven-release-plugin][skip ci] prepare release 25.1.0.60 2025-02-26 21:30:26 +00:00
Piotr Żurek
0303f74372 ACS-9352 Bump T-Core to 5.1.7-A.3 & ATS to 4.1.7-A.1 (#3226) 2025-02-26 21:34:02 +01:00
alfresco-build
c405974d8d [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-26 16:43:36 +00:00
alfresco-build
d541ba3e49 [maven-release-plugin][skip ci] prepare release 25.1.0.59 2025-02-26 16:43:34 +00:00
Damian Ujma
cc86d9e9ed Revert "ACS-9199 Bump subethasmtp version to 7.1.3 (#3207)" (#3225) 2025-02-26 17:00:04 +01:00
dependabot[bot]
7a7fbf37a2 PRODSEC-9938 PRODSEC-9940 Bump io.netty:netty-bom from 4.1.117.Final to 4.1.118.Final (#3194)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-26 13:57:26 +01:00
alfresco-build
6fd9fed28d [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-26 09:47:17 +00:00
alfresco-build
3f518beb46 [maven-release-plugin][skip ci] prepare release 25.1.0.58 2025-02-26 09:47:14 +00:00
Gerard Olenski
8b3fbdfec1 PRODSEC-9936 Bump spring-security to 6.3.7 (#3223) 2025-02-26 08:26:16 +01:00
alfresco-build
5d847fe5f9 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-25 11:02:11 +00:00
alfresco-build
b3a9633da3 [maven-release-plugin][skip ci] prepare release 25.1.0.57 2025-02-25 11:02:09 +00:00
Giovanni Toraldo
ebdc0b2614 OPSEXP-3032 Bump to latest alfresco-base-tomcat (#3222) 2025-02-25 10:43:29 +01:00
alfresco-build
8fb922a065 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-23 00:07:43 +00:00
alfresco-build
0a9e2e1ce7 [maven-release-plugin][skip ci] prepare release 25.1.0.56 2025-02-23 00:07:41 +00:00
Alfresco CI User
de5bf5a500 [force] Force release for 2025-02-23. 2025-02-23 00:04:35 +00:00
mohit-singh4
ac74222562 [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 21:58:01 +05:30
mohit-singh4
6b959f8901 [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 21:40:46 +05:30
alfresco-build
5112722755 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-19 15:26:53 +00:00
alfresco-build
0835f03ba6 [maven-release-plugin][skip ci] prepare release 25.1.0.55 2025-02-19 15:26:51 +00:00
Damian Ujma
1adddb0f7f ACS-9199 Bump subethasmtp version to 7.1.3 (#3207)
* ACS-9199 Bump subethasmtp to 7.1.3

* ACS-9199 Bump subethasmtp to 7.1.3

* ACS-9199 Use org.eclipse.angus

* ACS-9199 Update notice.txt

* ACS-9199 Remove provided scope for jakarta.mail:mail-api

* ACS-9199 Fix ags

* ACS-9199 Remove verbose
2025-02-19 15:42:14 +01:00
alfresco-build
85c0d7896e [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-19 14:42:02 +00:00
alfresco-build
64b5ca9f2b [maven-release-plugin][skip ci] prepare release 25.1.0.54 2025-02-19 14:42:00 +00:00
Kacper Magdziarz
e85ed14ac8 [ACS-9313] Switch to new tags for tomcat base images in Dockerfiles (#3208) 2025-02-19 14:43:03 +01:00
mohit-singh4
1fac054c08 [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 14:36:12 +05:30
mohit-singh4
eaf18d3b9d [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 14:07:48 +05:30
mohit-singh4
05195d84e7 [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 11:02:56 +05:30
mohit-singh4
2e2b41f879 [fix/MNT-24172-fixRecreationOfRendition2] Test case for recreation of rendition2 2025-02-19 11:01:11 +05:30
mohit-singh4
cf0463a24d [fix/MNT-24172-fixRecreationOfRendition2] Test case for Recreation of Rendition2 2025-02-19 08:56:21 +05:30
alfresco-build
48d391d250 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-17 13:00:19 +00:00
alfresco-build
df2c21dfef [maven-release-plugin][skip ci] prepare release 25.1.0.53 2025-02-17 13:00:17 +00:00
Kacper Magdziarz
b0a5d484b6 [ACS-9270] Switch MySQL driver from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver (#3204) 2025-02-17 12:58:42 +01:00
mohit-singh4
ed80663a07 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-17 14:49:10 +05:30
alfresco-build
798ca41d63 [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-17 08:55:52 +00:00
alfresco-build
7b8576c403 [maven-release-plugin][skip ci] prepare release 25.1.0.52 2025-02-17 08:55:50 +00:00
mohit-singh4
31343c5177 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-17 13:55:11 +05:30
Gerard Olenski
75d5201af1 ACS 9256 improve async tests stability (#3191)
* ACS-9256 Improved stability in DynamicallySizedThreadPoolExecutorTest

* ACS-9256 Removed unused unstable test in SpringAwareUserTransactionTest

* ACS-9256 Improved stability in DynamicallySizedThreadPoolExecutorTest

* ACS-9256 Improved stability in ActionServiceImplTest and RuleServiceCoverageTest

* ACS-9256 Improved stability in ActionTrackingServiceImplTest

* ACS-9256 Improved performance in ComparePropertyValueEvaluatorTest

* ACS-9256 Improved performance in LockServiceImplTest

* ACS-9256 Improved stability in LockBehaviourImplTest

* ACS-9256 Improved stability in ContentMetadataExtracterTest

* ACS-9256 Removed unstable and unused tests

* ACS-9256 Improve stability in CachedContentCleanupJobTest

* ACS-9256 Pre-commit fixes
2025-02-17 08:58:04 +01:00
mohit-singh4
f3492d16cf [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-17 09:52:22 +05:30
alfresco-build
9e5a030b6f [maven-release-plugin][skip ci] prepare for next development iteration 2025-02-16 00:07:50 +00:00
mohit-singh4
5fb5e19434 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-13 12:27:00 +05:30
mohit-singh4
49d346a5c4 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-13 11:41:17 +05:30
mohit-singh4
ae699b37d0 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-13 09:20:41 +05:30
mohit-singh4
cc078037f7 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-13 08:49:25 +05:30
mohit-singh4
9b7eb95463 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-12 14:42:32 +05:30
mohit-singh4
5e560213bb [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-12 13:57:03 +05:30
mohit-singh4
a1d8aa7b48 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-12 13:32:12 +05:30
mohit-singh4
b7e1daaac9 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-12 13:27:24 +05:30
mohit-singh4
d70295a8de [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-12 12:47:54 +05:30
mohit-singh4
082770d73d [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-10 12:46:26 +05:30
mohit-singh4
2f81d382fd Merge branch 'master' of github.com:Alfresco/alfresco-community-repo into fix/MNT-24172-fixRecreationOfRendition2 2025-02-10 11:49:55 +05:30
mohit-singh4
70438d4a51 [fix/MNT-24172-fixRecreationOfRendition2] Test Case for recreation of Rendition2 2025-02-10 11:47:48 +05:30
mohit-singh4
91aaee9f78 Merge branch 'master' of github.com:Alfresco/alfresco-community-repo into fix/MNT-24172-fixRecreationOfRendition2 2025-02-07 10:43:55 +05:30
mohit-singh4
d46162de7a [fix/MNT-24172-fixRecreationOfRendition2] Fix for recreation of rendition2 along with PR changes 2025-01-30 10:49:03 +05:30
mohit-singh4
ba0c9e471a Merge branch 'master' of github.com:Alfresco/alfresco-community-repo into fix/MNT-24172-fixRecreationOfRendition2 2025-01-30 10:11:33 +05:30
mohit-singh4
40deb11173 [fix/MNT-24172-fixRecreationOfRendition2] fix for recreation of rendition2 2025-01-16 23:56:56 +05:30
48 changed files with 11176 additions and 11702 deletions

View File

@@ -515,7 +515,7 @@ jobs:
RP_OPTS: ${{ github.ref_name == 'master' && steps.rp-prepare.outputs.mvn-opts || '' }}
run: |
eval "args=($RP_OPTS)"
mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=com.mysql.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco "${args[@]}"
mvn -B test -pl repository -am -Dtest=AllDBTestsTestSuite -DfailIfNoTests=false -Ddb.driver=com.mysql.cj.jdbc.Driver -Ddb.name=alfresco -Ddb.url=jdbc:mysql://localhost:3307/alfresco -Ddb.username=alfresco -Ddb.password=alfresco "${args[@]}"
continue-on-error: true
- name: "Update GitHub Step Summary"
if: github.ref_name == 'master'

View File

@@ -1377,7 +1377,7 @@
"filename": "repository/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java",
"hashed_secret": "d033e22ae348aeb5660fc2140aec35850c4da997",
"is_verified": false,
"line_number": 118,
"line_number": 116,
"is_secret": false
}
],
@@ -1431,26 +1431,6 @@
"is_secret": false
}
],
"repository/src/test/java/org/alfresco/repo/lock/LockBehaviourImplTest.java": [
{
"type": "Secret Keyword",
"filename": "repository/src/test/java/org/alfresco/repo/lock/LockBehaviourImplTest.java",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 112,
"is_secret": false
}
],
"repository/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java": [
{
"type": "Secret Keyword",
"filename": "repository/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 103,
"is_secret": false
}
],
"repository/src/test/java/org/alfresco/repo/management/JmxDumpUtilTest.java": [
{
"type": "Secret Keyword",
@@ -1888,5 +1868,5 @@
}
]
},
"generated_at": "2024-12-19T08:58:42Z"
"generated_at": "2025-02-26T15:13:52Z"
}

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -1,3 +1,3 @@
SOLR6_TAG=2.0.14
SOLR6_TAG=2.0.15-A.1
POSTGRES_TAG=16.6
ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -23,10 +23,6 @@ function runAction(p_params)
if (p_params.destNode.hasAspect("cm:lockable") && !p_params.destNode.hasAspect("trx:transferred"))
{
p_params.destNode.unlock();
if(p_params.destNode.hasAspect("gd2:editingInGoogle"))
{
p_params.destNode.removeAspect("gd2:editingInGoogle");
}
}
var resultId = originalDoc.name,

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<dependencies>
@@ -145,6 +145,12 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${dependency.awaitility.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
* Copyright (C) 2005-2025 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,6 +18,9 @@
*/
package org.alfresco.util;
import static org.awaitility.Awaitility.await;
import java.time.Duration;
import java.util.Map.Entry;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
@@ -26,20 +29,20 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import junit.framework.TestCase;
/**
* Tests for our instance of {@link java.util.concurrent.ThreadPoolExecutor}
*
*
* @author Nick Burch
*/
public class DynamicallySizedThreadPoolExecutorTest extends TestCase
{
private static Log logger = LogFactory.getLog(DynamicallySizedThreadPoolExecutorTest.class);
private static final Duration MAX_WAIT_TIMEOUT = Duration.ofSeconds(1);
private static final Log logger = LogFactory.getLog(DynamicallySizedThreadPoolExecutorTest.class);
private static final int DEFAULT_KEEP_ALIVE_TIME = 90;
@Override
@@ -48,9 +51,9 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
SleepUntilAllWake.reset();
}
public void testUpToCore() throws Exception
public void testUpToCore()
{
DynamicallySizedThreadPoolExecutor exec = createInstance(5,10, DEFAULT_KEEP_ALIVE_TIME);
DynamicallySizedThreadPoolExecutor exec = createInstance(5, 10, DEFAULT_KEEP_ALIVE_TIME);
assertEquals(0, exec.getPoolSize());
exec.execute(new SleepUntilAllWake());
@@ -61,15 +64,15 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
assertEquals(4, exec.getPoolSize());
exec.execute(new SleepUntilAllWake());
assertEquals(5, exec.getPoolSize());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
waitForPoolSizeEquals(exec, 5);
assertEquals(5, exec.getPoolSize());
}
public void testPastCoreButNotHugeQueue() throws Exception
public void testPastCoreButNotHugeQueue()
{
DynamicallySizedThreadPoolExecutor exec = createInstance(5,10, DEFAULT_KEEP_ALIVE_TIME);
DynamicallySizedThreadPoolExecutor exec = createInstance(5, 10, DEFAULT_KEEP_ALIVE_TIME);
assertEquals(0, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
@@ -80,7 +83,7 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
exec.execute(new SleepUntilAllWake());
assertEquals(5, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
// Need to hit max pool size before it adds more
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
@@ -89,20 +92,20 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
exec.execute(new SleepUntilAllWake());
assertEquals(5, exec.getPoolSize());
assertEquals(5, exec.getQueue().size());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(5, exec.getPoolSize());
assertEquals(7, exec.getQueue().size());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
waitForPoolSizeEquals(exec, 5);
assertEquals(5, exec.getPoolSize());
}
public void testToExpandQueue() throws Exception
{
DynamicallySizedThreadPoolExecutor exec = createInstance(2,4,1);
DynamicallySizedThreadPoolExecutor exec = createInstance(2, 4, 5);
assertEquals(0, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
@@ -110,166 +113,37 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
exec.execute(new SleepUntilAllWake());
assertEquals(2, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(2, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// Next should add one
exec.execute(new SleepUntilAllWake());
Thread.sleep(20); // Let the new thread spin up
waitForPoolSizeEquals(exec, 3); // Let the new thread spin up
assertEquals(3, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// And again
exec.execute(new SleepUntilAllWake());
Thread.sleep(20); // Let the new thread spin up
waitForPoolSizeEquals(exec, 4); // Let the new thread spin up
assertEquals(4, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// But no more will be added, as we're at max
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(4, exec.getPoolSize());
assertEquals(6, exec.getQueue().size());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
// All threads still running, as 1 second timeout
assertEquals(4, exec.getPoolSize());
}
public void offTestToExpandThenContract() throws Exception
{
DynamicallySizedThreadPoolExecutor exec = createInstance(2,4,1);
exec.setKeepAliveTime(30, TimeUnit.MILLISECONDS);
assertEquals(0, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(2, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(2, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// Next should add one
exec.execute(new SleepUntilAllWake());
Thread.sleep(20); // Let the new thread spin up
assertEquals(3, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
// And again
exec.execute(new SleepUntilAllWake());
Thread.sleep(20); // Let the new thread spin up
// All threads still running, as 5 second timeout
assertEquals(4, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// But no more will be added, as we're at max
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(4, exec.getPoolSize());
assertEquals(6, exec.getQueue().size());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
// Wait longer than the timeout without any work, which should
// let all the extra threads go away
// (Depending on how closely your JVM follows the specification,
// we may fall back to the core size which is correct, or we
// may go to zero which is wrong, but hey, it's the JVM...)
logger.debug("Core pool size is " + exec.getCorePoolSize());
logger.debug("Current pool size is " + exec.getPoolSize());
logger.debug("Queue size is " + exec.getQueue().size());
assertTrue(
"Pool size should be 0-2 as everything is idle, was " + exec.getPoolSize(),
exec.getPoolSize() >= 0
);
assertTrue(
"Pool size should be 0-2 as everything is idle, was " + exec.getPoolSize(),
exec.getPoolSize() <= 2
);
SleepUntilAllWake.reset();
// Add 2 new jobs, will stay/ go to at 2 threads
assertEquals(0, exec.getQueue().size());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
// Let the idle threads grab them, then check
Thread.sleep(20);
assertEquals(2, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
// 3 more, still at 2 threads
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
assertEquals(2, exec.getPoolSize());
assertEquals(3, exec.getQueue().size());
// And again wait for it all
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
assertEquals(2, exec.getPoolSize());
// Now decrease the overall pool size
// Will rise and fall to there now
exec.setCorePoolSize(1);
// Run a quick job, to ensure that the
// "can I kill one yet" logic is applied
SleepUntilAllWake.reset();
exec.execute(new SleepUntilAllWake());
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
assertEquals(1, exec.getPoolSize());
assertEquals(0, exec.getQueue().size());
SleepUntilAllWake.reset();
// Push enough on to go up to 4 active threads
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
exec.execute(new SleepUntilAllWake());
Thread.sleep(20); // Let the new threads spin up
assertEquals(4, exec.getPoolSize());
assertEquals(6, exec.getQueue().size());
// Wait for them all to finish, should drop back to 1 now
// (Or zero, if your JVM can't read the specification...)
SleepUntilAllWake.wakeAll();
Thread.sleep(100);
assertTrue(
"Pool size should be 0 or 1 as everything is idle, was " + exec.getPoolSize(),
exec.getPoolSize() >= 0
);
assertTrue(
"Pool size should be 0 or 1 as everything is idle, was " + exec.getPoolSize(),
exec.getPoolSize() <= 1
);
}
private DynamicallySizedThreadPoolExecutor createInstance(int corePoolSize, int maximumPoolSize, int keepAliveTime)
@@ -291,6 +165,11 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
new ThreadPoolExecutor.CallerRunsPolicy());
}
private void waitForPoolSizeEquals(DynamicallySizedThreadPoolExecutor exec, int expectedSize)
{
await().atMost(MAX_WAIT_TIMEOUT).until(() -> exec.getPoolSize() == expectedSize);
}
public static class SleepUntilAllWake implements Runnable
{
private static ConcurrentMap<String, Thread> sleeping = new ConcurrentHashMap<String, Thread>();
@@ -299,31 +178,33 @@ public class DynamicallySizedThreadPoolExecutorTest extends TestCase
@Override
public void run()
{
if(allAwake) return;
if (allAwake)
return;
// Track us, and wait for the bang
logger.debug("Adding thread: " + Thread.currentThread().getName());
sleeping.put(Thread.currentThread().getName(), Thread.currentThread());
try
{
Thread.sleep(30*1000);
Thread.sleep(30 * 1000);
System.err.println("Warning - Thread finished sleeping without wake!");
}
catch(InterruptedException e)
catch (InterruptedException e)
{
logger.debug("Interrupted thread: " + Thread.currentThread().getName());
}
}
public static void wakeAll()
{
allAwake = true;
for(Entry<String, Thread> t : sleeping.entrySet())
for (Entry<String, Thread> t : sleeping.entrySet())
{
logger.debug("Interrupting thread: " + t.getKey());
t.getValue().interrupt();
}
}
public static void reset()
{
logger.debug("Resetting.");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2023 Alfresco Software Limited.
* Copyright (C) 2005-2025 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -20,13 +20,11 @@ package org.alfresco.util.transaction;
import java.util.NoSuchElementException;
import java.util.Objects;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.UserTransaction;
import junit.framework.TestCase;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.NoTransactionException;
import org.springframework.transaction.TransactionDefinition;
@@ -35,21 +33,20 @@ import org.springframework.transaction.support.AbstractPlatformTransactionManage
import org.springframework.transaction.support.DefaultTransactionStatus;
/**
* @see org.alfresco.util.transaction.SpringAwareUserTransaction
*
* @author Derek Hulley
* @see org.alfresco.util.transaction.SpringAwareUserTransaction
*/
public class SpringAwareUserTransactionTest extends TestCase
{
private DummyTransactionManager transactionManager;
private FailingTransactionManager failingTransactionManager;
private UserTransaction txn;
public SpringAwareUserTransactionTest()
{
super();
}
@Override
protected void setUp() throws Exception
{
@@ -57,7 +54,7 @@ public class SpringAwareUserTransactionTest extends TestCase
failingTransactionManager = new FailingTransactionManager();
txn = getTxn();
}
private UserTransaction getTxn()
{
return new SpringAwareUserTransaction(
@@ -67,13 +64,13 @@ public class SpringAwareUserTransactionTest extends TestCase
TransactionDefinition.PROPAGATION_REQUIRED,
TransactionDefinition.TIMEOUT_DEFAULT);
}
public void testSetUp() throws Exception
{
assertNotNull(transactionManager);
assertNotNull(txn);
}
private void checkNoStatusOnThread()
{
try
@@ -86,7 +83,7 @@ public class SpringAwareUserTransactionTest extends TestCase
// expected
}
}
public void testNoTxnStatus() throws Exception
{
checkNoStatusOnThread();
@@ -134,7 +131,7 @@ public class SpringAwareUserTransactionTest extends TestCase
}
checkNoStatusOnThread();
}
public void testSimpleTxnWithRollback() throws Exception
{
testNoTxnStatus();
@@ -156,7 +153,7 @@ public class SpringAwareUserTransactionTest extends TestCase
transactionManager.getStatus());
checkNoStatusOnThread();
}
public void testNoBeginCommit() throws Exception
{
testNoTxnStatus();
@@ -171,7 +168,7 @@ public class SpringAwareUserTransactionTest extends TestCase
}
checkNoStatusOnThread();
}
public void testPostRollbackCommitDetection() throws Exception
{
testNoTxnStatus();
@@ -189,7 +186,7 @@ public class SpringAwareUserTransactionTest extends TestCase
}
checkNoStatusOnThread();
}
public void testPostSetRollbackOnlyCommitDetection() throws Exception
{
testNoTxnStatus();
@@ -208,7 +205,7 @@ public class SpringAwareUserTransactionTest extends TestCase
}
checkNoStatusOnThread();
}
public void testMismatchedBeginCommit() throws Exception
{
UserTransaction txn1 = getTxn();
@@ -218,18 +215,18 @@ public class SpringAwareUserTransactionTest extends TestCase
txn1.begin();
txn2.begin();
txn2.commit();
txn1.commit();
checkNoStatusOnThread();
txn1 = getTxn();
txn2 = getTxn();
txn1.begin();
txn2.begin();
try
{
txn1.commit();
@@ -245,58 +242,6 @@ public class SpringAwareUserTransactionTest extends TestCase
checkNoStatusOnThread();
}
/**
* Test for leaked transactions (no guarantee it will succeed due to reliance
* on garbage collector), so disabled by default.
*
* Also, if it succeeds, transaction call stack tracing will be enabled
* potentially hitting the performance of all subsequent tests.
*
* @throws Exception
*/
public void xtestLeakedTransactionLogging() throws Exception
{
assertFalse(SpringAwareUserTransaction.isCallStackTraced());
TrxThread t1 = new TrxThread();
t1.start();
System.gc();
Thread.sleep(1000);
TrxThread t2 = new TrxThread();
t2.start();
System.gc();
Thread.sleep(1000);
assertTrue(SpringAwareUserTransaction.isCallStackTraced());
TrxThread t3 = new TrxThread();
t3.start();
System.gc();
Thread.sleep(3000);
System.gc();
Thread.sleep(3000);
}
private class TrxThread extends Thread
{
public void run()
{
try
{
getTrx();
}
catch (Exception e) {}
}
public void getTrx() throws Exception
{
UserTransaction txn = getTxn();
txn.begin();
txn = null;
}
}
public void testConnectionPoolException() throws Exception
{
testNoTxnStatus();
@@ -311,7 +256,7 @@ public class SpringAwareUserTransactionTest extends TestCase
// Expected fail
}
}
private UserTransaction getFailingTxn()
{
return new SpringAwareUserTransaction(
@@ -321,7 +266,7 @@ public class SpringAwareUserTransactionTest extends TestCase
TransactionDefinition.PROPAGATION_REQUIRED,
TransactionDefinition.TIMEOUT_DEFAULT);
}
public void testTransactionListenerOrder() throws Throwable
{
testNoTxnStatus();
@@ -360,12 +305,12 @@ public class SpringAwareUserTransactionTest extends TestCase
}
checkNoStatusOnThread();
}
private static class TestTransactionListener extends TransactionListenerAdapter
{
private final String name;
private final StringBuffer buffer;
public TestTransactionListener(String name, StringBuffer buffer)
{
Objects.requireNonNull(name);
@@ -373,18 +318,18 @@ public class SpringAwareUserTransactionTest extends TestCase
this.name = name;
this.buffer = buffer;
}
@Override
public void beforeCommit(boolean readOnly)
{
buffer.append(name);
}
public String getName()
{
return name;
}
@Override
public boolean equals(Object obj)
{
@@ -394,17 +339,17 @@ public class SpringAwareUserTransactionTest extends TestCase
}
return false;
}
@Override
public int hashCode()
{
return name.hashCode();
}
}
/**
* Used to check that the transaction manager is being called correctly
*
*
* @author Derek Hulley
*/
@SuppressWarnings("serial")
@@ -412,7 +357,7 @@ public class SpringAwareUserTransactionTest extends TestCase
{
private int status = Status.STATUS_NO_TRANSACTION;
private Object txn = new Object();
/**
* @return Returns one of the {@link Status Status.STATUS_XXX} constants
*/
@@ -441,10 +386,10 @@ public class SpringAwareUserTransactionTest extends TestCase
status = Status.STATUS_ROLLEDBACK;
}
}
/**
* Throws {@link NoSuchElementException} on begin()
*
*
* @author alex.mukha
*/
private static class FailingTransactionManager extends AbstractPlatformTransactionManager
@@ -452,7 +397,7 @@ public class SpringAwareUserTransactionTest extends TestCase
private static final long serialVersionUID = 1L;
private int status = Status.STATUS_NO_TRANSACTION;
private Object txn = new Object();
/**
* @return Returns one of the {@link Status Status.STATUS_XXX} constants
*/

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -9,6 +9,6 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
</project>

View File

@@ -1,5 +1,5 @@
# More infos about this image: https://github.com/Alfresco/alfresco-docker-base-tomcat
FROM alfresco/alfresco-base-tomcat:tomcat10-jre17-rockylinux9@sha256:395664f9d9be0c9f73d3b722a58fd559ee7231609b263dfe19502617652740e3
FROM alfresco/alfresco-base-tomcat:tomcat10-jre17-rockylinux9@sha256:9622418e142fb4fe1c5320666ad61ea292bc5c98f3dd0b550b6add33d18f659f
# Set default docker_context.
ARG resource_path=target

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -1,3 +1,3 @@
SOLR6_TAG=2.0.14
SOLR6_TAG=2.0.15-A.1
POSTGRES_TAG=16.6
ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<organization>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<properties>

14
pom.xml
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>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Alfresco Community Repo Parent</name>
@@ -51,14 +51,14 @@
<dependency.alfresco-server-root.version>7.0.1</dependency.alfresco-server-root.version>
<dependency.activiti-engine.version>5.23.0</dependency.activiti-engine.version>
<dependency.activiti.version>5.23.0</dependency.activiti.version>
<dependency.alfresco-transform-core.version>5.1.6</dependency.alfresco-transform-core.version>
<dependency.alfresco-transform-service.version>4.1.6</dependency.alfresco-transform-service.version>
<dependency.alfresco-transform-core.version>5.1.7-A.4</dependency.alfresco-transform-core.version>
<dependency.alfresco-transform-service.version>4.1.7-A.1</dependency.alfresco-transform-service.version>
<dependency.alfresco-greenmail.version>7.1</dependency.alfresco-greenmail.version>
<dependency.acs-event-model.version>1.0.2</dependency.acs-event-model.version>
<dependency.aspectj.version>1.9.22.1</dependency.aspectj.version>
<dependency.spring.version>6.2.2</dependency.spring.version>
<dependency.spring-security.version>6.3.4</dependency.spring-security.version>
<dependency.spring-security.version>6.3.7</dependency.spring-security.version>
<dependency.antlr.version>3.5.3</dependency.antlr.version>
<dependency.jackson.version>2.17.2</dependency.jackson.version>
<dependency.cxf.version>4.1.0</dependency.cxf.version>
@@ -86,7 +86,7 @@
<dependency.poi.version>5.3.0</dependency.poi.version>
<dependency.jboss.logging.version>3.5.0.Final</dependency.jboss.logging.version>
<dependency.camel.version>4.6.0</dependency.camel.version> <!-- when bumping this version, please keep track/sync with included netty.io dependencies -->
<dependency.netty.version>4.1.117.Final</dependency.netty.version> <!-- must be in sync with camels transitive dependencies, e.g.: netty-common -->
<dependency.netty.version>4.1.118.Final</dependency.netty.version> <!-- must be in sync with camels transitive dependencies, e.g.: netty-common -->
<dependency.activemq.version>5.18.6</dependency.activemq.version>
<dependency.apache-compress.version>1.27.1</dependency.apache-compress.version>
<dependency.awaitility.version>4.2.2</dependency.awaitility.version>
@@ -112,7 +112,7 @@
<dependency.jakarta-ee-json-api.version>2.1.3</dependency.jakarta-ee-json-api.version>
<dependency.jakarta-ee-json-impl.version>1.1.7</dependency.jakarta-ee-json-impl.version>
<dependency.jakarta-json-path.version>2.9.0</dependency.jakarta-json-path.version>
<dependency.json-smart.version>2.5.1</dependency.json-smart.version>
<dependency.json-smart.version>2.5.2</dependency.json-smart.version>
<alfresco.googledrive.version>4.1.0</alfresco.googledrive.version>
<alfresco.aos-module.version>3.2.0</alfresco.aos-module.version>
<alfresco.api-explorer.version>25.1.0-A1</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share -->
@@ -155,7 +155,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>25.1.0.51</tag>
<tag>HEAD</tag>
</scm>
<distributionManagement>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -26,17 +26,38 @@
package org.alfresco.rest.api.tests;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.google.common.collect.Ordering;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
import org.alfresco.repo.rendition2.RenditionService2Impl;
import org.alfresco.repo.rendition2.SynchronousTransformClient;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.nodes.NodesEntityResource;
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
@@ -54,23 +75,11 @@ import org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData;
import org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.util.TempFileProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* V1 REST API tests for Renditions
@@ -93,17 +102,20 @@ public class RenditionsTest extends AbstractBaseApiTest
* Private site of user one from network one
*/
private Site userOneN1Site;
private final static long DELAY_IN_MS = 500;
protected static ContentService contentService;
private static SynchronousTransformClient synchronousTransformClient;
private RetryingTransactionHelper transactionHelper;
@Before
public void setup() throws Exception
{
contentService = applicationContext.getBean("contentService", ContentService.class);
synchronousTransformClient = applicationContext.getBean("synchronousTransformClient", SynchronousTransformClient.class);
transactionHelper = (RetryingTransactionHelper) this.applicationContext
.getBean("retryingTransactionHelper");
networkN1 = repoService.createNetworkWithAlias("ping", true);
networkN1.create();
userOneN1 = networkN1.createUser();
@@ -123,14 +135,16 @@ public class RenditionsTest extends AbstractBaseApiTest
/**
* Tests get node renditions.
* <p>GET:</p>
* <p>
* GET:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions}
*/
@Test
public void testListNodeRenditions() throws Exception
{
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -263,14 +277,16 @@ public class RenditionsTest extends AbstractBaseApiTest
/**
* Tests get node rendition.
* <p>GET:</p>
* <p>
* GET:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions/<renditionId>}
*/
@Test
public void testGetNodeRendition() throws Exception
{
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -331,8 +347,8 @@ public class RenditionsTest extends AbstractBaseApiTest
String jpgFileName = "quick.jpg";
File jpgFile = getResourceFile(fileName);
reqBody = MultiPartBuilder.create()
.setFileData(new FileData(jpgFileName, jpgFile))
.build();
.setFileData(new FileData(jpgFileName, jpgFile))
.build();
// Upload quick.jpg file into 'folder'
response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
@@ -352,14 +368,16 @@ public class RenditionsTest extends AbstractBaseApiTest
/**
* Tests create rendition.
* <p>POST:</p>
* <p>
* POST:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions}
*/
@Test
public void testCreateRendition() throws Exception
{
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -411,24 +429,24 @@ public class RenditionsTest extends AbstractBaseApiTest
if (areLocalTransformsAvailable())
{
// Create a node without any content
String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId());
post(getNodeRenditionsUrl(emptyContentNodeId), toJsonAsString(renditionRequest), 202);
// Create a node without any content
String emptyContentNodeId = addToDocumentLibrary(userOneN1Site, "emptyDoc.txt", TYPE_CM_CONTENT, userOneN1.getId());
post(getNodeRenditionsUrl(emptyContentNodeId), toJsonAsString(renditionRequest), 202);
// Rendition for binary content
String content = "The quick brown fox jumps over the lazy dog.";
file = TempFileProvider.createTempFile(new ByteArrayInputStream(content.getBytes()), getClass().getSimpleName(), ".bin");
multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData("binaryFileName", file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document binaryDocument = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
post(getNodeRenditionsUrl(binaryDocument.getId()), toJsonAsString(renditionRequest), 202);
// Rendition for binary content
String content = "The quick brown fox jumps over the lazy dog.";
file = TempFileProvider.createTempFile(new ByteArrayInputStream(content.getBytes()), getClass().getSimpleName(), ".bin");
multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData("binaryFileName", file));
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document binaryDocument = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
post(getNodeRenditionsUrl(binaryDocument.getId()), toJsonAsString(renditionRequest), 202);
}
//
// -ve Tests
//
// The rendition requested already exists
response = post(getNodeRenditionsUrl(contentNodeId), toJsonAsString(new Rendition().setId("imgpreview")), 409);
ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
@@ -563,7 +581,9 @@ public class RenditionsTest extends AbstractBaseApiTest
/**
* Tests create rendition when on upload/create of a file
*
* <p>POST:</p>
* <p>
* POST:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
@@ -619,25 +639,11 @@ public class RenditionsTest extends AbstractBaseApiTest
assertRenditionCreatedWithWait(contentNodeId, renditionName);
}
/* RA-834: commented-out since not currently applicable for empty file
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType("cm:content");
ContentInfo ci = new ContentInfo();
ci.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
d1.setContent(ci);
// create empty file including request to generate a thumbnail
renditionName = "doclib";
response = post(getNodeChildrenUrl(folder_Id), userId, toJsonAsStringNonNull(d1), "?renditions="+renditionName, 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String d1Id = documentResp.getId();
// wait and check that rendition is created ...
rendition = waitAndGetRendition(userId, d1Id, renditionName);
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
*/
/* RA-834: commented-out since not currently applicable for empty file Document d1 = new Document(); d1.setName("d1.txt"); d1.setNodeType("cm:content"); ContentInfo ci = new ContentInfo(); ci.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN); d1.setContent(ci);
*
* // create empty file including request to generate a thumbnail renditionName = "doclib"; response = post(getNodeChildrenUrl(folder_Id), userId, toJsonAsStringNonNull(d1), "?renditions="+renditionName, 201); Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class); String d1Id = documentResp.getId();
*
* // wait and check that rendition is created ... rendition = waitAndGetRendition(userId, d1Id, renditionName); assertNotNull(rendition); assertEquals(RenditionStatus.CREATED, rendition.getStatus()); */
// Multiple renditions requested
reqBody = MultiPartBuilder.create()
@@ -694,9 +700,9 @@ public class RenditionsTest extends AbstractBaseApiTest
public void testCreateRenditionForNewVersion() throws Exception
{
String PROP_LTM = "cm:lastThumbnailModification";
String RENDITION_NAME = "imgpreview";
String userId = userOneN1.getId();
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
@@ -718,7 +724,7 @@ public class RenditionsTest extends AbstractBaseApiTest
String contentNodeId = document1.getId();
assertNotNull(document1.getProperties());
assertNull(document1.getProperties().get(PROP_LTM));
// pause briefly
Thread.sleep(DELAY_IN_MS);
@@ -730,8 +736,8 @@ public class RenditionsTest extends AbstractBaseApiTest
params = new HashMap<>();
params.put("placeholder", "false");
getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME+"/content"), params, 404);
getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 404);
// TODO add test to request creation of rendition as another user (that has read-only access on the content, not write)
// Create and get 'imgpreview' rendition
@@ -747,24 +753,24 @@ public class RenditionsTest extends AbstractBaseApiTest
params = new HashMap<>();
params.put("placeholder", "false");
response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME+"/content"), params, 200);
response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 200);
byte[] renditionBytes1 = response.getResponseAsBytes();
assertNotNull(renditionBytes1);
// check node details ...
params = Collections.singletonMap("include", "properties");
response = getSingle(NodesEntityResource.class, contentNodeId, params, 200);
Document document1b = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// assertEquals(document1b.getModifiedAt(), document1.getModifiedAt());
// assertEquals(document1b.getModifiedAt(), document1.getModifiedAt());
assertEquals(document1b.getModifiedByUser().getId(), document1.getModifiedByUser().getId());
assertEquals(document1b.getModifiedByUser().getDisplayName(), document1.getModifiedByUser().getDisplayName());
assertNotEquals(document1b.getProperties().get(PROP_LTM), document1.getProperties().get(PROP_LTM));
// upload another version of "quick.pdf" and check again
fileName = "quick-2.pdf";
file = getResourceFile(fileName);
reqBody = MultiPartBuilder.create()
@@ -781,9 +787,9 @@ public class RenditionsTest extends AbstractBaseApiTest
params = new HashMap<>();
params.put("placeholder", "false");
response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME+"/content"), params, 200);
response = getSingle(getNodeRenditionsUrl(contentNodeId), (RENDITION_NAME + "/content"), params, 200);
assertNotNull(response.getResponseAsBytes());
// check rendition binary has changed
assertNotEquals(renditionBytes1, response.getResponseAsBytes());
@@ -792,24 +798,26 @@ public class RenditionsTest extends AbstractBaseApiTest
response = getSingle(NodesEntityResource.class, contentNodeId, params, 200);
Document document2b = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// assertTrue(document2b.getModifiedAt().after(document1.getModifiedAt()));
// assertTrue(document2b.getModifiedAt().after(document1.getModifiedAt()));
assertEquals(document2b.getModifiedByUser().getId(), document1.getModifiedByUser().getId());
assertEquals(document2b.getModifiedByUser().getDisplayName(), document1.getModifiedByUser().getDisplayName());
// check last thumbnail modification property has changed ! (REPO-1644)
assertNotEquals(document2b.getProperties().get(PROP_LTM), document1b.getProperties().get(PROP_LTM));
}
/**
* Tests download rendition.
* <p>GET:</p>
* <p>
* GET:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions/<renditionId>/content}
*/
@Test
public void testDownloadRendition() throws Exception
{
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
@@ -818,7 +826,7 @@ public class RenditionsTest extends AbstractBaseApiTest
String fileName = "quick.pdf";
File file = getResourceFile(fileName);
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file));
.setFileData(new FileData(fileName, file));
MultiPartRequest reqBody = multiPartBuilder.build();
// Upload quick.pdf file into 'folder'
@@ -928,8 +936,8 @@ public class RenditionsTest extends AbstractBaseApiTest
// the old fileName and setting overwrite field to true
file = getResourceFile("quick-2.pdf");
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file))
.setOverwrite(true);
.setFileData(new FileData(fileName, file))
.setOverwrite(true);
reqBody = multiPartBuilder.build();
// Update quick.pdf
@@ -937,7 +945,7 @@ public class RenditionsTest extends AbstractBaseApiTest
// The requested "If-Modified-Since" date is older than rendition modified date
response = getSingleWithDelayRetry(getNodeRenditionsUrl(contentNodeId), "doclib/content", params, headers, MAX_RETRY,
PAUSE_TIME, 200);
PAUSE_TIME, 200);
assertNotNull(response);
responseHeaders = response.getHeaders();
assertNotNull(responseHeaders);
@@ -945,7 +953,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertNotNull(newLastModifiedHeader);
assertNotEquals(lastModifiedHeader, newLastModifiedHeader);
//-ve tests
// -ve tests
// nodeId in the path parameter does not represent a file
getSingle(getNodeRenditionsUrl(folder_Id), "doclib/content", 400);
@@ -958,8 +966,8 @@ public class RenditionsTest extends AbstractBaseApiTest
InputStream inputStream = new ByteArrayInputStream("The quick brown fox jumps over the lazy dog".getBytes());
file = TempFileProvider.createTempFile(inputStream, "RenditionsTest-", ".abcdef");
reqBody = MultiPartBuilder.create()
.setFileData(new FileData(file.getName(), file))
.build();
.setFileData(new FileData(file.getName(), file))
.build();
// Upload temp file into 'folder'
response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
@@ -981,6 +989,72 @@ public class RenditionsTest extends AbstractBaseApiTest
getSingle(getNodeRenditionsUrl(emptyContentNodeId), "doclib/content", params, 200);
}
/**
* Test recreation of rendition2 aspect.
* <p>
* POST:
* </p>
* <p>
* DELETE:
* </p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions} {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions/{renditionID}
*/
@Test
public void testRecreationOfRendition2() throws Exception
{
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folderId = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userOneN1.getId());
// Create multipart request.
String renditionName = "pdf";
String fileName = "quick.pdf";
File file = getResourceFile(fileName);
MultiPartRequest reqBody = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file))
.setRenditions(Collections.singletonList(renditionName))
.build();
// Upload quick.pdf file into 'folder'
HttpResponse response = post(getNodeChildrenUrl(folderId), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String contentNodeId = document.getId();
// wait and check that rendition is created ...
Rendition rendition = waitAndGetRendition(contentNodeId, null, renditionName);
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
Thread.sleep(DELAY_IN_MS);
delete(getNodeRenditionIdUrl(contentNodeId, renditionName), null, null, null, null, 204);
// retry to double-check deletion
delete(getNodeRenditionIdUrl(contentNodeId, renditionName), null, null, null, null, 404);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class);
SWFTransformationOptions swfTransformationOptions = new SWFTransformationOptions();
swfTransformationOptions.setUse("pdf");
NodeRef thumbNode = transactionHelper
.doInTransaction(
() -> thumbnailService.createThumbnail(getFolderNodeRef(contentNodeId), ContentModel.PROP_CONTENT,
MimetypeMap.MIMETYPE_PDF, swfTransformationOptions, "pdf"));
assertNotNull(thumbNode);
assertNotEquals("Both, we are getting same rendition Id's", rendition.getId(), thumbNode.getId());
}
private NodeRef getFolderNodeRef(String folderId)
{
return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderId);
}
private String addToDocumentLibrary(Site testSite, String name, String nodeType, String userId) throws Exception
{
String parentId = getSiteContainerNodeId(testSite.getId(), "documentLibrary");

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.51</version>
<version>25.1.0.68-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -57,7 +57,7 @@ public class NodeSizeDetailsServiceImpl implements NodeSizeDetailsService, Initi
{
private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsServiceImpl.class);
private static final String FIELD_FACET = "content.size";
private static final String FACET_QUERY = "{!afts}content.size:[0 TO " + Integer.MAX_VALUE + "]";
private static final String FACET_QUERY = "{!afts key='extra large'}content.size:[0 TO " + Integer.MAX_VALUE + "]";
private SearchService searchService;
private SimpleCache<Serializable, NodeSizeDetails> simpleCache;
private TransactionService transactionService;

View File

@@ -28,11 +28,17 @@ package org.alfresco.repo.workflow.activiti.script;
import java.util.Map;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.delegate.VariableScope;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.el.Expression;
import org.activiti.engine.impl.persistence.entity.DeploymentEntity;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.repository.ProcessDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.workflow.WorkflowDeployer;
@@ -45,13 +51,12 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowException;
/**
* Base class for execution scripts, using {@link ScriptService} as part of
* activiti workflow.
* Base class for execution scripts, using {@link ScriptService} as part of activiti workflow.
*
* @author Frederik Heremans
* @since 3.4.e
*/
public class ActivitiScriptBase
public class ActivitiScriptBase
{
protected static final String PERSON_BINDING_NAME = "person";
protected static final String USERHOME_BINDING_NAME = "userhome";
@@ -61,17 +66,19 @@ public class ActivitiScriptBase
protected Expression runAs;
protected Expression scriptProcessor;
private static final Logger LOGGER = LoggerFactory.getLogger(ActivitiScriptBase.class);
protected Object executeScript(String theScript, Map<String, Object> model, String scriptProcessorName, String runAsUser)
{
String user = AuthenticationUtil.getFullyAuthenticatedUser();
Object scriptResult = null;
if (runAsUser == null && user != null)
{
// Just execute the script using the current user
scriptResult = executeScript(theScript, model, scriptProcessorName);
}
else
else
{
if (runAsUser != null)
{
@@ -87,26 +94,25 @@ public class ActivitiScriptBase
}
return scriptResult;
}
protected Object executeScriptAsUser(final String theScript, final Map<String, Object> model, final String scriptProcessorName, final String runAsUser)
{
// execute as specified runAsUser
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<>() {
public Object doWork() throws Exception
{
return executeScript(theScript, model, scriptProcessorName);
}
}, runAsUser);
}
protected Object executeScript(String theScript, Map<String, Object> model, String scriptProcessorName)
{
// Execute the script using the appropriate processor
Object scriptResult = null;
// Checks if current workflow is secure
boolean secure = isSecure();
boolean secure = isSecure(model);
if (scriptProcessorName != null)
{
@@ -117,11 +123,11 @@ public class ActivitiScriptBase
// Use default script-processor
scriptResult = getServiceRegistry().getScriptService().executeScriptString(theScript, model, secure);
}
return scriptResult;
}
protected String getStringValue(Expression expression, VariableScope scope)
protected String getStringValue(Expression expression, VariableScope scope)
{
if (expression != null)
{
@@ -133,15 +139,15 @@ public class ActivitiScriptBase
protected ServiceRegistry getServiceRegistry()
{
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null)
if (config != null)
{
// Fetch the registry that is injected in the activiti spring-configuration
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null)
{
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
@@ -149,42 +155,136 @@ public class ActivitiScriptBase
}
/**
* Checks whether the workflow must be considered secure or not - based on {@link DeploymentEntity} category.
* If it is not considered secure, the workflow will be executed in sandbox context with more restrictions
* Checks whether the workflow must be considered secure or not - based on {@link DeploymentEntity} category. If it is not considered secure, the workflow will be executed in sandbox context with more restrictions
*
* @return true if workflow is considered secure, false otherwise
*/
private boolean isSecure()
private boolean isSecure(Map<String, Object> model)
{
String category = getDeploymentCategory(model);
// iF The deployment category matches the condition (either internal or full access) the workflow is considered secure
return category != null && (WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL.equals(category) || WorkflowDeployer.CATEGORY_FULL_ACCESS.equals(category));
}
/**
* Gets the deployment category from the execution context. If no execution context is available, a query to obtain the deployment is performed so the category can be returned.
*
* @param model
* a map with workflow model
* @return the deployment category
*/
private String getDeploymentCategory(Map<String, Object> model)
{
String category = getDeploymentCategoryFromContext();
if (category == null)
{
String deploymentId = null;
String processDefinitionId = null;
if (model != null && model.containsKey(EXECUTION_BINDING_NAME) && model.get(EXECUTION_BINDING_NAME) instanceof ExecutionEntity)
{
ExecutionEntity executionEntity = (ExecutionEntity) model.get(EXECUTION_BINDING_NAME);
deploymentId = executionEntity.getDeploymentId();
processDefinitionId = executionEntity.getProcessDefinitionId();
}
category = getDeploymentCategoryFromQuery(deploymentId, processDefinitionId);
}
return category;
}
/**
* Obtains the deployment category from current execution context
*
* @return the category for current execution deployment, otherwise null
*/
private String getDeploymentCategoryFromContext()
{
String category = null;
try
{
if (Context.isExecutionContextActive())
{
category = Context.getExecutionContext().getDeployment().getCategory();
}
else
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("No execution context available");
}
}
}
catch (Exception e)
{
// No action required
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Could not obtain deployment category from execution context: {}", e.getMessage());
}
}
// If the workflow is considered secure, the deployment entity category matches the condition (either internal or full access)
return category != null && (WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL.equals(category) || WorkflowDeployer.CATEGORY_FULL_ACCESS.equals(category));
return category;
}
/**
* Checks that the specified 'runAs' field
* specifies a valid username.
* Obtains the deployment category through a query
*
* @param deploymentId
* the deployment id to obtain the category from
* @param processDefinitionId
* if no deployment id is provided, the process definition id can be used to obtain the deployment
* @return the category for the obtained deployment, otherwise null
*/
private void validateRunAsUser(final String runAsUser)
private String getDeploymentCategoryFromQuery(String deploymentId, String processDefinitionId)
{
Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>()
String category = null;
try
{
RepositoryService repositoryService = Context.getProcessEngineConfiguration().getRepositoryService();
if (deploymentId == null && processDefinitionId != null)
{
ProcessDefinition processDefnition = repositoryService.getProcessDefinition(processDefinitionId);
if (processDefnition != null)
{
deploymentId = processDefnition.getDeploymentId();
}
}
if (deploymentId != null)
{
DeploymentEntity deployment = (DeploymentEntity) repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment != null)
{
category = deployment.getCategory();
}
}
}
catch (Exception e)
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Could not obtain deployment category through a query: {}", e.getMessage());
}
}
return category;
}
/**
* Checks that the specified 'runAs' field specifies a valid username.
*/
private void validateRunAsUser(final String runAsUser)
{
Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<>() {
// Validate using System user to ensure sufficient permissions available to access person node.
public Boolean doWork() throws Exception
@Override
public Boolean doWork() throws Exception
{
return getServiceRegistry().getPersonService().personExists(runAsUser);
}
@@ -195,21 +295,21 @@ public class ActivitiScriptBase
throw new WorkflowException("runas user '" + runAsUser + "' does not exist.");
}
}
protected ActivitiScriptNode getPersonNode(String runAsUser)
{
String userName = null;
if (runAsUser != null)
if (runAsUser != null)
{
userName = runAsUser;
}
else
else
{
userName = AuthenticationUtil.getFullyAuthenticatedUser();
}
// The "System" user is a special case, which has no person object associated with it.
if(userName != null && !AuthenticationUtil.SYSTEM_USER_NAME.equals(userName))
if (userName != null && !AuthenticationUtil.SYSTEM_USER_NAME.equals(userName))
{
ServiceRegistry services = getServiceRegistry();
PersonService personService = services.getPersonService();
@@ -221,18 +321,18 @@ public class ActivitiScriptBase
}
return null;
}
public void setScript(Expression script)
public void setScript(Expression script)
{
this.script = script;
}
public void setRunAs(Expression runAs)
public void setRunAs(Expression runAs)
{
this.runAs = runAs;
}
public void setScriptProcessor(Expression scriptProcessor)
public void setScriptProcessor(Expression scriptProcessor)
{
this.scriptProcessor = scriptProcessor;
}

View File

@@ -1,363 +1,354 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2023 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%
*/
/*
* Copyright (C) 2005 Jesper Steen M<>ller
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.repo.action.executer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.test.context.transaction.TestTransaction;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Test of the ActionExecuter for extracting metadata.
*
* @author Jesper Steen Møller
*/
@Category(BaseSpringTestsCategory.class)
@Transactional
public class ContentMetadataExtracterTest extends BaseSpringTest
{
protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog";
protected static final String QUICK_DESCRIPTION = "Pangram, fox, dog, Gym class featuring a brown fox and lazy dog";
protected static final String QUICK_CREATOR = "Nevin Nollop";
private NodeService nodeService;
private ContentService contentService;
private MetadataExtracterRegistry registry;
private TransactionService transactionService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private ContentMetadataExtracter executer;
private final static String ID = GUID.generate();
@Before
public void before() throws Exception
{
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
registry = (MetadataExtracterRegistry) applicationContext.getBean("metadataExtracterRegistry");
transactionService = (TransactionService) this.applicationContext.getBean("transactionService");
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Setup the content from the PDF test data
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));
// Get the executer instance
this.executer = (ContentMetadataExtracter) this.applicationContext.getBean("extract-metadata");
}
/**
* Test execution of the extraction itself
*/
@Test
public void testFromBlanks() throws Exception
{
// Test that the action writes properties when they don't exist or are
// unset
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.remove(ContentModel.PROP_AUTHOR);
props.put(ContentModel.PROP_TITLE, "");
props.put(ContentModel.PROP_DESCRIPTION, null); // Wonder how this will
// be handled
this.nodeService.setProperties(this.nodeRef, props);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
// Execute the action
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
Thread.sleep(3000); // Need to wait for the async extract
// Check that the properties have been set
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertEquals(QUICK_TITLE, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
return null;
}
});
}
private static final QName PROP_UNKNOWN_1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "unkown1");
private static final QName PROP_UNKNOWN_2 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "unkown2");
private static class TestUnknownMetadataExtracter extends AbstractMappingMetadataExtracter
{
public TestUnknownMetadataExtracter()
{
Properties mappingProperties = new Properties();
mappingProperties.put("unknown1", PROP_UNKNOWN_1.toString());
mappingProperties.put("unknown2", PROP_UNKNOWN_2.toString());
setMappingProperties(mappingProperties);
}
@Override
protected Map<String, Set<QName>> getDefaultMapping()
{
// No need to give anything back as we have explicitly set the mapping already
return new HashMap<String, Set<QName>>(0);
}
@Override
public boolean isSupported(String sourceMimetype)
{
return sourceMimetype.equals(MimetypeMap.MIMETYPE_BINARY);
}
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Map<String, Serializable> rawMap = newRawMap();
rawMap.put("unknown1", Integer.valueOf(1));
rawMap.put("unknown2", "TWO");
return rawMap;
}
}
@Test
public void testUnknownProperties()
{
TestUnknownMetadataExtracter extracterUnknown = new TestUnknownMetadataExtracter();
extracterUnknown.setRegistry(registry);
extracterUnknown.register();
// Now add some content with a binary mimetype
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_BINARY);
cw.putContent("Content for " + getName());
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, this.nodeRef);
// The unkown properties should be present
Serializable prop1 = nodeService.getProperty(nodeRef, PROP_UNKNOWN_1);
Serializable prop2 = nodeService.getProperty(nodeRef, PROP_UNKNOWN_2);
assertNotNull("Unknown property is null", prop1);
assertNotNull("Unknown property is null", prop2);
}
private static class TestNullPropMetadataExtracter extends AbstractMappingMetadataExtracter
{
public TestNullPropMetadataExtracter()
{
Properties mappingProperties = new Properties();
mappingProperties.put("title", ContentModel.PROP_TITLE.toString());
mappingProperties.put("description", ContentModel.PROP_DESCRIPTION.toString());
setMappingProperties(mappingProperties);
}
@Override
protected Map<String, Set<QName>> getDefaultMapping()
{
// No need to give anything back as we have explicitly set the mapping already
return new HashMap<String, Set<QName>>(0);
}
@Override
public boolean isSupported(String sourceMimetype)
{
return sourceMimetype.equals(MimetypeMap.MIMETYPE_BINARY);
}
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Map<String, Serializable> rawMap = newRawMap();
putRawValue("title", null, rawMap);
putRawValue("description", "", rawMap);
return rawMap;
}
}
/**
* Ensure that missing raw values result in node properties being removed
* when running with {@link ContentMetadataExtracter#setCarryAspectProperties(boolean)}
* set to <tt>false</tt>.
*/
@Test
public void testNullExtractedValues_ALF1823()
{
TestNullPropMetadataExtracter extractor = new TestNullPropMetadataExtracter();
extractor.setRegistry(registry);
extractor.register();
// Now set the title and description
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "TITLE");
nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "DESCRIPTION");
// Now add some content with a binary mimetype
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_BINARY);
cw.putContent("Content for " + getName());
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, this.nodeRef);
// cm:titled properties should be present
Serializable title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
Serializable descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
assertNotNull("cm:title property is null", title);
assertNotNull("cm:description property is null", descr);
try
{
// Now change the setting to remove unset aspect properties
executer.setCarryAspectProperties(false);
// Extract again
executer.execute(action, this.nodeRef);
// cm:titled properties should *NOT* be present
title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
assertNull("cm:title property is not null", title);
assertNull("cm:description property is not null", descr);
}
finally
{
executer.setCarryAspectProperties(true);
}
}
/**
* Test execution of the pragmatic approach
*/
@Test
public void testFromPartial() throws Exception
{
// Test that the action does not overwrite properties that are already
// set
String myCreator = "Null-op";
String myTitle = "The hot dog is eaten by the city fox";
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.put(ContentModel.PROP_AUTHOR, myCreator);
props.put(ContentModel.PROP_TITLE, myTitle);
props.remove(ContentModel.PROP_DESCRIPTION); // Allow this baby
this.nodeService.setProperties(this.nodeRef, props);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
// Execute the action
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
Thread.sleep(3000); // Need to wait for the async extract
// Check that the properties have been preserved, but that description has been set
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
assertEquals(myTitle, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
return null;
}
});
}
}
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2025 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.action.executer;
import static org.awaitility.Awaitility.await;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.test.context.transaction.TestTransaction;
import org.springframework.transaction.annotation.Transactional;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Test of the ActionExecuter for extracting metadata.
*
* @author Jesper Steen Møller
*/
@Category(BaseSpringTestsCategory.class)
@Transactional
public class ContentMetadataExtracterTest extends BaseSpringTest
{
protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog";
protected static final String QUICK_DESCRIPTION = "Pangram, fox, dog, Gym class featuring a brown fox and lazy dog";
protected static final String QUICK_CREATOR = "Nevin Nollop";
private NodeService nodeService;
private ContentService contentService;
private MetadataExtracterRegistry registry;
private TransactionService transactionService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private ContentMetadataExtracter executer;
private final static String ID = GUID.generate();
@Before
public void before() throws Exception
{
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
registry = (MetadataExtracterRegistry) applicationContext.getBean("metadataExtracterRegistry");
transactionService = (TransactionService) this.applicationContext.getBean("transactionService");
AuthenticationComponent authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
authenticationComponent.setSystemUserAsCurrentUser();
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Setup the content from the PDF test data
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));
// Get the executer instance
this.executer = (ContentMetadataExtracter) this.applicationContext.getBean("extract-metadata");
}
/**
* Test execution of the extraction itself
*/
@Test
public void testFromBlanks() throws Exception
{
// Test that the action writes properties when they don't exist or are
// unset
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.remove(ContentModel.PROP_AUTHOR);
props.put(ContentModel.PROP_TITLE, "");
props.put(ContentModel.PROP_DESCRIPTION, null); // Wonder how this will
// be handled
this.nodeService.setProperties(this.nodeRef, props);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
// Execute the action
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
// Need to wait for the async extract
await().pollInSameThread()
.atMost(MAX_ASYNC_TIMEOUT)
.until(() -> nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), Objects::nonNull);
// Check that the properties have been set
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
assertEquals(QUICK_TITLE, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
return null;
}
});
}
private static final QName PROP_UNKNOWN_1 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "unkown1");
private static final QName PROP_UNKNOWN_2 = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "unkown2");
private static class TestUnknownMetadataExtracter extends AbstractMappingMetadataExtracter
{
public TestUnknownMetadataExtracter()
{
Properties mappingProperties = new Properties();
mappingProperties.put("unknown1", PROP_UNKNOWN_1.toString());
mappingProperties.put("unknown2", PROP_UNKNOWN_2.toString());
setMappingProperties(mappingProperties);
}
@Override
protected Map<String, Set<QName>> getDefaultMapping()
{
// No need to give anything back as we have explicitly set the mapping already
return new HashMap<String, Set<QName>>(0);
}
@Override
public boolean isSupported(String sourceMimetype)
{
return sourceMimetype.equals(MimetypeMap.MIMETYPE_BINARY);
}
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Map<String, Serializable> rawMap = newRawMap();
rawMap.put("unknown1", Integer.valueOf(1));
rawMap.put("unknown2", "TWO");
return rawMap;
}
}
@Test
public void testUnknownProperties()
{
TestUnknownMetadataExtracter extracterUnknown = new TestUnknownMetadataExtracter();
extracterUnknown.setRegistry(registry);
extracterUnknown.register();
// Now add some content with a binary mimetype
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_BINARY);
cw.putContent("Content for " + getName());
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, this.nodeRef);
// The unkown properties should be present
Serializable prop1 = nodeService.getProperty(nodeRef, PROP_UNKNOWN_1);
Serializable prop2 = nodeService.getProperty(nodeRef, PROP_UNKNOWN_2);
assertNotNull("Unknown property is null", prop1);
assertNotNull("Unknown property is null", prop2);
}
private static class TestNullPropMetadataExtracter extends AbstractMappingMetadataExtracter
{
public TestNullPropMetadataExtracter()
{
Properties mappingProperties = new Properties();
mappingProperties.put("title", ContentModel.PROP_TITLE.toString());
mappingProperties.put("description", ContentModel.PROP_DESCRIPTION.toString());
setMappingProperties(mappingProperties);
}
@Override
protected Map<String, Set<QName>> getDefaultMapping()
{
// No need to give anything back as we have explicitly set the mapping already
return new HashMap<String, Set<QName>>(0);
}
@Override
public boolean isSupported(String sourceMimetype)
{
return sourceMimetype.equals(MimetypeMap.MIMETYPE_BINARY);
}
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Map<String, Serializable> rawMap = newRawMap();
putRawValue("title", null, rawMap);
putRawValue("description", "", rawMap);
return rawMap;
}
}
/**
* Ensure that missing raw values result in node properties being removed when running with {@link ContentMetadataExtracter#setCarryAspectProperties(boolean)} set to <tt>false</tt>.
*/
@Test
public void testNullExtractedValues_ALF1823()
{
TestNullPropMetadataExtracter extractor = new TestNullPropMetadataExtracter();
extractor.setRegistry(registry);
extractor.register();
// Now set the title and description
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "TITLE");
nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "DESCRIPTION");
// Now add some content with a binary mimetype
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_BINARY);
cw.putContent("Content for " + getName());
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, this.nodeRef);
// cm:titled properties should be present
Serializable title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
Serializable descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
assertNotNull("cm:title property is null", title);
assertNotNull("cm:description property is null", descr);
try
{
// Now change the setting to remove unset aspect properties
executer.setCarryAspectProperties(false);
// Extract again
executer.execute(action, this.nodeRef);
// cm:titled properties should *NOT* be present
title = nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
descr = nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
assertNull("cm:title property is not null", title);
assertNull("cm:description property is not null", descr);
}
finally
{
executer.setCarryAspectProperties(true);
}
}
/**
* Test execution of the pragmatic approach
*/
@Test
public void testFromPartial() throws Exception
{
// Test that the action does not overwrite properties that are already
// set
String myCreator = "Null-op";
String myTitle = "The hot dog is eaten by the city fox";
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.put(ContentModel.PROP_AUTHOR, myCreator);
props.put(ContentModel.PROP_TITLE, myTitle);
props.remove(ContentModel.PROP_DESCRIPTION); // Allow this baby
this.nodeService.setProperties(this.nodeRef, props);
// Make the nodeRef visible to other transactions as it will need to be in async requests
TestTransaction.flagForCommit();
TestTransaction.end();
// Execute the action
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
ActionImpl action = new ActionImpl(null, ID, SetPropertyValueActionExecuter.NAME, null);
executer.execute(action, nodeRef);
return null;
}
});
// Need to wait for the async extract
await().pollInSameThread()
.atMost(MAX_ASYNC_TIMEOUT)
.until(() -> nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), Objects::nonNull);
// Check that the properties have been preserved, but that description has been set
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
assertEquals(myTitle, nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHOR));
assertEquals(QUICK_DESCRIPTION, nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION));
return null;
}
});
}
}

View File

@@ -1,478 +1,475 @@
/*
* #%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.caching.cleanup;
import static org.junit.Assert.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.alfresco.repo.content.caching.CacheFileProps;
import org.alfresco.repo.content.caching.CachingContentStore;
import org.alfresco.repo.content.caching.ContentCacheImpl;
import org.alfresco.repo.content.caching.Key;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.alfresco.util.testing.category.LuceneTests;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
/**
* Tests for the CachedContentCleanupJob
*
* @author Matt Ward
*/
@Category(LuceneTests.class)
public class CachedContentCleanupJobTest
{
private enum UrlSource { PROPS_FILE, REVERSE_CACHE_LOOKUP, NOT_PRESENT };
private static ApplicationContext ctx;
private CachingContentStore cachingStore;
private ContentCacheImpl cache;
private File cacheRoot;
private CachedContentCleaner cleaner;
@BeforeClass
public static void beforeClass()
{
String cleanerConf = "classpath:cachingstore/test-cleaner-context.xml";
ctx = ApplicationContextHelper.getApplicationContext(new String[] { cleanerConf });
}
@Before
public void setUp() throws IOException
{
cachingStore = (CachingContentStore) ctx.getBean("cachingContentStore");
cache = (ContentCacheImpl) ctx.getBean("contentCache");
cacheRoot = cache.getCacheRoot();
cleaner = (CachedContentCleaner) ctx.getBean("cachedContentCleaner");
cleaner.setMinFileAgeMillis(0);
cleaner.setMaxDeleteWatchCount(0);
// Clear the cache from disk and memory
cache.removeAll();
FileUtils.cleanDirectory(cacheRoot);
}
@Test
public void filesNotInCacheAreDeleted() throws InterruptedException
{
cleaner.setMaxDeleteWatchCount(0);
int numFiles = 300; // Must be a multiple of number of UrlSource types being tested
long totalSize = 0; // what is the total size of the sample files?
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
// Testing with a number of files. The cached file cleaner will be able to determine the 'original'
// content URL for each file by either retrieving from the companion properties file, or performing
// a 'reverse lookup' in the cache (i.e. cache.contains(Key.forCacheFile(...))), or there will be no
// URL determinable for the file.
UrlSource urlSource = UrlSource.values()[i % UrlSource.values().length];
File cacheFile = createCacheFile(urlSource, false);
files[i] = cacheFile;
totalSize += cacheFile.length();
}
// Run cleaner
cleaner.execute();
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
// check all files deleted
for (File file : files)
{
assertFalse("File should have been deleted: " + file, file.exists());
}
assertEquals("Incorrect number of deleted files", numFiles, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", totalSize, cleaner.getSizeFilesDeleted());
}
@Test
public void filesNewerThanMinFileAgeMillisAreNotDeleted() throws InterruptedException
{
final long minFileAge = 5000;
cleaner.setMinFileAgeMillis(minFileAge);
cleaner.setMaxDeleteWatchCount(0);
int numFiles = 10;
File[] oldFiles = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
oldFiles[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, false);
}
// Sleep to make sure 'old' files really are older than minFileAgeMillis
Thread.sleep(minFileAge);
File[] newFiles = new File[numFiles];
long newFilesTotalSize = 0;
for (int i = 0; i < numFiles; i++)
{
newFiles[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, false);
newFilesTotalSize += newFiles[i].length();
}
// The cleaner must finish before any of the newFiles are older than minFileAge. If the files are too
// old the test will fail and it will be necessary to rethink how to test this.
cleaner.execute();
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
if (cleaner.getDurationMillis() > minFileAge)
{
fail("Test unable to complete, since cleaner took " + cleaner.getDurationMillis() + "ms" +
" which is longer than minFileAge [" + minFileAge + "ms]");
}
// check all 'old' files deleted
for (File file : oldFiles)
{
assertFalse("File should have been deleted: " + file, file.exists());
}
// check all 'new' files still present
for (File file : newFiles)
{
assertTrue("File should not have been deleted: " + file, file.exists());
}
assertEquals("Incorrect number of deleted files", newFiles.length, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", newFilesTotalSize, cleaner.getSizeFilesDeleted());
}
@Test
public void aggressiveCleanReclaimsTargetSpace() throws InterruptedException
{
int numFiles = 30;
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
// Make sure it's in the cache - all the files will be in the cache, so the
// cleaner won't clean any up once it has finished aggressively reclaiming space.
files[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, true);
}
// How much space to reclaim - seven files worth (all files are same size)
long fileSize = files[0].length();
long sevenFilesSize = 7 * fileSize;
// We'll get it to clean seven files worth aggressively and then it will continue non-aggressively.
// It will delete the older files aggressively (i.e. the ones prior to the two second sleep) and
// then will examine the new files for potential deletion.
// Since some of the newer files are not in the cache, it will delete those.
cleaner.executeAggressive("aggressiveCleanReclaimsTargetSpace()", sevenFilesSize);
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
int numDeleted = 0;
for (File f : files)
{
if (!f.exists())
{
numDeleted++;
}
}
// How many were definitely deleted?
assertEquals("Wrong number of files deleted", 7 , numDeleted);
// The cleaner should have recorded the correct number of deletions
assertEquals("Incorrect number of deleted files", 7, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", sevenFilesSize, cleaner.getSizeFilesDeleted());
}
@Test
public void standardCleanAfterAggressiveFinished() throws InterruptedException
{
// Don't use numFiles > 59! as we're using this for the minute element in the cache file path.
final int numFiles = 30;
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
Calendar calendar = new GregorianCalendar(2010, 11, 2, 17, i);
if (i >= 21 && i <= 24)
{
// 21 to 24 will be deleted after the aggressive deletions (once the cleaner has returned
// to normal cleaning), because they are not in the cache.
files[i] = createCacheFile(calendar, UrlSource.NOT_PRESENT, false);
}
else
{
// All other files will be in the cache
files[i] = createCacheFile(calendar, UrlSource.REVERSE_CACHE_LOOKUP, true);
}
}
// How much space to reclaim - seven files worth (all files are same size)
long fileSize = files[0].length();
long sevenFilesSize = 7 * fileSize;
// We'll get it to clean seven files worth aggressively and then it will continue non-aggressively.
// It will delete the older files aggressively (i.e. even if they are actively in the cache) and
// then will examine the new files for potential deletion.
// Since some of the newer files are not in the cache, it will delete those too.
cleaner.executeAggressive("standardCleanAfterAggressiveFinished()", sevenFilesSize);
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
for (int i = 0; i < numFiles; i++)
{
if (i < 7)
{
assertFalse("First 7 files should have been aggressively cleaned", files[i].exists());
}
if (i >= 21 && i <= 24)
{
assertFalse("Files with indexes 21-24 should have been deleted", files[i].exists());
}
}
assertEquals("Incorrect number of deleted files", 11, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", (11*fileSize), cleaner.getSizeFilesDeleted());
}
@Test
public void emptyParentDirectoriesAreDeleted() throws FileNotFoundException
{
cleaner.setMaxDeleteWatchCount(0);
File file = new File(cacheRoot, "243235984/a/b/c/d.bin");
file.getParentFile().mkdirs();
PrintWriter writer = new PrintWriter(file);
writer.println("Content for emptyParentDirectoriesAreDeleted");
writer.close();
assertTrue("Directory should exist", new File(cacheRoot, "243235984/a/b/c").exists());
cleaner.handle(file);
assertFalse("Directory should have been deleted", new File(cacheRoot, "243235984").exists());
}
@Test
public void markedFilesHaveDeletionDeferredUntilCorrectPassOfCleaner()
{
// A non-advisable setting but useful for testing, maxDeleteWatchCount of zero
// which should result in immediate deletion upon discovery of content no longer in the cache.
cleaner.setMaxDeleteWatchCount(0);
File file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkFilesDeleted(file);
// Anticipated to be the most common setting: maxDeleteWatchCount of 1.
cleaner.setMaxDeleteWatchCount(1);
file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 1);
cleaner.handle(file);
checkFilesDeleted(file);
// Check that some other arbitrary figure for maxDeleteWatchCount works correctly.
cleaner.setMaxDeleteWatchCount(3);
file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 1);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 2);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 3);
cleaner.handle(file);
checkFilesDeleted(file);
}
private void checkFilesDeleted(File file)
{
assertFalse("File should have been deleted: " + file, file.exists());
CacheFileProps props = new CacheFileProps(file);
assertFalse("Properties file should have been deleted, cache file: " + file, props.exists());
}
private void checkWatchCountForCacheFile(File file, Integer expectedWatchCount)
{
assertTrue("File should still exist: " + file, file.exists());
CacheFileProps props = new CacheFileProps(file);
props.load();
assertEquals("File should contain correct deleteWatchCount", expectedWatchCount, props.getDeleteWatchCount());
}
@Test
public void filesInCacheAreNotDeleted() throws InterruptedException
{
cleaner.setMaxDeleteWatchCount(0);
// The SlowContentStore will always give out content when asked,
// so asking for any content will cause something to be cached.
String url = makeContentUrl();
int numFiles = 50;
for (int i = 0; i < numFiles; i++)
{
ContentReader reader = cachingStore.getReader(url);
reader.getContentString();
}
cleaner.execute();
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
for (int i = 0; i < numFiles; i++)
{
File cacheFile = new File(cache.getCacheFilePath(url));
assertTrue("File should exist", cacheFile.exists());
}
}
private File createCacheFile(UrlSource urlSource, boolean putInCache)
{
Calendar calendar = new GregorianCalendar();
return createCacheFile(calendar, urlSource, putInCache);
}
private File createCacheFile(Calendar calendar, /*int year, int month, int day, int hour, int minute,*/
UrlSource urlSource, boolean putInCache)
{
File file = new File(cacheRoot, createNewCacheFilePath(calendar));
file.getParentFile().mkdirs();
writeSampleContent(file);
String contentUrl = makeContentUrl();
if (putInCache)
{
cache.putIntoLookup(Key.forUrl(contentUrl), file.getAbsolutePath());
}
switch(urlSource)
{
case NOT_PRESENT:
// cache won't be able to determine original content URL for the file
break;
case PROPS_FILE:
// file with content URL in properties file
CacheFileProps props = new CacheFileProps(file);
props.setContentUrl(contentUrl);
props.store();
break;
case REVERSE_CACHE_LOOKUP:
// file with content URL in reverse lookup cache - but not 'in the cache' (forward lookup).
cache.putIntoLookup(Key.forCacheFile(file), contentUrl);
}
assertTrue("File should exist", file.exists());
return file;
}
/**
* Mimick functionality of ContentCacheImpl.createNewCacheFilePath()
* but allowing a specific date (rather than 'now') to be used.
*
* @param calendar Calendar
* @return Path to use for cache file.
*/
private String createNewCacheFilePath(Calendar calendar)
{
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1; // 0-based
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
// create the URL
StringBuilder sb = new StringBuilder(20);
sb.append(year).append('/')
.append(month).append('/')
.append(day).append('/')
.append(hour).append('/')
.append(minute).append('/')
.append(GUID.generate()).append(".bin");
return sb.toString();
}
private String makeContentUrl()
{
return "protocol://some/made/up/url/" + GUID.generate();
}
private void writeSampleContent(File file)
{
try
{
PrintWriter writer = new PrintWriter(file);
writer.println("Content for sample file in " + getClass().getName());
writer.close();
}
catch (Throwable e)
{
throw new RuntimeException("Couldn't write file: " + file, e);
}
}
}
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2025 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.caching.cleanup;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Duration;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.alfresco.repo.content.caching.CacheFileProps;
import org.alfresco.repo.content.caching.CachingContentStore;
import org.alfresco.repo.content.caching.ContentCacheImpl;
import org.alfresco.repo.content.caching.Key;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.alfresco.util.testing.category.LuceneTests;
/**
* Tests for the CachedContentCleanupJob
*
* @author Matt Ward
*/
@Category(LuceneTests.class)
public class CachedContentCleanupJobTest
{
private static final Duration MAX_WAIT_TIMEOUT = Duration.ofSeconds(10);
private enum UrlSource
{
PROPS_FILE, REVERSE_CACHE_LOOKUP, NOT_PRESENT
}
;
private static ApplicationContext ctx;
private CachingContentStore cachingStore;
private ContentCacheImpl cache;
private File cacheRoot;
private CachedContentCleaner cleaner;
@BeforeClass
public static void beforeClass()
{
String cleanerConf = "classpath:cachingstore/test-cleaner-context.xml";
ctx = ApplicationContextHelper.getApplicationContext(new String[]{cleanerConf});
}
@Before
public void setUp() throws IOException
{
cachingStore = (CachingContentStore) ctx.getBean("cachingContentStore");
cache = (ContentCacheImpl) ctx.getBean("contentCache");
cacheRoot = cache.getCacheRoot();
cleaner = (CachedContentCleaner) ctx.getBean("cachedContentCleaner");
cleaner.setMinFileAgeMillis(0);
cleaner.setMaxDeleteWatchCount(0);
// Clear the cache from disk and memory
cache.removeAll();
FileUtils.cleanDirectory(cacheRoot);
}
@Test
public void filesNotInCacheAreDeleted() throws InterruptedException
{
cleaner.setMaxDeleteWatchCount(0);
int numFiles = 300; // Must be a multiple of number of UrlSource types being tested
long totalSize = 0; // what is the total size of the sample files?
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
// Testing with a number of files. The cached file cleaner will be able to determine the 'original'
// content URL for each file by either retrieving from the companion properties file, or performing
// a 'reverse lookup' in the cache (i.e. cache.contains(Key.forCacheFile(...))), or there will be no
// URL determinable for the file.
UrlSource urlSource = UrlSource.values()[i % UrlSource.values().length];
File cacheFile = createCacheFile(urlSource, false);
files[i] = cacheFile;
totalSize += cacheFile.length();
}
// Run cleaner
cleaner.execute();
await().pollDelay(Duration.ofMillis(100))
.atMost(MAX_WAIT_TIMEOUT)
.until(() -> !cleaner.isRunning());
// check all files deleted
for (File file : files)
{
assertFalse("File should have been deleted: " + file, file.exists());
}
assertEquals("Incorrect number of deleted files", numFiles, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", totalSize, cleaner.getSizeFilesDeleted());
}
@Test
public void filesNewerThanMinFileAgeMillisAreNotDeleted() throws InterruptedException
{
final long minFileAge = 5000;
cleaner.setMinFileAgeMillis(minFileAge);
cleaner.setMaxDeleteWatchCount(0);
int numFiles = 10;
File[] oldFiles = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
oldFiles[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, false);
}
// Sleep to make sure 'old' files really are older than minFileAgeMillis
Thread.sleep(minFileAge);
File[] newFiles = new File[numFiles];
long newFilesTotalSize = 0;
for (int i = 0; i < numFiles; i++)
{
newFiles[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, false);
newFilesTotalSize += newFiles[i].length();
}
// The cleaner must finish before any of the newFiles are older than minFileAge. If the files are too
// old the test will fail and it will be necessary to rethink how to test this.
cleaner.execute();
await().pollDelay(Duration.ofMillis(100))
.atMost(MAX_WAIT_TIMEOUT)
.until(() -> !cleaner.isRunning());
if (cleaner.getDurationMillis() > minFileAge)
{
fail("Test unable to complete, since cleaner took " + cleaner.getDurationMillis() + "ms" +
" which is longer than minFileAge [" + minFileAge + "ms]");
}
// check all 'old' files deleted
for (File file : oldFiles)
{
assertFalse("File should have been deleted: " + file, file.exists());
}
// check all 'new' files still present
for (File file : newFiles)
{
assertTrue("File should not have been deleted: " + file, file.exists());
}
assertEquals("Incorrect number of deleted files", newFiles.length, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", newFilesTotalSize, cleaner.getSizeFilesDeleted());
}
@Test
public void aggressiveCleanReclaimsTargetSpace() throws InterruptedException
{
int numFiles = 30;
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
// Make sure it's in the cache - all the files will be in the cache, so the
// cleaner won't clean any up once it has finished aggressively reclaiming space.
files[i] = createCacheFile(UrlSource.REVERSE_CACHE_LOOKUP, true);
}
// How much space to reclaim - seven files worth (all files are same size)
long fileSize = files[0].length();
long sevenFilesSize = 7 * fileSize;
// We'll get it to clean seven files worth aggressively and then it will continue non-aggressively.
// It will delete the older files aggressively (i.e. the ones prior to the two second sleep) and
// then will examine the new files for potential deletion.
// Since some of the newer files are not in the cache, it will delete those.
cleaner.executeAggressive("aggressiveCleanReclaimsTargetSpace()", sevenFilesSize);
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
int numDeleted = 0;
for (File f : files)
{
if (!f.exists())
{
numDeleted++;
}
}
// How many were definitely deleted?
assertEquals("Wrong number of files deleted", 7, numDeleted);
// The cleaner should have recorded the correct number of deletions
assertEquals("Incorrect number of deleted files", 7, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", sevenFilesSize, cleaner.getSizeFilesDeleted());
}
@Test
public void standardCleanAfterAggressiveFinished() throws InterruptedException
{
// Don't use numFiles > 59! as we're using this for the minute element in the cache file path.
final int numFiles = 30;
File[] files = new File[numFiles];
for (int i = 0; i < numFiles; i++)
{
Calendar calendar = new GregorianCalendar(2010, 11, 2, 17, i);
if (i >= 21 && i <= 24)
{
// 21 to 24 will be deleted after the aggressive deletions (once the cleaner has returned
// to normal cleaning), because they are not in the cache.
files[i] = createCacheFile(calendar, UrlSource.NOT_PRESENT, false);
}
else
{
// All other files will be in the cache
files[i] = createCacheFile(calendar, UrlSource.REVERSE_CACHE_LOOKUP, true);
}
}
// How much space to reclaim - seven files worth (all files are same size)
long fileSize = files[0].length();
long sevenFilesSize = 7 * fileSize;
// We'll get it to clean seven files worth aggressively and then it will continue non-aggressively.
// It will delete the older files aggressively (i.e. even if they are actively in the cache) and
// then will examine the new files for potential deletion.
// Since some of the newer files are not in the cache, it will delete those too.
cleaner.executeAggressive("standardCleanAfterAggressiveFinished()", sevenFilesSize);
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
for (int i = 0; i < numFiles; i++)
{
if (i < 7)
{
assertFalse("First 7 files should have been aggressively cleaned", files[i].exists());
}
if (i >= 21 && i <= 24)
{
assertFalse("Files with indexes 21-24 should have been deleted", files[i].exists());
}
}
assertEquals("Incorrect number of deleted files", 11, cleaner.getNumFilesDeleted());
assertEquals("Incorrect total size of files deleted", (11 * fileSize), cleaner.getSizeFilesDeleted());
}
@Test
public void emptyParentDirectoriesAreDeleted() throws FileNotFoundException
{
cleaner.setMaxDeleteWatchCount(0);
File file = new File(cacheRoot, "243235984/a/b/c/d.bin");
file.getParentFile().mkdirs();
PrintWriter writer = new PrintWriter(file);
writer.println("Content for emptyParentDirectoriesAreDeleted");
writer.close();
assertTrue("Directory should exist", new File(cacheRoot, "243235984/a/b/c").exists());
cleaner.handle(file);
assertFalse("Directory should have been deleted", new File(cacheRoot, "243235984").exists());
}
@Test
public void markedFilesHaveDeletionDeferredUntilCorrectPassOfCleaner()
{
// A non-advisable setting but useful for testing, maxDeleteWatchCount of zero
// which should result in immediate deletion upon discovery of content no longer in the cache.
cleaner.setMaxDeleteWatchCount(0);
File file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkFilesDeleted(file);
// Anticipated to be the most common setting: maxDeleteWatchCount of 1.
cleaner.setMaxDeleteWatchCount(1);
file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 1);
cleaner.handle(file);
checkFilesDeleted(file);
// Check that some other arbitrary figure for maxDeleteWatchCount works correctly.
cleaner.setMaxDeleteWatchCount(3);
file = createCacheFile(UrlSource.NOT_PRESENT, false);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 1);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 2);
cleaner.handle(file);
checkWatchCountForCacheFile(file, 3);
cleaner.handle(file);
checkFilesDeleted(file);
}
private void checkFilesDeleted(File file)
{
assertFalse("File should have been deleted: " + file, file.exists());
CacheFileProps props = new CacheFileProps(file);
assertFalse("Properties file should have been deleted, cache file: " + file, props.exists());
}
private void checkWatchCountForCacheFile(File file, Integer expectedWatchCount)
{
assertTrue("File should still exist: " + file, file.exists());
CacheFileProps props = new CacheFileProps(file);
props.load();
assertEquals("File should contain correct deleteWatchCount", expectedWatchCount, props.getDeleteWatchCount());
}
@Test
public void filesInCacheAreNotDeleted() throws InterruptedException
{
cleaner.setMaxDeleteWatchCount(0);
// The SlowContentStore will always give out content when asked,
// so asking for any content will cause something to be cached.
String url = makeContentUrl();
int numFiles = 50;
for (int i = 0; i < numFiles; i++)
{
ContentReader reader = cachingStore.getReader(url);
reader.getContentString();
}
cleaner.execute();
Thread.sleep(400);
while (cleaner.isRunning())
{
Thread.sleep(200);
}
for (int i = 0; i < numFiles; i++)
{
File cacheFile = new File(cache.getCacheFilePath(url));
assertTrue("File should exist", cacheFile.exists());
}
}
private File createCacheFile(UrlSource urlSource, boolean putInCache)
{
Calendar calendar = new GregorianCalendar();
return createCacheFile(calendar, urlSource, putInCache);
}
private File createCacheFile(Calendar calendar, /* int year, int month, int day, int hour, int minute, */
UrlSource urlSource, boolean putInCache)
{
File file = new File(cacheRoot, createNewCacheFilePath(calendar));
file.getParentFile().mkdirs();
writeSampleContent(file);
String contentUrl = makeContentUrl();
if (putInCache)
{
cache.putIntoLookup(Key.forUrl(contentUrl), file.getAbsolutePath());
}
switch (urlSource)
{
case NOT_PRESENT:
// cache won't be able to determine original content URL for the file
break;
case PROPS_FILE:
// file with content URL in properties file
CacheFileProps props = new CacheFileProps(file);
props.setContentUrl(contentUrl);
props.store();
break;
case REVERSE_CACHE_LOOKUP:
// file with content URL in reverse lookup cache - but not 'in the cache' (forward lookup).
cache.putIntoLookup(Key.forCacheFile(file), contentUrl);
}
assertTrue("File should exist", file.exists());
return file;
}
/**
* Mimick functionality of ContentCacheImpl.createNewCacheFilePath() but allowing a specific date (rather than 'now') to be used.
*
* @param calendar
* Calendar
* @return Path to use for cache file.
*/
private String createNewCacheFilePath(Calendar calendar)
{
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1; // 0-based
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
// create the URL
StringBuilder sb = new StringBuilder(20);
sb.append(year).append('/')
.append(month).append('/')
.append(day).append('/')
.append(hour).append('/')
.append(minute).append('/')
.append(GUID.generate()).append(".bin");
return sb.toString();
}
private String makeContentUrl()
{
return "protocol://some/made/up/url/" + GUID.generate();
}
private void writeSampleContent(File file)
{
try
{
PrintWriter writer = new PrintWriter(file);
writer.println("Content for sample file in " + getClass().getName());
writer.close();
}
catch (Throwable e)
{
throw new RuntimeException("Couldn't write file: " + file, e);
}
}
}

View File

@@ -1,57 +1,57 @@
/*
* #%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.util;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextCustomizerFactories;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Base test class providing Hibernate sessions.
* <p>
* By default this is auto-wired by type. If a this is going to
* result in a conlict the use auto-wire by name. This can be done by
* setting populateProtectedVariables to true in the constructor and
* then adding protected members with the same name as the bean you require.
*
* @author Derek Hulley
*/
@RunWith(SpringRunner.class)
@ContextConfiguration({"classpath:alfresco/application-context.xml"})
@ContextCustomizerFactories(factories = {}, mergeMode = ContextCustomizerFactories.MergeMode.REPLACE_DEFAULTS)
public abstract class BaseSpringTest extends TestCase
{
public Log logger = LogFactory.getLog(getClass().getName());
@Autowired
protected ApplicationContext applicationContext;
}
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2025 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.util;
import java.time.Duration;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextCustomizerFactories;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Base test class providing Hibernate sessions.
* <p>
* By default this is auto-wired by type. If a this is going to result in a conlict the use auto-wire by name. This can be done by setting populateProtectedVariables to true in the constructor and then adding protected members with the same name as the bean you require.
*
* @author Derek Hulley
*/
@RunWith(SpringRunner.class)
@ContextConfiguration({"classpath:alfresco/application-context.xml"})
@ContextCustomizerFactories(factories = {}, mergeMode = ContextCustomizerFactories.MergeMode.REPLACE_DEFAULTS)
public abstract class BaseSpringTest extends TestCase
{
protected static final Duration MAX_ASYNC_TIMEOUT = Duration.ofSeconds(10);
public Log logger = LogFactory.getLog(getClass().getName());
@Autowired
protected ApplicationContext applicationContext;
}