archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1232615 - in /archiva/trunk/archiva-modules: archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/ archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/j...
Date Tue, 17 Jan 2012 22:35:09 GMT
Author: olamy
Date: Tue Jan 17 22:35:08 2012
New Revision: 1232615

URL: http://svn.apache.org/viewvc?rev=1232615&view=rev
Log:
add a rest method to validate if managed repository location already exists.
So move RepositoryCommonValidator to admin api and add the interface

Added:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
  (with props)
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
  (contents, props changed)
      - copied, changed from r1232433, archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java
Removed:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java
Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java

Added: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java?rev=1232615&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
(added)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
Tue Jan 17 22:35:08 2012
@@ -0,0 +1,60 @@
+package org.apache.archiva.admin.model;
+/*
+ * 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.archiva.admin.model.beans.AbstractRepository;
+import org.apache.archiva.admin.model.beans.ManagedRepository;
+
+/**
+ * apply basic repository validation : id and name.
+ * Check if already exists.
+ *
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+public interface RepositoryCommonValidator
+{
+
+    public static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
+
+    public static final String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
+
+
+    void basicValidation( AbstractRepository abstractRepository, boolean update )
+        throws RepositoryAdminException;
+
+    /**
+     * validate cronExpression and location format
+     *
+     * @param managedRepository
+     * @since 1.4-M2
+     */
+    void validateManagedRepository( ManagedRepository managedRepository )
+        throws RepositoryAdminException;
+
+    /**
+     * replace some interpolations ${appserver.base} with correct values
+     *
+     * @param directory
+     * @return
+     */
+    String removeExpressions( String directory );
+
+
+}

Propchange: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
Tue Jan 17 22:35:08 2012
@@ -20,6 +20,7 @@ package org.apache.archiva.admin.reposit
 
 import org.apache.archiva.admin.model.AuditInformation;
 import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.RepositoryCommonValidator;
 import org.apache.archiva.audit.AuditEvent;
 import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.configuration.ArchivaConfiguration;

Copied: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
(from r1232433, archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java)
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java?p2=archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java&p1=archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java&r1=1232433&r2=1232615&rev=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
Tue Jan 17 22:35:08 2012
@@ -19,6 +19,7 @@ package org.apache.archiva.admin.reposit
  */
 
 import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.RepositoryCommonValidator;
 import org.apache.archiva.admin.model.beans.AbstractRepository;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
@@ -41,14 +42,10 @@ import javax.inject.Named;
  * @since 1.4-M1
  */
 @Service
-public class RepositoryCommonValidator
+public class DefaultRepositoryCommonValidator
+    implements RepositoryCommonValidator
 {
 
-    public static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
-
-    public static final String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
-
-
     @Inject
     private ArchivaConfiguration archivaConfiguration;
 

Propchange: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
Tue Jan 17 22:35:08 2012
@@ -80,5 +80,12 @@ public interface ManagedRepositoriesServ
     Boolean updateManagedRepository( ManagedRepository managedRepository )
         throws ArchivaRestServiceException;
 
+    @Path( "fileLocationExists/{fileLocation}" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN
} )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
)
+    Boolean fileLocationExists( @PathParam( "fileLocation" ) String fileLocation )
+        throws ArchivaRestServiceException;
+
 
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
Tue Jan 17 22:35:08 2012
@@ -19,6 +19,7 @@ package org.apache.archiva.rest.services
  */
 
 import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.RepositoryCommonValidator;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
@@ -28,6 +29,7 @@ import org.apache.commons.lang.StringUti
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
+import java.io.File;
 import java.util.Collections;
 import java.util.List;
 
@@ -47,6 +49,9 @@ public class DefaultManagedRepositoriesS
     @Inject
     private PlexusSisuBridge plexusSisuBridge;
 
+    @Inject
+    private RepositoryCommonValidator repositoryCommonValidator;
+
 
     public List<ManagedRepository> getManagedRepositories()
         throws ArchivaRestServiceException
@@ -132,4 +137,10 @@ public class DefaultManagedRepositoriesS
         }
     }
 
+    public Boolean fileLocationExists( String fileLocation )
+        throws ArchivaRestServiceException
+    {
+        String location = repositoryCommonValidator.removeExpressions( fileLocation );
+        return new File( location ).exists();
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
Tue Jan 17 22:35:08 2012
@@ -23,6 +23,8 @@ import org.apache.archiva.admin.model.be
 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
 import org.junit.Test;
 
+import java.io.File;
+
 /**
  * @author Olivier Lamy
  */
@@ -80,5 +82,19 @@ public class ManagedRepositoriesServiceT
 
     }
 
+    //@Test
+    public void fileLocationExists()
+        throws Exception
+    {
+        ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader
);
+        File target = new File( "target" );
+
+        assertTrue( service.fileLocationExists( target.getCanonicalPath() ) );
+
+        // normally should not exists :-)
+        assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
+
+    }
+
 
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
Tue Jan 17 22:35:08 2012
@@ -19,8 +19,9 @@ package org.apache.archiva.web.action.ad
  * under the License.
  */
 
+import org.apache.archiva.admin.model.RepositoryCommonValidator;
 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
-import org.apache.archiva.admin.repository.RepositoryCommonValidator;
+import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
 import org.apache.archiva.audit.Auditable;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.apache.archiva.web.action.AbstractActionSupport;

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
Tue Jan 17 22:35:08 2012
@@ -21,7 +21,7 @@ package org.apache.archiva.web.action.ad
 
 import com.opensymphony.xwork2.Action;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.admin.repository.RepositoryCommonValidator;
+import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
@@ -99,14 +99,14 @@ public class AddManagedRepositoryActionT
         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryTaskScheduler(
             repositoryTaskScheduler );
 
-        RepositoryCommonValidator repositoryCommonValidator = new RepositoryCommonValidator();
-        repositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
-        repositoryCommonValidator.setRegistry( registry );
+        DefaultRepositoryCommonValidator defaultRepositoryCommonValidator = new DefaultRepositoryCommonValidator();
+        defaultRepositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
+        defaultRepositoryCommonValidator.setRegistry( registry );
 
         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
-            repositoryCommonValidator );
+            defaultRepositoryCommonValidator );
 
-        action.setRepositoryCommonValidator( repositoryCommonValidator );
+        action.setRepositoryCommonValidator( defaultRepositoryCommonValidator );
 
         action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java?rev=1232615&r1=1232614&r2=1232615&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
Tue Jan 17 22:35:08 2012
@@ -22,7 +22,7 @@ package org.apache.archiva.web.action.ad
 import com.opensymphony.xwork2.Action;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.admin.repository.RepositoryCommonValidator;
+import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
 import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -121,14 +121,14 @@ public class EditManagedRepositoryAction
         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setAuditListeners(
             new ArrayList<AuditListener>( 0 ) );
 
-        RepositoryCommonValidator repositoryCommonValidator = new RepositoryCommonValidator();
-        repositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
-        repositoryCommonValidator.setRegistry( registry );
+        DefaultRepositoryCommonValidator defaultRepositoryCommonValidator = new DefaultRepositoryCommonValidator();
+        defaultRepositoryCommonValidator.setArchivaConfiguration( archivaConfiguration );
+        defaultRepositoryCommonValidator.setRegistry( registry );
 
         ( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRepositoryCommonValidator(
-            repositoryCommonValidator );
+            defaultRepositoryCommonValidator );
 
-        action.setRepositoryCommonValidator( repositoryCommonValidator );
+        action.setRepositoryCommonValidator( defaultRepositoryCommonValidator );
 
         action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
 



Mime
View raw message