ALF-10771: schema validation and differences rules

Validation serialized and deserialized in XML.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31942 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2011-11-14 16:25:49 +00:00
parent 6b3eb6181f
commit 3df35a9d06
15 changed files with 432 additions and 62 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.validator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.util.schemacomp.model.DbObject;
/**
* Base class providing DbValidator support.
*
* @author Matt Ward
*/
public abstract class AbstractDbValidator<T extends DbObject> implements DbValidator<T>
{
private final Map<String, String> properties = new HashMap<String, String>();
@Override
public void setProperty(String name, String value)
{
properties.put(name, value);
}
@Override
public String getProperty(String name)
{
return properties.get(name);
}
@Override
public Set<String> getPropertyNames()
{
return properties.keySet();
}
}

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.util.schemacomp.validator;
import java.util.Set;
import org.alfresco.util.schemacomp.DiffContext;
import org.alfresco.util.schemacomp.model.DbObject;
@@ -27,7 +29,13 @@ import org.alfresco.util.schemacomp.model.DbObject;
*
* @author Matt Ward
*/
public interface DbValidator
public interface DbValidator<T extends DbObject>
{
void validate(DbObject reference, DbObject target, DiffContext ctx);
void validate(T reference, T target, DiffContext ctx);
void setProperty(String name, String value);
String getProperty(String name);
Set<String> getPropertyNames();
}

View File

@@ -18,8 +18,8 @@
*/
package org.alfresco.util.schemacomp.validator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import org.alfresco.util.schemacomp.DbProperty;
@@ -36,7 +36,7 @@ import org.hibernate.dialect.Dialect;
*
* @author Matt Ward
*/
public class NameValidator implements DbValidator
public class NameValidator implements DbValidator<DbObject>
{
private Pattern pattern;
@@ -58,4 +58,41 @@ public class NameValidator implements DbValidator
{
this.pattern = pattern;
}
public Pattern getPattern()
{
return this.pattern;
}
@Override
public void setProperty(String name, String value)
{
if (name.equals("pattern") && value != null)
{
Pattern pattern = Pattern.compile(value);
setPattern(pattern);
}
}
@Override
public String getProperty(String name)
{
if (name.equals("pattern") && pattern != null)
{
return pattern.toString();
}
return null;
}
@Override
public Set<String> getPropertyNames()
{
Set<String> props = new TreeSet<String>();
props.add("pattern");
return props;
}
}

View File

@@ -22,7 +22,10 @@ package org.alfresco.util.schemacomp.validator;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.alfresco.util.schemacomp.DiffContext;
@@ -80,6 +83,14 @@ public class NameValidatorTest
}
@Test
public void canSetPatternUsingProperties()
{
validator.setProperty("pattern", "ORA_[A-Z_]+");
assertEquals("ORA_[A-Z_]+", validator.getPattern().toString());
}
private DbObject indexForName(String name)
{
return new Index(null, name, new ArrayList<String>());

View File

@@ -26,7 +26,7 @@ import org.alfresco.util.schemacomp.model.DbObject;
*
* @author Matt Ward
*/
public class NullValidator implements DbValidator
public class NullValidator extends AbstractDbValidator<DbObject>
{
@Override
public void validate(DbObject reference, DbObject target, DiffContext ctx)