Commit a93188af999d30510759e3b2ca47ad8d65e1f057

Authored by Steven Glover
1 parent 9b196c97a8
Exists in master

Changes resulting from review comments

1 1 This library adds a scheduled job that will empty your Alfresco trashcan according to configuration. The following properties can be configured in alfresco-global.properties:
2 2  
  3 +```
3 4 trashcan.cron=0 30 * * * ?
4 5 trashcan.daysToKeep=P1D
5 6 trashcan.deleteBatchCount=1000
  7 +```
6 8  
7 9 In the above configuration the scheduled process will clean all deleted items older than one day to a maximum of 1000 (each execution) each hour at the middle of the hour (30 minutes).
8 10  
9 11 To enable debug logging:
10 12  
11   -log4j.logger.org.alfresco.trashcan=debug
12 13 \ No newline at end of file
  14 +```
  15 +log4j.logger.org.alfresco.trashcan=debug
  16 +```
13 17 \ No newline at end of file
... ...
... ... @@ -15,7 +15,8 @@
15 15 </parent>
16 16  
17 17 <properties>
18   - <!-- Defines the alfresco edition to compile against. Allowed values are [org.alfresco|org.alfresco.enterprise]-->
  18 + <!-- Defines the alfresco edition to compile against. Allowed values
  19 + are [org.alfresco|org.alfresco.enterprise] -->
19 20 <alfresco.groupId>org.alfresco</alfresco.groupId>
20 21 <!-- Defines the alfresco version to compile against -->
21 22 <alfresco.version>5.2.1-SNAPSHOT</alfresco.version>
... ... @@ -34,12 +35,12 @@
34 35 (e.g.version and edition) -->
35 36 <dependencyManagement>
36 37 <dependencies>
37   - <!--
38   - This will import the dependencyManagement for all artifacts in the selected Alfresco version/edition
39   - (see http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies)
40   - NOTE: You still need to define dependencies in your POM, but you can omit version as it's enforced by this dependencyManagement. NOTE: It defaults
41   - to the latest version this SDK pom has been tested with, but alfresco version can/should be overridden in your project's pom
42   - -->
  38 + <!-- This will import the dependencyManagement for all artifacts
  39 + in the selected Alfresco version/edition (see http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies)
  40 + NOTE: You still need to define dependencies in your POM, but you can omit
  41 + version as it's enforced by this dependencyManagement. NOTE: It defaults
  42 + to the latest version this SDK pom has been tested with, but alfresco version
  43 + can/should be overridden in your project's pom -->
43 44 <dependency>
44 45 <groupId>${alfresco.groupId}</groupId>
45 46 <artifactId>alfresco-platform-distribution</artifactId>
... ... @@ -49,10 +50,10 @@
49 50 </dependency>
50 51 </dependencies>
51 52 </dependencyManagement>
52   -
  53 +
53 54 <!-- Following dependencies are needed for compiling Java code in src/main/java;
54   - <scope>provided</scope> is inherited for each of the following;
55   - for more info, please refer to alfresco-platform-distribution POM -->
  55 + <scope>provided</scope> is inherited for each of the following; for more
  56 + info, please refer to alfresco-platform-distribution POM -->
