summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-10-02 21:12:42 +0000
committerOlivier Lamy <olamy@apache.org>2012-10-02 21:12:42 +0000
commitac900f8e4bf13b3d85a8849325eb96cac9c0483d (patch)
treec97137b8a23d12669df8f139d80c1817d56bcde9
parentf89eb0781bded087d4b651b046aec6b4a7bd009d (diff)
downloadarchiva-ac900f8e4bf13b3d85a8849325eb96cac9c0483d.tar.gz
archiva-ac900f8e4bf13b3d85a8849325eb96cac9c0483d.zip
[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
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java37
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties3
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js7
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html2
5 files changed, 47 insertions, 6 deletions
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<String> repos = map.get( groupId );
if ( repos == null )
{
- repos = new java.util.ArrayList<String>();
+ repos = new ArrayList<String>();
map.put( groupId, repos );
}
repos.add( repo.getId() );
@@ -247,7 +247,7 @@ public class DefaultRepositoryGroupAdmin
java.util.List<String> groups = map.get( repositoryId );
if ( groups == null )
{
- groups = new java.util.ArrayList<String>();
+ groups = new ArrayList<String>();
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 @@
<div class="control-group">
<label class="control-label" for="id">${$.i18n.prop('proxy-connector-rule.pattern')}</label>
<div class="controls">
- <input type="text" class="input-large required" id="proxy-connector-rule-pattern" name="id" size="15"
+ <input type="text" class="input-large required" id="pattern" name="pattern" size="15"
data-bind="value:proxyConnectorRule.pattern,css:{'uneditable-input': update},readonly:update"/>
</div>
</div>