From d6ddac89f31929a0e699aca7ec8a5ccdf51a532a Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Thu, 5 Jun 2008 23:50:57 +0000 Subject: [PATCH] [MRM-789] -added confirmation page before saving a new or updated managed repo if the repo location already exists -added tests git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@663788 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractManagedRepositoriesAction.java | 2 + .../AddManagedRepositoryAction.java | 33 ++++- .../EditManagedRepositoryAction.java | 33 ++++- .../src/main/resources/xwork.xml | 2 + .../jsp/admin/confirmAddRepository.jsp | 135 ++++++++++++++++++ .../AddManagedRepositoryActionTest.java | 18 +++ .../EditManagedRepositoryActionTest.java | 3 +- 7 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java index f15ca0542..7fc658676 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java @@ -45,6 +45,8 @@ public abstract class AbstractManagedRepositoriesAction */ protected RoleManager roleManager; + public static final String CONFIRM = "confirm"; + public RoleManager getRoleManager() { return roleManager; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java index 6d5a0bb7b..919bce071 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -26,7 +26,7 @@ import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.scheduler.CronExpressionValidator; - +import java.io.File; import java.io.IOException; /** @@ -45,6 +45,8 @@ public class AddManagedRepositoryAction * The model for this action. */ private ManagedRepositoryConfiguration repository; + + private String action = "addRepository"; public void prepare() { @@ -60,11 +62,27 @@ public class AddManagedRepositoryAction return INPUT; } - + + public String confirmAdd() + { + return save(); + } + public String commit() + { + File location = new File( repository.getLocation() ); + if( location.exists() ) + { + return CONFIRM; + } + + return save(); + } + + private String save() { Configuration configuration = archivaConfiguration.getConfiguration(); - + String result; try { @@ -73,12 +91,12 @@ public class AddManagedRepositoryAction result = saveConfiguration( configuration ); } catch ( RoleManagerException e ) - { + { addActionError( "Role Manager Exception: " + e.getMessage() ); result = INPUT; } catch ( IOException e ) - { + { addActionError( "Role Manager Exception: " + e.getMessage() ); result = INPUT; } @@ -125,4 +143,9 @@ public class AddManagedRepositoryAction { this.repository = repository; } + + public String getAction() + { + return action; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index ade35bb7f..86817bab6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -28,6 +28,7 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.scheduler.CronExpressionValidator; +import java.io.File; import java.io.IOException; /** @@ -48,6 +49,8 @@ public class EditManagedRepositoryAction private ManagedRepositoryConfiguration repository; private String repoid; + + private final String action = "editRepository"; public void prepare() { @@ -73,11 +76,34 @@ public class EditManagedRepositoryAction return INPUT; } + public String confirmUpdate() + { + return save(); + } + public String commit() + { + ManagedRepositoryConfiguration existingConfig = + archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() ); + + // check if the location was changed + if( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) ) + { + File dir = new File( repository.getLocation() ); + if( dir.exists() ) + { + return CONFIRM; + } + } + + return save(); + } + + private String save() { // Ensure that the fields are valid. Configuration configuration = archivaConfiguration.getConfiguration(); - + // We are in edit mode, remove the old repository configuration. removeRepository( repository.getId(), configuration ); @@ -133,4 +159,9 @@ public class EditManagedRepositoryAction { this.repository = repository; } + + public String getAction() + { + return action; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml index ea788ef62..c85744f25 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -291,6 +291,7 @@ /WEB-INF/jsp/admin/addRepository.jsp /WEB-INF/jsp/admin/addRepository.jsp + /WEB-INF/jsp/admin/confirmAddRepository.jsp repositories @@ -299,6 +300,7 @@ /WEB-INF/jsp/admin/editRepository.jsp /WEB-INF/jsp/admin/editRepository.jsp repositories + /WEB-INF/jsp/admin/confirmAddRepository.jsp diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp new file mode 100644 index 000000000..270b90591 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp @@ -0,0 +1,135 @@ +<%-- + ~ 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" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Admin: Add Managed Repository + + + + + +

Admin: Add Managed Repository

+ +
+

+ WARNING: Repository location already exists. +

+
+ +

+ Are you sure you want to ${action == 'addRepository' ? 'add' : 'update'} the following managed repository? +

+ +
+ + + + + + + + + + + + + + + + + + + + <%--td>${repository.layout} + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID:${repository.id}
Name:${repository.name}
Directory:${repository.location}
Index Directory:${repository.indexDir}
Type: + + + Maven 2.x Repository + + + Maven 1.x Repository + + +
Cron:${repository.refreshCronExpression}
Repository Purge By Days Older Than:${repository.daysOlder}
Repository Purge By Retention Count:${repository.retentionCount}
Releases Included: +
Snapshots Included: +
Scannable: +
Delete Released Snapshots: +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java index ed0501636..beaafba67 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -159,6 +159,24 @@ public class AddManagedRepositoryActionTest archivaConfigurationControl.verify(); } + + public void testAddRepositoryExistingLocation() + throws Exception + { + if( !location.exists() ) + { + location.mkdirs(); + } + + action.prepare(); + ManagedRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + + assertTrue( location.exists() ); + String status = action.commit(); + assertEquals( AddManagedRepositoryAction.CONFIRM, status ); + } + private void populateRepository( ManagedRepositoryConfiguration repository ) { repository.setId( REPO_ID ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index 57f30a44e..5c944f8d6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -134,6 +134,7 @@ public class EditManagedRepositoryActionTest archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration ); archivaConfiguration.save( configuration ); @@ -157,7 +158,7 @@ public class EditManagedRepositoryActionTest roleManagerControl.verify(); archivaConfigurationControl.verify(); } - + private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, ManagedRepositoryConfiguration actualRepository ) { -- 2.39.5