56 57 <dependencies>
57 58 <dependency>
58 59 <groupId>${alfresco.groupId}</groupId>
... ... @@ -91,39 +92,34 @@
91 92 </resources>
92 93  
93 94 <pluginManagement>
94   - <plugins>
95   - <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
96   - <plugin>
97   - <groupId>org.eclipse.m2e</groupId>
98   - <artifactId>lifecycle-mapping</artifactId>
99   - <version>1.0.0</version>
100   - <configuration>
101   - <lifecycleMappingMetadata>
102   - <pluginExecutions>
103   - <pluginExecution>
104   - <pluginExecutionFilter>
105   - <groupId>
106   - org.codehaus.mojo
107   - </groupId>
108   - <artifactId>
109   - sql-maven-plugin
110   - </artifactId>
111   - <versionRange>
112   - [1.5,)
113   - </versionRange>
114   - <goals>
115   - <goal>execute</goal>
116   - </goals>
117   - </pluginExecutionFilter>
118   - <action>
119   - <ignore></ignore>
120   - </action>
121   - </pluginExecution>
122   - </pluginExecutions>
123   - </lifecycleMappingMetadata>
124   - </configuration>
125   - </plugin>
126   - </plugins>
  95 + <plugins>
  96 + <!--This plugin's configuration is used to store Eclipse
  97 + m2e settings only. It has no influence on the Maven build itself. -->
  98 + <plugin>
  99 + <groupId>org.eclipse.m2e</groupId>
  100 + <artifactId>lifecycle-mapping</artifactId>
  101 + <version>1.0.0</version>
  102 + <configuration>
  103 + <lifecycleMappingMetadata>
  104 + <pluginExecutions>
  105 + <pluginExecution>
  106 + <pluginExecutionFilter>
  107 + <groupId>org.codehaus.mojo</groupId>
  108 + <artifactId>sql-maven-plugin</artifactId>
  109 + <versionRange>[1.5,)</versionRange>
  110 + <goals>
  111 + <goal>execute</goal>
  112 + </goals>
  113 + </pluginExecutionFilter>
  114 + <action>
  115 + <ignore></ignore>
  116 + </action>
  117 + </pluginExecution>
  118 + </pluginExecutions>
  119 + </lifecycleMappingMetadata>
  120 + </configuration>
  121 + </plugin>
  122 + </plugins>
127 123 </pluginManagement>
128 124 </build>
129 125  
... ... @@ -147,53 +143,53 @@
147 143 <name>wipeDB</name>
148 144 </property>
149 145 </activation>
150   - <build>
151   - <plugins>
152   - <plugin>
153   - <groupId>org.codehaus.mojo</groupId>
154   - <artifactId>sql-maven-plugin</artifactId>
155   - <dependencies>
156   - <dependency>
157   - <groupId>org.postgresql</groupId>
158   - <artifactId>postgresql</artifactId>
159   - <version>${dependency.postgresql.version}</version>
160   - </dependency>
  146 + <build>
  147 + <plugins>
  148 + <plugin>
  149 + <groupId>org.codehaus.mojo</groupId>
  150 + <artifactId>sql-maven-plugin</artifactId>
  151 + <dependencies>
  152 + <dependency>
  153 + <groupId>org.postgresql</groupId>
  154 + <artifactId>postgresql</artifactId>
  155 + <version>${dependency.postgresql.version}</version>
  156 + </dependency>
161 157 </dependencies>
162   - <configuration>
163   - <skip>${db.skip}</skip>
164   - <autocommit>true</autocommit>
165   - <driver>${db.driver}</driver>
166   - <url>${db.master.url}</url>
167   - <username>${db.master.username}</username>
168   - <password>${db.master.password}</password>
169   - </configuration>
170   - <executions>
171   - <execution>
172   - <id>drop-db</id>
173   - <phase>initialize</phase>
174   - <goals>
175   - <goal>execute</goal>
176   - </goals>
177   - <configuration>
178   - <skip>false</skip><!-- always run -->
179   - <sqlCommand>${db.drop.command}</sqlCommand>
180   - </configuration>
181   - </execution>
182   - <execution>
183   - <id>create-db</id>
184   - <phase>initialize</phase>
185   - <goals>
186   - <goal>execute</goal>
187   - </goals>
188   - <configuration>
189   - <skip>false</skip><!-- always run -->
190   - <sqlCommand>${db.create.command}</sqlCommand>
191   - </configuration>
192   - </execution>
193   - </executions>
194   - </plugin>
195   - </plugins>
196   - </build>
  158 + <configuration>
  159 + <skip>${db.skip}</skip>
  160 + <autocommit>true</autocommit>
  161 + <driver>${db.driver}</driver>
  162 + <url>${db.master.url}</url>
  163 + <username>${db.master.username}</username>
  164 + <password>${db.master.password}</password>
  165 + </configuration>
  166 + <executions>
  167 + <execution>
  168 + <id>drop-db</id>
  169 + <phase>initialize</phase>
  170 + <goals>
  171 + <goal>execute</goal>
  172 + </goals>
  173 + <configuration>
  174 + <skip>false</skip><!-- always run -->
  175 + <sqlCommand>${db.drop.command}</sqlCommand>
  176 + </configuration>
  177 + </execution>
  178 + <execution>
  179 + <id>create-db</id>
  180 + <phase>initialize</phase>
  181 + <goals>
  182 + <goal>execute</goal>
  183 + </goals>
  184 + <configuration>
  185 + <skip>false</skip><!-- always run -->
  186 + <sqlCommand>${db.create.command}</sqlCommand>
  187 + </configuration>
  188 + </execution>
  189 + </executions>
  190 + </plugin>
  191 + </plugins>
  192 + </build>
197 193 </profile>
198 194 </profiles>
199 195 </project>
... ...
src/main/config/alfresco/module/alfresco-trashcan-cleaner/context/service-context.xml
... ... @@ -11,20 +11,21 @@
11 11  
12 12 <bean id="trashcanCleanerJob" class="org.alfresco.util.CronTriggerBean">
13 13 <property name="jobDetail">
14   - <bean id="trashcanCleanerJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
  14 + <bean id="trashcanCleanerJobDetail"
  15 + class="org.springframework.scheduling.quartz.JobDetailBean">
15 16 <property name="jobClass">
16 17 <value>org.alfresco.trashcan.TrashcanCleanerJob</value>
17 18 </property>
18 19 <property name="jobDataAsMap">
19   - <map>
20   - <entry key="trashcanCleaner" value-ref="trashcanCleaner" />
  20 + <map>
  21 + <entry key="trashcanCleaner" value-ref="trashcanCleaner" />
21 22 <entry key="jobLockService" value-ref="jobLockService" />
22   - </map>
23   - </property>
  23 + </map>
  24 + </property>
24 25 </bean>
25 26 </property>
26 27 <property name="scheduler" ref="schedulerFactory" />
27 28 <property name="cronExpression" value="${trashcan.cron}" />
28 29 </bean>
29   -
  30 +
30 31 </beans>
... ...
src/main/config/alfresco/module/alfresco-trashcan-cleaner/module-context.xml
... ... @@ -18,7 +18,7 @@
18 18 <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
19 19  
20 20 <beans>
21   - <!-- This is filtered by Maven at build time, so that module name is single sourced. -->
  21 + <!-- This is filtered by Maven at build time, so that module name is single sourced. -->
22 22 <import resource="classpath:alfresco/module/${project.artifactId}/context/service-context.xml" />
23 23  
24 24 </beans>
... ...
src/main/config/alfresco/module/alfresco-trashcan-cleaner/module.properties
1   -# Licensed to the Apache Software Foundation (ASF) under one or more
2   -# contributor license agreements. See the NOTICE file distributed with
3   -# this work for additional information regarding copyright ownership.
4   -# The ASF licenses this file to You under the Apache License, Version 2.0
5   -# (the "License"); you may not use this file except in compliance with
6   -# the License. You may obtain a copy of the License at
7   -#
8   -# http://www.apache.org/licenses/LICENSE-2.0
9   -#
10   -# Unless required by applicable law or agreed to in writing, software
11   -# distributed under the License is distributed on an "AS IS" BASIS,
12   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   -# See the License for the specific language governing permissions and
14   -# limitations under the License.
15   -
16   -# ==== Beginning of Alfresco required/optional properties ====== #
17 1 # NB: These properties are filtered at build time by Maven, single
18 2 # sourcing from POM properties
19 3 module.id=${project.artifactId}
20   -#module.aliases=myModule-123, my-module
21 4 module.title=${project.name}
22 5 module.description=${project.description}
23   -module.version=${project.version}
24   -
25   -# The following optional properties can be used to prevent the module from being added
26   -# to inappropriate versions of the WAR file.
27   -# module.repo.version.min=2.0
28   -# module.repo.version.max=2.1
29   -
30   -# FIXME: This dependencies should come out of mvn dependencies on amp
31   -
32   -# The following describe dependencies on other modules
33   -# Depends on net.sf.myproject.module.SupportModuleA version ${version} or later
34   -# module.depends.net.sf.myproject.module.SupportModuleA=${version}-*
35   -# Depends on net.sf.myproject.module.SupportModuleA version ${version} to 2.0
36   -# module.depends.net.sf.myproject.module.SupportModuleB=${version}-2.0
37   -# Depends on net.sf.myproject.module.SupportModuleC - any version
38   -# module.depends.net.sf.myproject.module.SupportModuleB=*
39   -
40   -
41   -# ==== End of Alfresco required/optional properties ======= #
42   -
43   -
44   -# ==== Beginning of module required properties/optional ====== #
45 6 \ No newline at end of file
  7 +module.version=${project.version}
46 8 \ No newline at end of file
... ...
src/main/java/org/alfresco/trashcan/TrashcanCleaner.java
1 1 /*
2   - * Copyright (C) 2005-2013 Alfresco Software Limited.
3   - *
4   - * This program is free software; you can redistribute it and/or
5   - * modify it under the terms of the GNU General Public License
6   - * as published by the Free Software Foundation; either version 2
7   - * of the License, or (at your option) any later version.
8   -
9   - * This program is distributed in the hope that it will be useful,
  2 + * #%L
  3 + * Alfresco Trash Can Cleaner
  4 + * %%
  5 + * Copyright (C) 2005 - 2016 Alfresco Software Limited
  6 + * %%
  7 + * This file is part of the Alfresco software.
  8 + * If the software was purchased under a paid Alfresco license, the terms of
  9 + * the paid license agreement will prevail. Otherwise, the software is
  10 + * provided under the following open source license terms:
  11 + *
  12 + * Alfresco is free software: you can redistribute it and/or modify
  13 + * it under the terms of the GNU Lesser General Public License as published by
  14 + * the Free Software Foundation, either version 3 of the License, or
  15 + * (at your option) any later version.
  16 + *
  17 + * Alfresco is distributed in the hope that it will be useful,
10 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   - * GNU General Public License for more details.
13   -
14   - * You should have received a copy of the GNU General Public License
15   - * along with this program; if not, write to the Free Software
16   - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17   -
18   - * As a special exception to the terms and conditions of version 2.0 of
19   - * the GPL, you may redistribute this Program in connection with Free/Libre
20   - * and Open Source Software ("FLOSS") applications as described in Alfresco's
21   - * FLOSS exception. You should have recieved a copy of the text describing
22   - * the FLOSS exception, and it is also available here:
23   - * http://www.alfresco.com/legal/licensing"
  20 + * GNU Lesser General Public License for more details.
  21 + *
  22 + * You should have received a copy of the GNU Lesser General Public License
  23 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  24 + * #L%
24 25 */
25 26 package org.alfresco.trashcan;
26 27  
... ...
src/main/java/org/alfresco/trashcan/TrashcanCleanerJob.java
1 1 /*
2   - * Copyright (C) 2005-2013 Alfresco Software Limited.
3   - *
4   - * This program is free software; you can redistribute it and/or
5   - * modify it under the terms of the GNU General Public License
6   - * as published by the Free Software Foundation; either version 2
7   - * of the License, or (at your option) any later version.
8   -
9   - * This program is distributed in the hope that it will be useful,
  2 + * #%L
  3 + * Alfresco Trash Can Cleaner
  4 + * %%
  5 + * Copyright (C) 2005 - 2016 Alfresco Software Limited
  6 + * %%
  7 + * This file is part of the Alfresco software.
  8 + * If the software was purchased under a paid Alfresco license, the terms of
  9 + * the paid license agreement will prevail. Otherwise, the software is
  10 + * provided under the following open source license terms:
  11 + *
  12 + * Alfresco is free software: you can redistribute it and/or modify
  13 + * it under the terms of the GNU Lesser General Public License as published by
  14 + * the Free Software Foundation, either version 3 of the License, or
  15 + * (at your option) any later version.
  16 + *
  17 + * Alfresco is distributed in the hope that it will be useful,
10 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   - * GNU General Public License for more details.
13   -
14   - * You should have received a copy of the GNU General Public License
15   - * along with this program; if not, write to the Free Software
16   - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17   -
18   - * As a special exception to the terms and conditions of version 2.0 of
19   - * the GPL, you may redistribute this Program in connection with Free/Libre
20   - * and Open Source Software ("FLOSS") applications as described in Alfresco's
21   - * FLOSS exception. You should have recieved a copy of the text describing
22   - * the FLOSS exception, and it is also available here:
23   - * http://www.alfresco.com/legal/licensing"
  20 + * GNU Lesser General Public License for more details.
  21 + *
  22 + * You should have received a copy of the GNU Lesser General Public License
  23 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  24 + * #L%
24 25 */
25 26 package org.alfresco.trashcan;
26 27  
... ...
src/test/java/org/alfresco/trashcan/TrashcanCleanerTest.java
1 1 /*
2   - * Copyright (C) 2005-2013 Alfresco Software Limited.
3   - *
4   - * This program is free software; you can redistribute it and/or
5   - * modify it under the terms of the GNU General Public License
6   - * as published by the Free Software Foundation; either version 2
7   - * of the License, or (at your option) any later version.
8   -
9   - * This program is distributed in the hope that it will be useful,
  2 + * #%L
  3 + * Alfresco Trash Can Cleaner
  4 + * %%
  5 + * Copyright (C) 2005 - 2016 Alfresco Software Limited
  6 + * %%
  7 + * This file is part of the Alfresco software.
  8 + * If the software was purchased under a paid Alfresco license, the terms of
  9 + * the paid license agreement will prevail. Otherwise, the software is
  10 + * provided under the following open source license terms:
  11 + *
  12 + * Alfresco is free software: you can redistribute it and/or modify
  13 + * it under the terms of the GNU Lesser General Public License as published by
  14 + * the Free Software Foundation, either version 3 of the License, or
  15 + * (at your option) any later version.
  16 + *
  17 + * Alfresco is distributed in the hope that it will be useful,
10 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   - * GNU General Public License for more details.
13   -
14   - * You should have received a copy of the GNU General Public License
15   - * along with this program; if not, write to the Free Software
16   - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17   -
18   - * As a special exception to the terms and conditions of version 2.0 of
19   - * the GPL, you may redistribute this Program in connection with Free/Libre
20   - * and Open Source Software ("FLOSS") applications as described in Alfresco's
21   - * FLOSS exception. You should have recieved a copy of the text describing
22   - * the FLOSS exception, and it is also available here:
23   - * http://www.alfresco.com/legal/licensing"
  20 + * GNU Lesser General Public License for more details.
  21 + *
  22 + * You should have received a copy of the GNU Lesser General Public License
  23 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  24 + * #L%
24 25 */
25 26 package org.alfresco.trashcan;
26 27  
... ... @@ -113,7 +114,8 @@ public class TrashcanCleanerTest
113 114 private void cleanBatchTest(int nodesCreate, int nodesRemain) throws Exception
114 115 {
115 116 UserTransaction userTransaction1 = transactionService.getUserTransaction();
116   - try {
  117 + try
  118 + {
117 119 userTransaction1.begin();
118 120 TrashcanCleaner cleaner = new TrashcanCleaner(nodeService, transactionService,
119 121 BATCH_SIZE, "PT1S"); // 1s
... ...
src/test/resources/log4j.properties
1   -# This is a full override of Alfresco 4.2.b log4j.properties
2   -# This file overwrites the alfresco.war log4j.properties
3   -
4 1 # Set root logger level to error
5 2 log4j.rootLogger=${app.log.root.level}, Console, File
6 3  
... ...