]> source.dussan.org Git - archiva.git/commitdiff
[MRM-462] restore management of remote repositories
authorBrett Porter <brett@apache.org>
Wed, 12 Sep 2007 05:52:25 +0000 (05:52 +0000)
committerBrett Porter <brett@apache.org>
Wed, 12 Sep 2007 05:52:25 +0000 (05:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@574791 13f79535-47bb-0310-9956-ffa450edef68

MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java
MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml
MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp
MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java [new file with mode: 0644]
MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml [new file with mode: 0644]

diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java
new file mode 100644 (file)
index 0000000..779250c
--- /dev/null
@@ -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;
+    }
+}
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java
new file mode 100644 (file)
index 0000000..4e131ba
--- /dev/null
@@ -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 );
+        }
+    }
+}
index 1a522b65e6b40108e68b0110a3573a948c776a1a..437ef009a65b824a4ee3657991caecffa40cde75 100644 (file)
@@ -22,21 +22,13 @@ package org.apache.maven.archiva.web.action.admin.repositories;
 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 @@ import java.io.IOException;
  * @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 @@ public class ConfigureRepositoryAction
         return INPUT;
     }
 
-    // TODO: rename to confirmDelete
-    public String confirm()
-    {
-        return INPUT;
-    }
-
     public String delete()
     {
         String result = SUCCESS;
@@ -140,39 +116,11 @@ public class ConfigureRepositoryAction
         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 @@ public class ConfigureRepositoryAction
             this.repository.setIndexed( false );
         }
 
-        // TODO! others?
         ManagedRepositoryConfiguration repoconfig =
             archivaConfiguration.getConfiguration().findManagedRepositoryById( id );
         if ( repoconfig != null )
@@ -264,7 +211,6 @@ public class ConfigureRepositoryAction
             containsError = true;
         }
 
-        // TODO! split
         if ( StringUtils.isBlank( repository.getLocation() ) )
         {
             addFieldError( "repository.location", "You must enter a directory." );
@@ -284,16 +230,6 @@ public class ConfigureRepositoryAction
         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 @@ public class ConfigureRepositoryAction
             // 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 @@ public class ConfigureRepositoryAction
 
     private void removeRepository( String repoId, Configuration configuration )
     {
-        // TODO! what about others?
         ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
         if ( toremove != null )
         {
@@ -341,31 +275,8 @@ public class ConfigureRepositoryAction
         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;
-    }
-
 }
index f196c655cb53bd937a5174f230625b0fca3b9d61..b993d7dfb7d45f1db50f6cae106927989686b935 100644 (file)
       <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">
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp
new file mode 100644 (file)
index 0000000..d117df1
--- /dev/null
@@ -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>
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp
new file mode 100644 (file)
index 0000000..da23fdc
--- /dev/null
@@ -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
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp
new file mode 100644 (file)
index 0000000..545d513
--- /dev/null
@@ -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
diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf
new file mode 100644 (file)
index 0000000..d5316de
--- /dev/null
@@ -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="#@java.util.LinkedHashMap@{'default' : 'Maven 2.x Repository', 'legacy' : 'Maven 1.x Repository'}"
+           name="repository.layout" label="Type"/>
index 4cca99fdebc575c58cfa840808ce1a2aafc89aff..484f60d0f43243ba93d76de14c8ffc83a392b35d 100644 (file)
@@ -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>
     </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>
 </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>
   </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}'>
 
         <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>
diff --git a/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java b/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java
new file mode 100644 (file)
index 0000000..3200bf5
--- /dev/null
@@ -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?
+}
diff --git a/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml b/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml
new file mode 100644 (file)
index 0000000..ed67e65
--- /dev/null
@@ -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>