summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-01-17 22:35:08 +0000
committerOlivier Lamy <olamy@apache.org>2012-01-17 22:35:08 +0000
commit58c30c851dcb4fd9d9e544986d8466d4756cfa8b (patch)
tree6f548075d809c13c766eadc9adb9dd02738813cb
parent32b26356e9446dfc5c4d0fb857466cd808eec353 (diff)
downloadarchiva-58c30c851dcb4fd9d9e544986d8466d4756cfa8b.tar.gz
archiva-58c30c851dcb4fd9d9e544986d8466d4756cfa8b.zip
add a rest method to validate if managed repository location already exists.
So move RepositoryCommonValidator to admin api and add the interface git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1232615 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java60
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java1
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java (renamed from archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java)9
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java7
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java11
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java16
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java3
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java12
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java12
9 files changed, 112 insertions, 19 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
new file mode 100644
index 000000000..6c862c10b
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryCommonValidator.java
@@ -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 );
+
+
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
index bb26445e8..bed10a5a1 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java
@@ -20,6 +20,7 @@ package org.apache.archiva.admin.repository;
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;
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
index 05756fd48..5ee256b97 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/DefaultRepositoryCommonValidator.java
@@ -19,6 +19,7 @@ package org.apache.archiva.admin.repository;
*/
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;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
index 0f3ed0760..095b5a090 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ManagedRepositoriesService.java
@@ -80,5 +80,12 @@ public interface ManagedRepositoriesService
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;
+
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
index a9f51284c..0b02b472e 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java
@@ -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.StringUtils;
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 DefaultManagedRepositoriesService
@Inject
private PlexusSisuBridge plexusSisuBridge;
+ @Inject
+ private RepositoryCommonValidator repositoryCommonValidator;
+
public List<ManagedRepository> getManagedRepositories()
throws ArchivaRestServiceException
@@ -132,4 +137,10 @@ public class DefaultManagedRepositoriesService
}
}
+ public Boolean fileLocationExists( String fileLocation )
+ throws ArchivaRestServiceException
+ {
+ String location = repositoryCommonValidator.removeExpressions( fileLocation );
+ return new File( location ).exists();
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
index 12ececb97..47a896eee 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ManagedRepositoriesServiceTest.java
@@ -23,6 +23,8 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
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 ManagedRepositoriesServiceTest
}
+ //@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" ) );
+
+ }
+
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
index f1ba9f62f..c5719c30f 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
@@ -19,8 +19,9 @@ package org.apache.archiva.web.action.admin.repositories;
* 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;
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
index 8eeba40bd..89d2cc91b 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
@@ -21,7 +21,7 @@ package org.apache.archiva.web.action.admin.repositories;
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 AddManagedRepositoryActionTest
( (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() );
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
index fe16df9f4..2dcb8f7d8 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
@@ -22,7 +22,7 @@ package org.apache.archiva.web.action.admin.repositories;
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 EditManagedRepositoryActionTest
( (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() );