From: Olivier Lamy Date: Tue, 2 Oct 2012 21:12:42 +0000 (+0000) Subject: [MRM-1681] addProxy Connectors Rules screen X-Git-Tag: archiva-1.4-M3~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ac900f8e4bf13b3d85a8849325eb96cac9c0483d;p=archiva.git [MRM-1681] addProxy Connectors Rules screen add validation. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1393185 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java index 1d903eed3..03b995146 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java @@ -225,7 +225,7 @@ public class DefaultRepositoryGroupAdmin java.util.List repos = map.get( groupId ); if ( repos == null ) { - repos = new java.util.ArrayList(); + repos = new ArrayList(); map.put( groupId, repos ); } repos.add( repo.getId() ); @@ -247,7 +247,7 @@ public class DefaultRepositoryGroupAdmin java.util.List groups = map.get( repositoryId ); if ( groups == null ) { - groups = new java.util.ArrayList(); + groups = new ArrayList(); map.put( repositoryId, groups ); } groups.add( group.getId() ); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java index fd74d15bc..3b13bd8b9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.beans.ProxyConnectorRule; import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ProxyConnectorRuleService; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import javax.inject.Inject; @@ -31,7 +32,7 @@ import java.util.List; /** * @author Olivier Lamy */ -@Service ( "proxyConnectorRuleService#rest" ) +@Service ("proxyConnectorRuleService#rest") public class DefaultProxyConnectorRuleService extends AbstractRestService implements ProxyConnectorRuleService @@ -53,9 +54,43 @@ public class DefaultProxyConnectorRuleService } } + private void validateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule ) + throws ArchivaRestServiceException + { + if ( StringUtils.isEmpty( proxyConnectorRule.getPattern() ) ) + { + ArchivaRestServiceException e = new ArchivaRestServiceException( "pattern cannot be empty", null ); + e.setErrorKey( "proxy-connector-rule.pattern.empty" ); + throw e; + } + + if ( proxyConnectorRule.getProxyConnectors() == null || proxyConnectorRule.getProxyConnectors().isEmpty() ) + { + ArchivaRestServiceException e = + new ArchivaRestServiceException( "proxyConnector rule must have proxyConnectors.", null ); + e.setErrorKey( "proxy-connector-rule.pattern.connectors.empty" ); + throw e; + } + + for ( ProxyConnectorRule proxyConnectorRule1 : getProxyConnectorRules() ) + { + if ( StringUtils.equals( proxyConnectorRule.getPattern(), proxyConnectorRule1.getPattern() ) + && proxyConnectorRule.getProxyConnectorRuleType() == proxyConnectorRule1.getProxyConnectorRuleType() ) + { + ArchivaRestServiceException e = + new ArchivaRestServiceException( "same ProxyConnector rule already exists.", null ); + e.setErrorKey( "proxy-connector-rule.pattern.already.exists" ); + throw e; + } + } + } + public Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule ) throws ArchivaRestServiceException { + + validateProxyConnectorRule( proxyConnectorRule ); + try { proxyConnectorRuleAdmin.addProxyConnectorRule( proxyConnectorRule, getAuditInformation() ); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index f4d788a04..9742d40f1 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -493,5 +493,8 @@ proxy-connector-rule.deleted=ProxyConnector rule deleted. proxy-connector-rule.pattern=Pattern proxy-connector-rule.added=ProxyConnector rule added. proxy-connector-rule.updated=ProxyConnector rule updated. +proxy-connector-rule.pattern.empty=Pattern cannot be empty. +proxy-connector-rule.pattern.already.exists=Same ProxyConnector rule already exists. +proxy-connector-rule.pattern.connectors.empty=You must select proxyConnectors. diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js index c0b93dbb3..ddd4110ce 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstrap","jquery.validate","knockout" +define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstrap","jquery.ui","knockout" ,"knockout.simpleGrid","knockout.sortable","archiva.proxy-connectors"], function() { @@ -57,7 +57,10 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra addProxyConnectorRule=function(proxyConnectorRule){ $("#proxy-connector-rule-add-btn" ).button("loading"); $.log("addProxyConnectorRule"); - self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/proxyConnectorRule",true); + self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/proxyConnectorRule",true, + function(){ + $("#proxy-connector-rule-add-btn" ).button("reset"); + }); } this.saveProxyConnectorRule=function(proxyConnectorRule,url,add,completeFnCallback){ diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html index 1c81dc583..32e7d2570 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html @@ -1341,7 +1341,7 @@
-