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( AbstractPurgeConfiguration purgeConfig )
46      {
47          DirectoryPurgeConfiguration dirPurge = (DirectoryPurgeConfiguration) purgeConfig;
48          doPurge( dirPurge.getLocation() );
49      }
50  
51      public void doPurge( String path )
52      {
53          log.info( "--- Start: Purging directory path '{}'---", path );
54          try
55          {
56              purgeExecutor.purge( path );
57          }
58          catch ( ContinuumPurgeExecutorException e )
59          {
60              log.error( e.getMessage(), e );
61          }
62          log.info( "--- End: Purging directory path '{}'---", path );
63      }
64  
65      public void initializeExecutors( AbstractPurgeConfiguration purgeConfig )
66          throws ContinuumPurgeExecutorException
67      {
68          DirectoryPurgeConfiguration dirPurge = (DirectoryPurgeConfiguration) purgeConfig;
69  
70          if ( dirPurge.isDeleteAll() )
71          {
72              purgeExecutor = new CleanAllPurgeExecutor( dirPurge.getDirectoryType() );
73          }
74          else if ( dirPurge.getDaysOlder() > 0 )
75          {
76              purgeExecutor = new DaysOldDirectoryPurgeExecutor( dirPurge.getDaysOlder(), dirPurge.getRetentionCount(),
77                                                                 dirPurge.getDirectoryType() );
78          }
79          else
80          {
81              purgeExecutor = new RetentionCountDirectoryPurgeExecutor( dirPurge.getRetentionCount(),
82                                                                        dirPurge.getDirectoryType() );
83          }
84      }
85  }