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.xwork2.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.apache.maven.archiva.web.action.PlexusActionSupport;
32 import org.codehaus.plexus.redback.rbac.Resource;
33 import org.codehaus.plexus.registry.RegistryException;
35 import java.util.Collections;
36 import java.util.List;
37 import org.codehaus.redback.integration.interceptor.SecureAction;
38 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
39 import org.codehaus.redback.integration.interceptor.SecureActionException;
45 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="databaseAction" instantiation-strategy="per-lookup"
47 public class DatabaseAction
48 extends PlexusActionSupport
49 implements Preparable, SecureAction
54 private ArchivaConfiguration archivaConfiguration;
59 private DatabaseConsumers databaseConsumers;
64 * List of available {@link AdminDatabaseConsumer} objects for unprocessed artifacts.
66 private List unprocessedConsumers;
69 * List of enabled {@link AdminDatabaseConsumer} objects for unprocessed artifacts.
71 private List enabledUnprocessedConsumers;
74 * List of {@link AdminDatabaseConsumer} objects for "to cleanup" artifacts.
76 private List cleanupConsumers;
79 * List of enabled {@link AdminDatabaseConsumer} objects for "to cleanup" artifacts.
81 private List enabledCleanupConsumers;
86 Configuration config = archivaConfiguration.getConfiguration();
87 DatabaseScanningConfiguration dbscanning = config.getDatabaseScanning();
89 this.cron = dbscanning.getCronExpression();
91 AddAdminDatabaseConsumerClosure addAdminDbConsumer;
93 addAdminDbConsumer = new AddAdminDatabaseConsumerClosure( dbscanning.getUnprocessedConsumers() );
94 CollectionUtils.forAllDo( databaseConsumers.getAvailableUnprocessedConsumers(), addAdminDbConsumer );
95 this.unprocessedConsumers = addAdminDbConsumer.getList();
96 Collections.sort( this.unprocessedConsumers, AdminRepositoryConsumerComparator.getInstance() );
98 addAdminDbConsumer = new AddAdminDatabaseConsumerClosure( dbscanning.getCleanupConsumers() );
99 CollectionUtils.forAllDo( databaseConsumers.getAvailableCleanupConsumers(), addAdminDbConsumer );
100 this.cleanupConsumers = addAdminDbConsumer.getList();
101 Collections.sort( this.cleanupConsumers, AdminRepositoryConsumerComparator.getInstance() );
104 public String updateUnprocessedConsumers()
106 archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers(
107 enabledUnprocessedConsumers );
109 return saveConfiguration();
112 public String updateCleanupConsumers()
114 archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers );
116 return saveConfiguration();
119 public String updateSchedule()
121 archivaConfiguration.getConfiguration().getDatabaseScanning().setCronExpression( cron );
123 return saveConfiguration();
126 private String saveConfiguration()
130 archivaConfiguration.save( archivaConfiguration.getConfiguration() );
131 addActionMessage( "Successfully saved configuration" );
133 catch ( RegistryException e )
135 log.error( e.getMessage(), e );
136 addActionError( "Error in saving configuration" );
139 catch ( IndeterminateConfigurationException e )
141 addActionError( e.getMessage() );
148 public SecureActionBundle getSecureActionBundle()
149 throws SecureActionException
151 SecureActionBundle bundle = new SecureActionBundle();
153 bundle.setRequiresAuthentication( true );
154 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
159 public String getCron()
164 public void setCron( String cron )
169 public List getCleanupConsumers()
171 return cleanupConsumers;
174 public List getUnprocessedConsumers()
176 return unprocessedConsumers;
179 public List getEnabledUnprocessedConsumers()
181 return enabledUnprocessedConsumers;
184 public void setEnabledUnprocessedConsumers( List enabledUnprocessedConsumers )
186 this.enabledUnprocessedConsumers = enabledUnprocessedConsumers;
189 public List getEnabledCleanupConsumers()
191 return enabledCleanupConsumers;
194 public void setEnabledCleanupConsumers( List enabledCleanupConsumers )
196 this.enabledCleanupConsumers = enabledCleanupConsumers;