]> source.dussan.org Git - archiva.git/commitdiff
[MRM-789]
authorMaria Odea B. Ching <oching@apache.org>
Thu, 5 Jun 2008 23:50:57 +0000 (23:50 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Thu, 5 Jun 2008 23:50:57 +0000 (23:50 +0000)
-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

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java

index f15ca054243eebdb44c2108b925153070b26c5bc..7fc658676075c56f08af18d0edc0b60925b7b762 100644 (file)
@@ -45,6 +45,8 @@ public abstract class AbstractManagedRepositoriesAction
      */
     protected RoleManager roleManager;
     
+    public static final String CONFIRM = "confirm";
+    
     public RoleManager getRoleManager()
     {
         return roleManager;
index 6d5a0bb7b5acb0faa4f09405707c0165bbc5eec5..919bce0711b5d1cac8bf319f6b0dcb8369cecb25 100644 (file)
@@ -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;
+    }
 }
index ade35bb7f63630650f408a6ee708000475ad82a6..86817bab669756e5e9806ccf6b62a005cc63bb25 100644 (file)
@@ -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;
+    }
 }
index ea788ef62744aa7d944fc848355f8e40fd50f9b9..c85744f25112f774e630ad3aac55cfe15b8dcede 100644 (file)
     <action name="addRepository" class="addManagedRepositoryAction" method="input">
       <result name="input">/WEB-INF/jsp/admin/addRepository.jsp</result>
       <result name="error">/WEB-INF/jsp/admin/addRepository.jsp</result>
+      <result name="confirm">/WEB-INF/jsp/admin/confirmAddRepository.jsp</result>
       <result name="success" type="redirect-action">repositories</result>
       <interceptor-ref name="configuredPrepareParamsStack"/>
     </action>
       <result name="input">/WEB-INF/jsp/admin/editRepository.jsp</result>
       <result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result>
       <result name="success" type="redirect-action">repositories</result>
+      <result name="confirm">/WEB-INF/jsp/admin/confirmAddRepository.jsp</result>
       <interceptor-ref name="configuredPrepareParamsStack"/>
     </action>
 
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 (file)
index 0000000..270b905
--- /dev/null
@@ -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" %>
+
+<html>
+<head>
+  <title>Admin: Add Managed Repository</title>
+  <ww:head/>
+</head>
+
+<body>
+
+<h1>Admin: Add Managed Repository</h1>
+
+  <div class="warningbox">
+    <p>
+      <strong>WARNING: Repository location already exists.</strong>
+    </p>
+  </div>
+  
+  <p>
+    Are you sure you want to ${action == 'addRepository' ? 'add' : 'update'} the following managed repository?
+  </p>
+
+  <div class="infobox">
+    <table class="infotable">
+      <tr>
+        <td>ID:</td>
+        <td><code>${repository.id}</code></td>
+      </tr>
+      <tr>
+        <td>Name:</td>
+        <td>${repository.name}</td>
+      </tr>
+      <tr>
+        <td>Directory:</td>
+        <td>${repository.location}</td>
+      </tr>
+      <tr>
+        <td>Index Directory:</td>
+        <td>${repository.indexDir}</td>
+      </tr>
+      <tr>
+        <td>Type:</td>
+        <%--td>${repository.layout}</td--%>
+        <td>
+          <c:choose>
+               <c:when test="${repository.layout == 'default'}">
+                 Maven 2.x Repository
+               </c:when>
+               <c:otherwise>
+                 Maven 1.x Repository
+               </c:otherwise>
+             </c:choose>
+           </td>
+      </tr>
+      <tr>
+        <td>Cron:</td>
+        <td>${repository.refreshCronExpression}</td>
+      </tr>
+      <tr>
+        <td>Repository Purge By Days Older Than:</td>
+        <td>${repository.daysOlder}</td>
+      </tr>
+      <tr>
+        <td>Repository Purge By Retention Count:</td>
+        <td>${repository.retentionCount}</td>
+      </tr>
+      <tr>
+        <td>Releases Included:</td>
+        <td class="${repository.releases ? 'donemark' : 'errormark'} booleanIcon">
+      </tr>
+      <tr>
+        <td>Snapshots Included:</td>
+        <td class="${repository.snapshots ? 'donemark' : 'errormark'} booleanIcon">
+      </tr>
+      <tr>
+        <td>Scannable:</td>
+        <td class="${repository.scanned ? 'donemark' : 'errormark'} booleanIcon">
+      </tr>
+      <tr>
+        <td>Delete Released Snapshots:</td>
+        <td class="${repository.deleteReleasedSnapshots ? 'donemark' : 'errormark'} booleanIcon">
+      </tr>
+    </table>
+  </div>
+       
+  <ww:form method="post" action="${action}" namespace="/admin" validate="true" theme="simple">
+    <div class="buttons">      
+      <ww:hidden name="repository.id" value="${repository.id}"/>
+      <ww:hidden name="repository.name" value="${repository.name}"/>
+      <ww:hidden name="repository.location" value="${repository.location}"/>
+      <ww:hidden name="repository.indexDir" value="${repository.indexDir}"/>
+      <ww:hidden name="repository.layout" value="${repository.layout}"/>
+      <ww:hidden name="repository.refreshCronExpression" value="${repository.refreshCronExpression}"/>
+      <ww:hidden name="repository.daysOlder" value="${repository.daysOlder}"/>
+      <ww:hidden name="repository.retentionCount" value="${repository.retentionCount}"/>
+      <ww:hidden name="repository.releases" value="${repository.releases}"/>
+      <ww:hidden name="repository.snapshots" value="${repository.snapshots}"/>
+      <ww:hidden name="repository.scanned" value="${repository.scanned}"/>
+      <ww:hidden name="repository.deleteReleasedSnapshots" value="${repository.deleteReleasedSnapshots}"/>
+      
+      <c:choose>      
+        <c:when test="${action == 'addRepository'}">
+         <ww:submit value="Save" method="confirmAdd"/>
+       </c:when>
+       <c:otherwise>
+         <ww:submit value="Save" method="confirmUpdate"/>
+       </c:otherwise>
+     </c:choose>
+      
+      <ww:submit value="Cancel" method="execute"/>
+    </div>
+  </ww:form>
+  
+</body>
+</html>
index ed0501636173adfeead5186f241f67181670831e..beaafba67a83c789e532f154d61ac6942a0e80bd 100644 (file)
@@ -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 );
index 57f30a44e4ec8fce12d7afdef85e0ba08e15d08b..5c944f8d6ce0ea40f16f854bf9c39eb06b3863bf 100644 (file)
@@ -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 )
     {