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;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
28 import org.apache.maven.archiva.indexer.RepositoryIndexException;
29 import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
30 import org.apache.maven.archiva.scheduler.executors.IndexerTaskExecutor;
31 import org.apache.maven.archiva.security.ArchivaRoleConstants;
32 import org.codehaus.plexus.registry.RegistryException;
33 import org.codehaus.plexus.scheduler.CronExpressionValidator;
34 import org.codehaus.plexus.security.rbac.Resource;
35 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
36 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
37 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
38 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
41 import java.io.IOException;
42 import java.util.Date;
45 * Configures the application.
47 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureAction"
49 public class ConfigureAction
50 extends PlexusActionSupport
51 implements ModelDriven, Preparable, Validateable, SecureAction
56 private ArchivaConfiguration archivaConfiguration;
59 * @plexus.requirement role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" role-hint="indexer"
61 private IndexerTaskExecutor indexer;
66 private Configuration configuration;
68 private CronExpressionValidator cronValidator;
70 private String second = "0";
72 private String minute = "0";
74 private String hour = "*";
76 private String dayOfMonth = "*";
78 private String month = "*";
80 private String dayOfWeek = "?";
84 private String lastIndexingTime;
86 public void validate()
88 //validate cron expression
89 cronValidator = new CronExpressionValidator();
91 if ( !cronValidator.validate( getCronExpression() ) )
93 addActionError( "Invalid Cron Expression" );
97 public String execute()
98 throws IOException, RepositoryIndexException, RepositoryIndexSearchException, InvalidConfigurationException,
101 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
102 // TODO: if this is changed, do we move the index or recreate it?
103 configuration.setIndexerCronExpression( getCronExpression() );
105 // Normalize the path
106 File file = new File( configuration.getIndexPath() );
107 configuration.setIndexPath( file.getCanonicalPath() );
108 if ( !file.exists() )
111 // TODO: error handling when this fails, or is not a directory!
114 // Just double checking that our validation routines line up with what is expected in the configuration
115 assert configuration.isValid();
117 archivaConfiguration.save( configuration );
119 // TODO: if the repository has changed, we need to check if indexing is needed!
121 addActionMessage( "Successfully saved configuration" );
126 public String input()
128 String[] cronEx = configuration.getIndexerCronExpression().split( " " );
131 while ( i < cronEx.length )
145 dayOfMonth = cronEx[i];
151 dayOfWeek = cronEx[i];
160 if ( indexer.getLastIndexingTime() != 0 )
162 lastIndexingTime = new Date( indexer.getLastIndexingTime() ).toString();
166 lastIndexingTime = "Never been run.";
172 public Object getModel()
174 return configuration;
177 public void prepare()
179 configuration = archivaConfiguration.getConfiguration();
182 public String getLastIndexingTime()
184 return lastIndexingTime;
187 public void setLastIndexingTime( String lastIndexingTime )
189 this.lastIndexingTime = lastIndexingTime;
192 public String getSecond()
197 public void setSecond( String second )
199 this.second = second;
202 public String getMinute()
207 public void setMinute( String minute )
209 this.minute = minute;
212 public String getHour()
217 public void setHour( String hour )
222 public String getDayOfMonth()
227 public void setDayOfMonth( String dayOfMonth )
229 this.dayOfMonth = dayOfMonth;
232 public String getYear()
237 public void setYear( String year )
242 public String getMonth()
247 public void setMonth( String month )
252 public String getDayOfWeek()
257 public void setDayOfWeek( String dayOfWeek )
259 this.dayOfWeek = dayOfWeek;
262 private String getCronExpression()
264 return ( second + " " + minute + " " + hour + " " + dayOfMonth + " " + month + " " + dayOfWeek + " " +
268 public SecureActionBundle getSecureActionBundle()
269 throws SecureActionException
271 SecureActionBundle bundle = new SecureActionBundle();
273 bundle.setRequiresAuthentication( true );
274 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );