Updates to data dictionary constraints

- Added getType and getParameters methods to Constraint interface
  - Updated existing constraint implementations
Updates to FormService
  - Implemented regex pattern match for selecting appropriate form processor
  - Added constraints to Form object constructed in NodeHandler

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12396 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2008-12-15 21:18:51 +00:00
parent 6bda204c4d
commit e04da90fac
14 changed files with 257 additions and 30 deletions

View File

@@ -32,9 +32,12 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.forms.AssociationFieldDefinition.Direction;
import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -149,7 +152,7 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
setComplete();
endTransaction();
}
public void testGetForm() throws Exception
{
Form form = this.formService.getForm(this.document.toString());
@@ -228,18 +231,16 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
assertTrue("Expecting cm:name to be mandatory", nameField.isMandatory());
assertFalse("Expecting cm:name to be single valued", nameField.isRepeating());
// TODO: get the constraint for the name field and check
/*
// get the constraint for the name field and check
List<FieldConstraint> constraints = nameField.getConstraints();
assertEquals("Expecting 1 constraint for cm:name", constraints.size());
assertEquals("Expecting 1 constraint for cm:name", 1, constraints.size());
FieldConstraint constraint = constraints.get(0);
assertEquals("Expecting name of constraint to be 'REGEX'", "REGEX", constraint.getName());
assertEquals("Expecting name of constraint to be 'REGEX'", "REGEX", constraint.getType());
Map<String, String> params = constraint.getParams();
assertNotNull("Expecting constraint parameters", params);
assertEquals("Expecting 2 constraint parameters", 2, params.size());
assertNotNull("Expecting an 'expression' constraint parameter", params.get("expression"));
assertNotNull("Expecting an 'requiresMatch' constraint parameter", params.get("requiresMatch"));
*/
// check details of the addressees field
assertEquals("Expecting cm:addressees type to be d:text", "d:text", addresseesField.getDataType());

View File

@@ -151,30 +151,30 @@ public class PropertyFieldDefinition extends FieldDefinition
*/
public class FieldConstraint
{
protected String name;
protected String type;
protected Map<String, String> params;
/**
* Constructs a FieldConstraint
*
* @param name The name of the constraint
* @param type The type of the constraint
* @param params Map of parameters for the constraint
*/
public FieldConstraint(String name, Map<String, String> params)
public FieldConstraint(String type, Map<String, String> params)
{
super();
this.name = name;
this.type = type;
this.params = params;
}
/**
* Returns the name of the constraint
* Returns the type of the constraint
*
* @return The constraint name
* @return The constraint type
*/
public String getName()
public String getType()
{
return this.name;
return this.type;
}
/**

View File

@@ -24,6 +24,9 @@
*/
package org.alfresco.repo.forms.processor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,6 +43,7 @@ public abstract class AbstractFormProcessor implements FormProcessor
protected FormProcessorRegistry processorRegistry;
protected String matchPattern;
protected boolean active = true;
protected Pattern patternMatcher;
/**
* Sets the form process registry
@@ -91,6 +95,11 @@ public abstract class AbstractFormProcessor implements FormProcessor
return;
}
else
{
// setup pattern matcher
this.patternMatcher = Pattern.compile(this.matchPattern);
}
// register this instance
this.processorRegistry.addProcessor(this);
@@ -109,12 +118,16 @@ public abstract class AbstractFormProcessor implements FormProcessor
*/
public boolean isApplicable(String item)
{
// TODO: do a regular expression match on the pattern supplied to
// determine if the processor matches
// this form processor matches if the match pattern provided matches
// the item provided
// NOTE: For now just return true as there is only going to be one
// form processor instance
return true;
Matcher matcher = patternMatcher.matcher(item);
boolean matches = matcher.matches();
if (logger.isDebugEnabled())
logger.debug("Checking processor " + this + " for applicability for item '" + item + "', result = " + matches);
return matches;
}
/*

View File

@@ -178,16 +178,20 @@ public class NodeHandler extends AbstractHandler
for (ConstraintDefinition constraintDef : constraints)
{
// TODO: We need to define a common interface for all constraints
// so that we can determine the name and parameters without
// having to know all the implementations
/*
Constraint constraint = constraintDef.getConstraint();
FieldConstraint fieldConstraint = fieldDef.new FieldConstraint(constraint.toString(),
new HashMap<String,String>());
Map<String, String> fieldConstraintParams = null;
Map<String, Object> constraintParams = constraint.getParameters();
if (constraintParams != null)
{
fieldConstraintParams = new HashMap<String, String>(constraintParams.size());
for (String name : constraintParams.keySet())
{
fieldConstraintParams.put(name, constraintParams.get(name).toString());
}
}
FieldConstraint fieldConstraint = fieldDef.new FieldConstraint(
constraint.getType(), fieldConstraintParams);
fieldConstraints.add(fieldConstraint);
*/
}
fieldDef.setConstraints(fieldConstraints);