1 package org.apache.maven.archiva.web.action.admin.database;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.opensymphony.xwork.Preparable;
23 import org.apache.commons.collections.CollectionUtils;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
27 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
28 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
29 import org.apache.maven.archiva.security.ArchivaRoleConstants;
30 import org.apache.maven.archiva.web.action.admin.scanning.AdminRepositoryConsumerComparator;
31 import org.codehaus.plexus.redback.rbac.Resource;
32 import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
33 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
34 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
35 import org.codehaus.plexus.registry.RegistryException;
36 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
38 import java.util.Collections;
39 import java.util.List;
44 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
46 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="databaseAction"
48 public class DatabaseAction
49 extends PlexusActionSupport
50 implements Preparable, SecureAction
55 private ArchivaConfiguration archivaConfiguration;
60 private DatabaseConsumers databaseConsumers;
65 * List of available {@link AdminDatabaseConsumer} objects for unprocessed artifacts.
67 private List unprocessedConsumers;
70 * List of enabled {@link AdminDatabaseConsumer} objects for unprocessed artifacts.
72 private List enabledUnprocessedConsumers;
75 * List of {@link AdminDatabaseConsumer} objects for "to cleanup" artifacts.
77 private List cleanupConsumers;
80 * List of enabled {@link AdminDatabaseConsumer} objects for "to cleanup" artifacts.
82 private List enabledCleanupConsumers;
87 Configuration config = archivaConfiguration.getConfiguration();
88 DatabaseScanningConfiguration dbscanning = config.getDatabaseScanning();
90 this.cron = dbscanning.getCronExpression();
92 AddAdminDatabaseConsumerClosure addAdminDbConsumer;
94 addAdminDbConsumer = new AddAdminDatabaseConsumerClosure( dbscanning.getUnprocessedConsumers() );
95 CollectionUtils.forAllDo( databaseConsumers.getAvailableUnprocessedConsumers(), addAdminDbConsumer );
96 this.unprocessedConsumers = addAdminDbConsumer.getList();
97 Collections.sort( this.unprocessedConsumers, AdminRepositoryConsumerComparator.getInstance() );
99 addAdminDbConsumer = new AddAdminDatabaseConsumerClosure( dbscanning.getCleanupConsumers() );
100 CollectionUtils.forAllDo( databaseConsumers.getAvailableCleanupConsumers(), addAdminDbConsumer );
101 this.cleanupConsumers = addAdminDbConsumer.getList();
102 Collections.sort( this.cleanupConsumers, AdminRepositoryConsumerComparator.getInstance() );
105 public String updateUnprocessedConsumers()
107 archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers(
108 enabledUnprocessedConsumers );
110 return saveConfiguration();
113 public String updateCleanupConsumers()
115 archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers );
117 return saveConfiguration();
120 public String updateSchedule()
122 archivaConfiguration.getConfiguration().getDatabaseScanning().setCronExpression( cron );
124 return saveConfiguration();
127 private String saveConfiguration()
131 archivaConfiguration.save( archivaConfiguration.getConfiguration() );
132 addActionMessage( "Successfully saved configuration" );
134 catch ( RegistryException e )
136 getLogger().error( e.getMessage(), e );
137 addActionError( "Error in saving configuration" );
140 catch ( IndeterminateConfigurationException e )
142 addActionError( e.getMessage() );
149 public SecureActionBundle getSecureActionBundle()
150 throws SecureActionException
152 SecureActionBundle bundle = new SecureActionBundle();
154 bundle.setRequiresAuthentication( true );
155 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
160 public String getCron()
165 public void setCron( String cron )
170 public List getCleanupConsumers()
172 return cleanupConsumers;
175 public List getUnprocessedConsumers()
177 return unprocessedConsumers;
180 public List getEnabledUnprocessedConsumers()
182 return enabledUnprocessedConsumers;
185 public void setEnabledUnprocessedConsumers( List enabledUnprocessedConsumers )
187 this.enabledUnprocessedConsumers = enabledUnprocessedConsumers;
190 public List getEnabledCleanupConsumers()
192 return enabledCleanupConsumers;
195 public void setEnabledCleanupConsumers( List enabledCleanupConsumers )
197 this.enabledCleanupConsumers = enabledCleanupConsumers;