]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1681] addProxy Connectors Rules screen
authorOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 21:12:42 +0000 (21:12 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 21:12:42 +0000 (21:12 +0000)
add validation.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1393185 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java
archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html

index 1d903eed363f5a2cacdfbd46243d98f6f2d52247..03b995146f65ac26f04d8385169c071f64bb3dbd 100644 (file)
@@ -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() );
index fd74d15bcd08f820e7295f565b09a44c7af3aa46..3b13bd8b9a86be33bea6bc521f8f920d7599628c 100644 (file)
@@ -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() );
index f4d788a04e72626a5037d16ed184935d64aa753c..9742d40f14ac5d288de3659f4bc574f8272ca7c0 100644 (file)
@@ -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.
 
 
index c0b93dbb30d7224036cb81a0726e20fd5072a4c4..ddd4110ce878d6d427adb6d0eb1c7b5c31f4dbc1 100644 (file)
@@ -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){
index 1c81dc583037400eb1189cdd9126513b74f08516..32e7d25700b9d7a7a4bdee4f45cbd3e745c54e11 100644 (file)
             <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>