[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
This commit is contained in:
Olivier Lamy 2012-10-02 21:12:42 +00:00
parent f89eb0781b
commit ac900f8e4b
5 changed files with 47 additions and 6 deletions

View 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() );

View 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() );

View 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.

View 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){

View File

@ -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>