1 package org.apache.maven.archiva.web.action.admin;
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.ModelDriven;
23 import com.opensymphony.xwork.Preparable;
24 import com.opensymphony.xwork.Validateable;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
29 import org.apache.maven.archiva.indexer.RepositoryIndexException;
30 import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
31 import org.apache.maven.archiva.repositories.ActiveManagedRepositories;
32 import org.apache.maven.archiva.security.ArchivaRoleConstants;
33 import org.codehaus.plexus.registry.RegistryException;
34 import org.codehaus.plexus.scheduler.CronExpressionValidator;
35 import org.codehaus.plexus.security.rbac.Resource;
36 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
37 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
38 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
39 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
42 import java.io.IOException;
43 import java.util.Date;
46 * Configures the application.
48 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureAction"
50 public class ConfigureAction
51 extends PlexusActionSupport
52 implements ModelDriven, Preparable, Validateable, SecureAction
57 private ArchivaConfiguration archivaConfiguration;
62 private ActiveManagedRepositories activeRepositories;
67 private Configuration configuration;
69 private CronExpressionValidator cronValidator;
71 private String second = "0";
73 private String minute = "0";
75 private String hour = "*";
77 private String dayOfMonth = "*";
79 private String month = "*";
81 private String dayOfWeek = "?";
85 private String lastIndexingTime;
87 public void validate()
89 //validate cron expression
90 cronValidator = new CronExpressionValidator();
92 if ( !cronValidator.validate( getCronExpression() ) )
94 addActionError( "Invalid Cron Expression" );
98 public String execute()
99 throws IOException, RepositoryIndexException, RepositoryIndexSearchException, InvalidConfigurationException,
102 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
103 // TODO: if this is changed, do we move the index or recreate it?
104 configuration.setDataRefreshCronExpression( getCronExpression() );
106 // Normalize the path
107 File file = new File( configuration.getIndexPath() );
108 configuration.setIndexPath( file.getCanonicalPath() );
109 if ( !file.exists() )
112 // TODO: error handling when this fails, or is not a directory!
115 // Just double checking that our validation routines line up with what is expected in the configuration
116 assert configuration.isValid();
118 archivaConfiguration.save( configuration );
120 // TODO: if the repository has changed, we need to check if indexing is needed!
122 addActionMessage( "Successfully saved configuration" );
127 public String input()
129 String[] cronEx = configuration.getDataRefreshCronExpression().split( " " );
132 while ( i < cronEx.length )
146 dayOfMonth = cronEx[i];
152 dayOfWeek = cronEx[i];
161 if ( activeRepositories.getLastDataRefreshTime() != 0 )
163 lastIndexingTime = new Date( activeRepositories.getLastDataRefreshTime() ).toString();
167 lastIndexingTime = "Never been run.";
173 public Object getModel()
175 return configuration;
178 public void prepare()
180 configuration = archivaConfiguration.getConfiguration();
183 public String getLastIndexingTime()
185 return lastIndexingTime;
188 public void setLastIndexingTime( String lastIndexingTime )
190 this.lastIndexingTime = lastIndexingTime;
193 public String getSecond()
198 public void setSecond( String second )
200 this.second = second;
203 public String getMinute()
208 public void setMinute( String minute )
210 this.minute = minute;
213 public String getHour()
218 public void setHour( String hour )
223 public String getDayOfMonth()
228 public void setDayOfMonth( String dayOfMonth )
230 this.dayOfMonth = dayOfMonth;
233 public String getYear()
238 public void setYear( String year )
243 public String getMonth()
248 public void setMonth( String month )
253 public String getDayOfWeek()
258 public void setDayOfWeek( String dayOfWeek )
260 this.dayOfWeek = dayOfWeek;
263 private String getCronExpression()
265 return ( second + " " + minute + " " + hour + " " + dayOfMonth + " " + month + " " + dayOfWeek + " " +
269 public SecureActionBundle getSecureActionBundle()
270 throws SecureActionException
272 SecureActionBundle bundle = new SecureActionBundle();
274 bundle.setRequiresAuthentication( true );
275 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );