Author: brett Date: Tue Sep 11 22:52:25 2007 New Revision: 574791 URL: http://svn.apache.org/viewvc?rev=574791&view=rev Log: [MRM-462] restore management of remote repositories
Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java (with props) maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml (with props) Modified: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java Tue Sep 11 22:52:25 2007 @@ -0,0 +1,118 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; +import org.apache.maven.archiva.configuration.InvalidConfigurationException; +import org.apache.maven.archiva.security.ArchivaRoleConstants; +import org.codehaus.plexus.redback.rbac.Resource; +import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.registry.RegistryException; +import org.codehaus.plexus.xwork.action.PlexusActionSupport; + +import java.io.IOException; + +/** + * Base class for repository configuration actions. + */ +public class AbstractConfigureRepositoryAction + extends PlexusActionSupport + implements SecureAction +{ + /** + * @plexus.requirement + */ + protected ArchivaConfiguration archivaConfiguration; + + protected String repoid; + + // TODO! consider removing? was just meant to be for delete... + protected String mode; + + // TODO: rename to confirmDelete + public String confirm() + { + return INPUT; + } + + public String getMode() + { + return this.mode; + } + + public String getRepoid() + { + return repoid; + } + + public SecureActionBundle getSecureActionBundle() + throws SecureActionException + { + SecureActionBundle bundle = new SecureActionBundle(); + + bundle.setRequiresAuthentication( true ); + bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL ); + + return bundle; + } + + public void setMode( String mode ) + { + this.mode = mode; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; + } + + public String edit() + { + this.mode = "edit"; + + return INPUT; + } + + protected String saveConfiguration( Configuration configuration ) + throws IOException, InvalidConfigurationException, RegistryException + { + try + { + archivaConfiguration.save( configuration ); + addActionMessage( "Successfully saved configuration" ); + } + catch ( IndeterminateConfigurationException e ) + { + addActionError( e.getMessage() ); + return INPUT; + } + + return SUCCESS; + } +} Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java Tue Sep 11 22:52:25 2007 @@ -0,0 +1,207 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.opensymphony.xwork.Preparable; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.InvalidConfigurationException; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; +import org.codehaus.plexus.registry.RegistryException; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRemoteRepositoryAction" + */ +public class ConfigureRemoteRepositoryAction + extends AbstractConfigureRepositoryAction + implements Preparable +{ + /** + * The model for this action. + */ + private RemoteRepositoryConfiguration repository; + + public String add() + { + this.mode = "add"; + + return INPUT; + } + + public String delete() + { + RemoteRepositoryConfiguration existingRepository = repository; + if ( existingRepository == null ) + { + addActionError( "A repository with that id does not exist" ); + return ERROR; + } + + String result; + try + { + Configuration configuration = archivaConfiguration.getConfiguration(); + removeRepository( repoid, configuration ); + result = saveConfiguration( configuration ); + } + catch ( IOException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + catch ( InvalidConfigurationException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + catch ( RegistryException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + + return result; + } + + public RemoteRepositoryConfiguration getRepository() + { + return repository; + } + + public void prepare() + { + String id = repoid; + if ( id == null ) + { + this.repository = new RemoteRepositoryConfiguration(); + } + else + { + this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id ); + } + } + + public String save() + { + // TODO! share + String repoId = repository.getId(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + boolean containsError = validateFields( configuration ); + + if ( containsError && StringUtils.equalsIgnoreCase( "add", mode ) ) + { + return INPUT; + } + else if ( containsError && StringUtils.equalsIgnoreCase( "edit", this.mode ) ) + { + return ERROR; + } + + if ( StringUtils.equalsIgnoreCase( "edit", this.mode ) ) + { + removeRepository( repoId, configuration ); + } + + String result; + try + { + addRepository( repository, configuration ); + result = saveConfiguration( configuration ); + } + catch ( IOException e ) + { + addActionError( "I/O Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( RoleManagerException e ) + { + addActionError( "Role Manager Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( InvalidConfigurationException e ) + { + addActionError( "Invalid Configuration Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( RegistryException e ) + { + addActionError( "Configuration Registry Exception: " + e.getMessage() ); + result = INPUT; + } + + return result; + } + + private boolean validateFields( Configuration config ) + { + // TODO! share + boolean containsError = false; + String repoId = repository.getId(); + + if ( StringUtils.isBlank( repoId ) ) + { + addFieldError( "repository.id", "You must enter a repository identifier." ); + containsError = true; + } + //if edit mode, do not validate existence of repoId + else if ( ( config.getManagedRepositoriesAsMap().containsKey( repoId ) || + config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) && + !StringUtils.equalsIgnoreCase( mode, "edit" ) ) + { + addFieldError( "repository.id", + "Unable to add new repository with id [" + repoId + "], that id already exists." ); + containsError = true; + } + + if ( StringUtils.isBlank( repository.getUrl() ) ) + { + addFieldError( "repository.url", "You must enter a URL." ); + containsError = true; + } + if ( StringUtils.isBlank( repository.getName() ) ) + { + addFieldError( "repository.name", "You must enter a repository name." ); + containsError = true; + } + + return containsError; + } + + private void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration ) + throws IOException, RoleManagerException + { + configuration.addRemoteRepository( repository ); + } + + private void removeRepository( String repoId, Configuration configuration ) + { + RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId ); + if ( toremove != null ) + { + configuration.removeRemoteRepository( toremove ); + } + } +} Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java?rev=574791&r1=574790&r2=574791&view=diff ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java (original) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java Tue Sep 11 22:52:25 2007 @@ -22,21 +22,13 @@ import com.opensymphony.xwork.Preparable; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.InvalidConfigurationException; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.archiva.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; -import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; -import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; -import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.scheduler.CronExpressionValidator; -import org.codehaus.plexus.xwork.action.PlexusActionSupport; import java.io.File; import java.io.IOException; @@ -47,28 +39,18 @@ * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" */ public class ConfigureRepositoryAction - extends PlexusActionSupport - implements Preparable, SecureAction + extends AbstractConfigureRepositoryAction + implements Preparable { /** - * @plexus.requirement role-hint="default" - */ - private RoleManager roleManager; - - /** - * @plexus.requirement + * The model for this action. */ - private ArchivaConfiguration archivaConfiguration; - - private String repoid; - - // TODO! consider removing? was just meant to be for delete... - private String mode; + private AdminRepositoryConfiguration repository; /** - * The model for this action. + * @plexus.requirement role-hint="default" */ - private AdminRepositoryConfiguration repository; + protected RoleManager roleManager; public String add() { @@ -80,12 +62,6 @@ return INPUT; } - // TODO: rename to confirmDelete - public String confirm() - { - return INPUT; - } - public String delete() { String result = SUCCESS; @@ -140,39 +116,11 @@ return result; } - public String edit() - { - this.mode = "edit"; - - return INPUT; - } - - public String getMode() - { - return this.mode; - } - - public String getRepoid() - { - return repoid; - } - public AdminRepositoryConfiguration getRepository() { return repository; } - public SecureActionBundle getSecureActionBundle() - throws SecureActionException - { - SecureActionBundle bundle = new SecureActionBundle(); - - bundle.setRequiresAuthentication( true ); - bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL ); - - return bundle; - } - public void prepare() { String id = repoid; @@ -183,7 +131,6 @@ this.repository.setIndexed( false ); } - // TODO! others? ManagedRepositoryConfiguration repoconfig = archivaConfiguration.getConfiguration().findManagedRepositoryById( id ); if ( repoconfig != null ) @@ -264,7 +211,6 @@ containsError = true; } - // TODO! split if ( StringUtils.isBlank( repository.getLocation() ) ) { addFieldError( "repository.location", "You must enter a directory." ); @@ -284,16 +230,6 @@ return containsError; } - public void setMode( String mode ) - { - this.mode = mode; - } - - public void setRepoid( String repoid ) - { - this.repoid = repoid; - } - private void addRepository( AdminRepositoryConfiguration repository, Configuration configuration ) throws IOException, RoleManagerException { @@ -306,7 +242,6 @@ // TODO: error handling when this fails, or is not a directory! } - // TODO! others configuration.addManagedRepository( repository ); // TODO: double check these are configured on start up @@ -324,7 +259,6 @@ private void removeRepository( String repoId, Configuration configuration ) { - // TODO! what about others? ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId ); if ( toremove != null ) { @@ -341,31 +275,8 @@ getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() ); } - private String saveConfiguration( Configuration configuration ) - throws IOException, InvalidConfigurationException, RegistryException - { - try - { - archivaConfiguration.save( configuration ); - addActionMessage( "Successfully saved configuration" ); - } - catch ( IndeterminateConfigurationException e ) - { - addActionError( e.getMessage() ); - return INPUT; - } - - return SUCCESS; - } - public void setRoleManager( RoleManager roleManager ) { this.roleManager = roleManager; } - - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) - { - this.archivaConfiguration = archivaConfiguration; - } - } Modified: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml?rev=574791&r1=574790&r2=574791&view=diff ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml (original) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml Tue Sep 11 22:52:25 2007 @@ -254,6 +254,32 @@ <interceptor-ref name="configuredPrepareParamsStack"/> </action> + <action name="addRemoteRepository" class="configureRemoteRepositoryAction" method="add"> + <result name="input">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result> + <result name="success" type="redirect-action">repositories</result> + <interceptor-ref name="configuredPrepareParamsStack"/> + </action> + + <action name="editRemoteRepository" class="configureRemoteRepositoryAction" method="edit"> + <result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result> + <result name="error" type="redirect-action">repositories</result> + <result name="success" type="redirect-action">repositories</result> + <interceptor-ref name="configuredPrepareParamsStack"/> + </action> + + <action name="saveRemoteRepository" class="configureRemoteRepositoryAction" method="save"> + <result name="success" type="redirect-action">repositories</result> + <result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result> + <result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result> + <interceptor-ref name="configuredPrepareParamsStack"/> + </action> + + <action name="deleteRemoteRepository" class="configureRemoteRepositoryAction" method="confirm"> + <result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result> + <result name="success" type="redirect-action">repositories</result> + <interceptor-ref name="configuredPrepareParamsStack"/> + </action> + <!-- .\ PROXY CONNECTORS \.________________________________________ --> <action name="proxyConnectors" class="proxyConnectorsAction" method="input"> Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp Tue Sep 11 22:52:25 2007 @@ -0,0 +1,51 @@ +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + +<html> +<head> + <title>Admin: Add Repository</title> + <ww:head/> +</head> + +<body> + +<h1>Admin: Add Repository</h1> + +<div id="contentArea"> + + <h2>Add Repository</h2> + + <ww:actionmessage/> + <ww:form method="post" action="saveRemoteRepository" namespace="/admin" validate="true"> + <ww:hidden name="mode" value="add"/> + <ww:textfield name="repository.id" label="Identifier" size="10" required="true"/> + <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> + <ww:submit value="Add Repository"/> + </ww:form> + + <script type="text/javascript"> + document.getElementById("saveRemoteRepository_id").focus(); + </script> + +</div> + +</body> +</html> Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp Tue Sep 11 22:52:25 2007 @@ -0,0 +1,54 @@ +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + +<html> +<head> + <title>Admin: Delete Repository</title> + <ww:head/> +</head> + +<body> + +<h1>Admin: Delete Repository</h1> + +<ww:actionerror/> + +<div id="contentArea"> + + <h2>Delete Repository</h2> + + <blockquote> + <strong><span class="statusFailed">WARNING:</span> This operation can not be undone.</strong> + </blockquote> + + <p> + Are you sure you want to delete the repository <code>[ ${repoid} ]</code> ? + </p> + + <ww:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true"> + <ww:hidden name="repoid"/> + <ww:submit value="Confirm" method="delete"/> + <ww:submit value="Cancel" method="execute"/> + </ww:form> +</div> + +</body> +</html> \ No newline at end of file Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp Tue Sep 11 22:52:25 2007 @@ -0,0 +1,53 @@ +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + +<html> +<head> + <title>Admin: Edit Repository</title> + <ww:head/> +</head> + +<body> + +<h1>Admin: Edit Repository</h1> + +<ww:actionerror/> + +<div id="contentArea"> + + <h2>Edit Repository</h2> + + <ww:actionmessage/> + <ww:form method="post" action="saveRemoteRepository" namespace="/admin" validate="false"> + <ww:hidden name="mode" value="edit"/> + <ww:hidden name="repository.id"/> + <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> + <ww:submit value="Update Repository"/> + </ww:form> + + <script type="text/javascript"> + document.getElementById("saveRemoteRepository_repository_name").focus(); + </script> + +</div> + +</body> +</html> \ No newline at end of file Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf Tue Sep 11 22:52:25 2007 @@ -0,0 +1,25 @@ +<%-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + +<ww:textfield name="repository.name" label="Name" size="50" required="true"/> +<ww:textfield name="repository.url" label="URL" size="50" required="true"/> +<ww:select list="[EMAIL PROTECTED]@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}" + name="repository.layout" label="Type"/> Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf ------------------------------------------------------------------------------ svn:eol-style = native Modified: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp?rev=574791&r1=574790&r2=574791&view=diff ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp (original) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp Tue Sep 11 22:52:25 2007 @@ -43,7 +43,7 @@ <ww:url id="addRepositoryUrl" action="addRepository"/> <ww:a href="%{addRepositoryUrl}"> <img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/> - Add Repository + Add </ww:a> </redback:ifAuthorized> </div> @@ -80,11 +80,11 @@ </ww:url> <ww:a href="%{editRepositoryUrl}"> <img src="<c:url value="/images/icons/edit.png" />" alt="" width="16" height="16"/> - Edit Repository + Edit </ww:a> <ww:a href="%{deleteRepositoryUrl}"> <img src="<c:url value="/images/icons/delete.gif" />" alt="" width="16" height="16"/> - Delete Repository + Delete </ww:a> </redback:ifAnyAuthorized> </div> @@ -226,6 +226,15 @@ </c:otherwise> </c:choose> +<div class="controls"> + <redback:ifAuthorized permission="archiva-manage-configuration"> + <ww:url id="addRepositoryUrl" action="addRemoteRepository"/> + <ww:a href="%{addRepositoryUrl}"> + <img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/> + Add + </ww:a> + </redback:ifAuthorized> +</div> <h2>Remote Repositories</h2> <c:choose> @@ -235,7 +244,6 @@ </c:when> <c:otherwise> <%-- Display the repositories. --%> - <c:forEach items="${remoteRepositories}" var="repository" varStatus="i"> <c:choose> <c:when test='${(i.index)%2 eq 0}'> @@ -250,19 +258,19 @@ <div class="controls"> <redback:ifAnyAuthorized permissions="archiva-manage-configuration"> - <ww:url id="editRepositoryUrl" action="editRepository"> + <ww:url id="editRepositoryUrl" action="editRemoteRepository"> <ww:param name="repoid" value="%{'${repository.id}'}"/> </ww:url> - <ww:url id="deleteRepositoryUrl" action="deleteRepository" method="confirm"> + <ww:url id="deleteRepositoryUrl" action="deleteRemoteRepository" method="confirm"> <ww:param name="repoid" value="%{'${repository.id}'}"/> </ww:url> <ww:a href="%{editRepositoryUrl}"> <img src="<c:url value="/images/icons/edit.png" />" alt="" width="16" height="16"/> - Edit Repository + Edit </ww:a> <ww:a href="%{deleteRepositoryUrl}"> <img src="<c:url value="/images/icons/delete.gif" />" alt="" width="16" height="16"/> - Delete Repository + Delete </ww:a> </redback:ifAnyAuthorized> </div> Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java Tue Sep 11 22:52:25 2007 @@ -0,0 +1,299 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import com.opensymphony.xwork.Action; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.registry.RegistryException; +import org.easymock.MockControl; + +import java.util.Collections; + +/** + * Test the repositories action returns the correct data. + */ +public class ConfigureRemoteRepositoryActionTest + extends PlexusTestCase +{ + private ConfigureRemoteRepositoryAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private static final String REPO_ID = "remote-repo-ident"; + + protected void setUp() + throws Exception + { + super.setUp(); + + // TODO: purely to quiet logging - shouldn't be needed + String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath(); + System.setProperty( "appserver.base", appserverBase ); + action = (ConfigureRemoteRepositoryAction) lookup( Action.class.getName(), "configureRemoteRepositoryAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + + public void testSecureActionBundle() + throws SecureActionException + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + SecureActionBundle bundle = action.getSecureActionBundle(); + assertTrue( bundle.requiresAuthentication() ); + assertEquals( 1, bundle.getAuthorizationTuples().size() ); + } + + public void testAddRemoteRepositoryInitialPage() + throws Exception + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + assertNull( action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration configuration = action.getRepository(); + assertNotNull( configuration ); + assertNull( configuration.getId() ); + + String status = action.add(); + assertEquals( Action.INPUT, status ); + } + + public void testAddRemoteRepository() + throws Exception + { + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + action.setMode( "add" ); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + + String status = action.save(); + assertEquals( Action.SUCCESS, status ); + + assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); + + archivaConfigurationControl.verify(); + } + + public void testEditRemoteRepositoryInitialPage() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.edit(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + } + + public void testEditRemoteRepository() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + action.setMode( "edit" ); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + repository.setName( "new repo name" ); + + String status = action.save(); + assertEquals( Action.SUCCESS, status ); + + RemoteRepositoryConfiguration newRepository = createRepository(); + newRepository.setName( "new repo name" ); + assertRepositoryEquals( repository, newRepository ); + assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); + + archivaConfigurationControl.verify(); + } + + public void testDeleteRemoteRepositoryConfirmation() + { + RemoteRepositoryConfiguration originalRepository = createRepository(); + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.confirm(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); + } + + public void testDeleteRemoteRepositoryKeepContent() + throws RegistryException, IndeterminateConfigurationException + { + Configuration configuration = executeDeletionTest( "delete-entry", createRepository() ); + + assertTrue( configuration.getRemoteRepositories().isEmpty() ); + } + + public void testDeleteRemoteRepositoryCancelled() + throws Exception + { + RemoteRepositoryConfiguration originalRepository = createRepository(); + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.setMode( "unmodified" ); // TODO! remove + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertEquals( "unmodified", action.getMode() ); + RemoteRepositoryConfiguration repositoryConfiguration = action.getRepository(); + assertNotNull( repositoryConfiguration ); + assertRepositoryEquals( repositoryConfiguration, createRepository() ); + + String status = action.execute(); + assertEquals( Action.SUCCESS, status ); + + RemoteRepositoryConfiguration repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); + } + + private Configuration executeDeletionTest( String mode, RemoteRepositoryConfiguration originalRepository ) + throws RegistryException, IndeterminateConfigurationException + { + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.setMode( mode ); // TODO! remove + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertEquals( mode, action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.delete(); + assertEquals( Action.SUCCESS, status ); + return configuration; + } + + private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository, + RemoteRepositoryConfiguration actualRepository ) + { + assertEquals( expectedRepository.getId(), actualRepository.getId() ); + assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() ); + assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() ); + assertEquals( expectedRepository.getName(), actualRepository.getName() ); + } + + private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration ) + { + Configuration configuration = new Configuration(); + configuration.addRemoteRepository( repositoryConfiguration ); + return configuration; + } + + private RemoteRepositoryConfiguration createRepository() + { + RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration(); + r.setId( REPO_ID ); + populateRepository( r ); + return r; + } + + private void populateRepository( RemoteRepositoryConfiguration repository ) + { + repository.setId( REPO_ID ); + repository.setName( "repo name" ); + repository.setUrl( "url" ); + repository.setLayout( "default" ); + } + + // TODO: test errors during add, other actions + // TODO: what if there are proxy connectors attached to a deleted repository? + // TODO: what about removing proxied content if a proxy is removed? +} Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml URL: http://svn.apache.org/viewvc/maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml?rev=574791&view=auto ============================================================================== --- maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml (added) +++ maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml Tue Sep 11 22:52:25 2007 @@ -0,0 +1,35 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<plexus> + <components> + <component> + <role>org.codehaus.plexus.logging.LoggerManager</role> + <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation> + <lifecycle-handler>basic</lifecycle-handler> + </component> + <component> + <role>com.opensymphony.xwork.Action</role> + <role-hint>configureRemoteRepositoryAction</role-hint> + <implementation>org.apache.maven.archiva.web.action.admin.repositories.ConfigureRemoteRepositoryAction + </implementation> + <instantiation-strategy>per-lookup</instantiation-strategy> + </component> + </components> +</plexus> Propchange: maven/archiva/branches/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml ------------------------------------------------------------------------------ svn:eol-style = native