View Javadoc

1   package org.apache.continuum.purge.controller;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.model.repository.AbstractPurgeConfiguration;
23  import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
24  import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
25  import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
26  import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
27  import org.apache.continuum.purge.executor.DaysOldDirectoryPurgeExecutor;
28  import org.apache.continuum.purge.executor.RetentionCountDirectoryPurgeExecutor;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  /**
33   * DirectoryPurgeController
34   *
35   * @author Maria Catherine Tan
36   * @plexus.component role="org.apache.continuum.purge.controller.PurgeController" role-hint="purge-directory"
37   */
38  public class DirectoryPurgeController
39      implements PurgeController
40  {
41      private static final Logger log = LoggerFactory.getLogger( DirectoryPurgeController.class );
42  
43      private ContinuumPurgeExecutor purgeExecutor;
44  
45      public void doPurge( String path )
46      {
47          try
48          {
49              purgeExecutor.purge( path );
50          }
51          catch ( ContinuumPurgeExecutorException e )
52          {
53              log.error( e.getMessage(), e );
54          }
55      }
56  
57      public void initializeExecutors( AbstractPurgeConfiguration purgeConfig )
58          throws ContinuumPurgeExecutorException
59      {
60          DirectoryPurgeConfiguration dirPurge = (DirectoryPurgeConfiguration) purgeConfig;
61  
62          if ( dirPurge.isDeleteAll() )
63          {
64              purgeExecutor = new CleanAllPurgeExecutor( dirPurge.getDirectoryType() );
65          }
66          else if ( dirPurge.getDaysOlder() > 0 )
67          {
68              purgeExecutor = new DaysOldDirectoryPurgeExecutor( dirPurge.getDaysOlder(), dirPurge.getRetentionCount(),
69                                                                 dirPurge.getDirectoryType() );
70          }
71          else
72          {
73              purgeExecutor =
74                  new RetentionCountDirectoryPurgeExecutor( dirPurge.getRetentionCount(), dirPurge.getDirectoryType() );
75          }
76      }
77  }