当前位置: 首页>>代码示例>>Java>>正文


Java PropertyDefinition.getConstraints方法代码示例

本文整理汇总了Java中org.alfresco.service.cmr.dictionary.PropertyDefinition.getConstraints方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDefinition.getConstraints方法的具体用法?Java PropertyDefinition.getConstraints怎么用?Java PropertyDefinition.getConstraints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.alfresco.service.cmr.dictionary.PropertyDefinition的用法示例。


在下文中一共展示了PropertyDefinition.getConstraints方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validatePropsDefaultValues

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
/**
 * Validates the properties' non-null default values against the defined property constraints.
 *
 * @param compiledModel the compiled model
 * @throws CustomModelException.CustomModelConstraintException if there is constraint evaluation
 *                                                             exception
 */
private void validatePropsDefaultValues(CompiledModel compiledModel)
{
    for (PropertyDefinition propertyDef : compiledModel.getProperties())
    {
        if (propertyDef.getDefaultValue() != null && propertyDef.getConstraints().size() > 0)
        {
            for (ConstraintDefinition constraintDef : propertyDef.getConstraints())
            {
                Constraint constraint = constraintDef.getConstraint();
                try
                {
                    constraint.evaluate(propertyDef.getDefaultValue());
                }
                catch (AlfrescoRuntimeException ex)
                {
                    String message = getRootCauseMsg(ex, false, "cmm.service.constraint.default_prop_value_err");
                    throw new CustomModelException.CustomModelConstraintException(message);
                }
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:CustomModelServiceImpl.java

示例2: testConstraintsOverrideInheritance

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
public void testConstraintsOverrideInheritance()
{
    QName baseQName = QName.createQName(TEST_URL, "base");
    QName fileQName = QName.createQName(TEST_URL, "file");
    QName folderQName = QName.createQName(TEST_URL, "folder");
    QName prop1QName = QName.createQName(TEST_URL, "prop1");

    // get the base property
    PropertyDefinition prop1Def = service.getProperty(baseQName, prop1QName);
    assertNotNull(prop1Def);
    List<ConstraintDefinition> prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);

    // check the inherited property on folder (must be same as above)
    prop1Def = service.getProperty(folderQName, prop1QName);
    assertNotNull(prop1Def);
    prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);

    // check the overridden property on file (must be reverse of above)
    prop1Def = service.getProperty(fileQName, prop1QName);
    assertNotNull(prop1Def);
    prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:35,代码来源:RepoDictionaryDAOTest.java

示例3: getReferenceableConstraintDefs

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
private Collection<ConstraintDefinition> getReferenceableConstraintDefs(
        CompiledModel model)
{
    Collection<ConstraintDefinition> conDefs = model.getConstraints();
    Collection<PropertyDefinition> propDefs = model.getProperties();
    for (PropertyDefinition propDef : propDefs)
    {
        for (ConstraintDefinition conDef : propDef.getConstraints())
        {
            conDefs.remove(conDef);
        }
    }

    return conDefs;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:16,代码来源:DictionaryDAOImpl.java

示例4: removeInlineConstraints

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
/**
 * Removes the inline constraints (i.e. defined within the property) from
 * all constraints. The result will be constraints that have been defined
 * within the model (Top level) itself.
 *
 * @param compiledModel the compiled model
 * @return list of model defined constraints
 */
public static List<ConstraintDefinition> removeInlineConstraints(CompiledModel compiledModel)
{
    List<ConstraintDefinition> modelConstraints = new ArrayList<>();

    Set<QName> propertyConstraints = new HashSet<>();
    for(PropertyDefinition propDef : compiledModel.getProperties())
    {
        if (propDef.getConstraints().size() > 0)
        {
            for (ConstraintDefinition propConst : propDef.getConstraints())
            {
                propertyConstraints.add(propConst.getName());
            }
        }
    }

    for (ConstraintDefinition constraint : compiledModel.getConstraints())
    {
        if (!propertyConstraints.contains(constraint.getName()))
        {
            modelConstraints.add(constraint);
        }
    }

    return modelConstraints;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:35,代码来源:CustomModelDefinitionImpl.java

示例5: testConstraintsOverrideInheritance

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
@Test
public void testConstraintsOverrideInheritance()
{
    QName baseQName = QName.createQName(TEST_URL, "base");
    QName fileQName = QName.createQName(TEST_URL, "file");
    QName folderQName = QName.createQName(TEST_URL, "folder");
    QName prop1QName = QName.createQName(TEST_URL, "prop1");

    // get the base property
    PropertyDefinition prop1Def = service.getProperty(baseQName, prop1QName);
    assertNotNull(prop1Def);
    List<ConstraintDefinition> prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);

    // check the inherited property on folder (must be same as above)
    prop1Def = service.getProperty(folderQName, prop1QName);
    assertNotNull(prop1Def);
    prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);

    // check the overridden property on file (must be reverse of above)
    prop1Def = service.getProperty(fileQName, prop1QName);
    assertNotNull(prop1Def);
    prop1Constraints = prop1Def.getConstraints();
    assertEquals("Incorrect number of constraints", 3, prop1Constraints.size());
    assertTrue("Constraint instance incorrect", prop1Constraints.get(0).getConstraint() instanceof StringLengthConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(1).getConstraint() instanceof RegexConstraint);
    assertTrue("Constraint instance incorrect", prop1Constraints.get(2).getConstraint() instanceof RegisteredConstraint);
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:36,代码来源:DictionaryDAOTest.java

示例6: CustomModelProperty

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
public CustomModelProperty(PropertyDefinition propertyDefinition, MessageLookup messageLookup)
{
    this.name = propertyDefinition.getName().getLocalName();
    this.prefixedName = propertyDefinition.getName().toPrefixString();
    this.title = propertyDefinition.getTitle(messageLookup);
    this.dataType = propertyDefinition.getDataType().getName().toPrefixString();
    this.description = propertyDefinition.getDescription(messageLookup);
    this.isMandatory = propertyDefinition.isMandatory();
    this.isMandatoryEnforced = propertyDefinition.isMandatoryEnforced();
    this.isMultiValued = propertyDefinition.isMultiValued();
    this.defaultValue = propertyDefinition.getDefaultValue();
    this.isIndexed = propertyDefinition.isIndexed();
    this.facetable = propertyDefinition.getFacetable();
    this.indexTokenisationMode = propertyDefinition.getIndexTokenisationMode();
    List<ConstraintDefinition> constraintDefs = propertyDefinition.getConstraints();
    if (constraintDefs.size() > 0)
    {
        this.constraintRefs = new ArrayList<>();
        this.constraints = new ArrayList<>();
        for (ConstraintDefinition cd : constraintDefs)
        {
            if (cd.getRef() != null)
            {
                constraintRefs.add(cd.getRef().toPrefixString());
            }
            else
            {
                constraints.add(new CustomModelConstraint(cd, messageLookup));
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:33,代码来源:CustomModelProperty.java

示例7: isMetadataValid

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
private boolean isMetadataValid(ImportableItem importableItem)
{
    if (!importableItem.getHeadRevision().metadataFileExists())
    {
        return true;
    }
    
    if (metadataLoader != null)
    {
        MetadataLoader.Metadata result = new MetadataLoader.Metadata();
        metadataLoader.loadMetadata(importableItem.getHeadRevision(), result);
        
        Map<QName, Serializable> metadataProperties = result.getProperties();
        for (QName propertyName : metadataProperties.keySet())
        {
            PropertyDefinition propDef = dictionaryService.getProperty(propertyName);
            if (propDef != null)
            {
                for (ConstraintDefinition constraintDef : propDef.getConstraints())
                {
                    Constraint constraint = constraintDef.getConstraint();
                    if (constraint != null)
                    {
                        try
                        {
                            constraint.evaluate(metadataProperties.get(propertyName));
                        }
                        catch (ConstraintException e)
                        {
                            if (log.isWarnEnabled())
                            {
                                log.warn("Skipping file '" + FileUtils.getFileName(importableItem.getHeadRevision().getContentFile())
                                   +"' with invalid metadata: '" + FileUtils.getFileName(importableItem.getHeadRevision().getMetadataFile()) + "'.", e);
                            }
                            return false;
                        }
                    }
                }
            }
        }
    }
    
    return true;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:DirectoryAnalyserImpl.java

示例8: validateDeleteConstraint

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
private void validateDeleteConstraint(CompiledModel compiledModel, QName constraintName, boolean sharedModel)
{
    String tenantDomain = TenantService.DEFAULT_DOMAIN;
    if (sharedModel)
    {
        tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
    }
    
    Set<QName> referencedBy = new HashSet<QName>(0);
    
    // check for references to constraint definition
    // note: could be anon prop constraint (if no referenceable constraint)
    Collection<QName> allModels = dictionaryDAO.getModels();
    for (QName model : allModels)
    {
        Collection<PropertyDefinition> propDefs = null;
        if (compiledModel.getModelDefinition().getName().equals(model))
        {
            // TODO deal with multiple pending model updates
            propDefs = compiledModel.getProperties();
        }
        else
        {
            propDefs = dictionaryDAO.getProperties(model);
        }
        
        for (PropertyDefinition propDef : propDefs)
        {
            for (ConstraintDefinition conDef : propDef.getConstraints())
            {
                if (constraintName.equals(conDef.getRef()))
                {
                    referencedBy.add(conDef.getName());
                }
            }
        }
    }
    
    if (referencedBy.size() == 1)
    {
        throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by '" + referencedBy.toArray()[0] + "' property constraint");
    }
    else if (referencedBy.size() > 1)
    {
        throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by " + referencedBy.size() + " property constraints");
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:48,代码来源:ModelValidatorImpl.java

示例9: makeFieldConstraints

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
private List<FieldConstraint> makeFieldConstraints(PropertyDefinition propDef)
{
    List<FieldConstraint> fieldConstraints = null;
    List<ConstraintDefinition> constraints = propDef.getConstraints();
    if (constraints != null && constraints.size() > 0)
    {
        fieldConstraints = new ArrayList<FieldConstraint>(constraints.size());
        for (ConstraintDefinition constraintDef : constraints)
        {
            Constraint constraint = constraintDef.getConstraint();
            String type = constraint.getType();
            Map<String, Object> params = constraint.getParameters();
            
            
            //ListOfValuesConstraints have special handling for localising their allowedValues.
            //If the constraint that we are currently handling is a registered constraint then
            //we need to examine the underlying constraint to see if it is a LIST constraint
            if (RegisteredConstraint.class.isAssignableFrom(constraint.getClass()))
            {
                constraint = ((RegisteredConstraint)constraint).getRegisteredConstraint();
            }
            
            if (ListOfValuesConstraint.class.isAssignableFrom(constraint.getClass()))
            {
                ListOfValuesConstraint lovConstraint = (ListOfValuesConstraint) constraint;
                List<String> allowedValues = lovConstraint.getAllowedValues();
                List<String> localisedValues = new ArrayList<String>(allowedValues.size());
                
                // Look up each localised display-label in turn.
                for (String value : allowedValues)
                {
                    String displayLabel = lovConstraint.getDisplayLabel(value, dictionaryService);
                    // Change the allowedValue entry to the format the FormsService expects for localised strings: "value|label"
                    // If there is no localisation defined for any value, then this will give us "value|value".
                    localisedValues.add(value + "|" + displayLabel);
                }
                
                // Now replace the allowedValues param with our localised version.
                params.put(ListOfValuesConstraint.ALLOWED_VALUES_PARAM, localisedValues);
            }
            FieldConstraint fieldConstraint = new FieldConstraint(type, params);
            fieldConstraints.add(fieldConstraint);
        }
    }
    return fieldConstraints;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:47,代码来源:PropertyFieldProcessor.java

示例10: setDefaultTaskProperties

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
/**
 * Sets Default Properties of Task
 * 
 * @param task
 *            task instance
 */
public void setDefaultTaskProperties(DelegateTask task)
{
    TypeDefinition typeDefinition = typeManager.getFullTaskDefinition(task);
    // Only local task properties should be set to default value
    Map<QName, Serializable> existingValues = getTaskProperties(task, typeDefinition, true);
    Map<QName, Serializable> defaultValues = new HashMap<QName, Serializable>();

    Map<QName, PropertyDefinition> propertyDefs = typeDefinition.getProperties();

    // for each property, determine if it has a default value
    for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
    {
        QName key = entry.getKey();
        String defaultValue = entry.getValue().getDefaultValue();
        if (defaultValue != null && existingValues.get(key) == null)
        {
            defaultValues.put(key, defaultValue);
        }
    }

    // Special case for property priorities
    PropertyDefinition priorDef = propertyDefs.get(WorkflowModel.PROP_PRIORITY);
    Serializable existingValue = existingValues.get(WorkflowModel.PROP_PRIORITY);
    try
    {
    	if(priorDef != null) {
         for (ConstraintDefinition constraintDef : priorDef.getConstraints())
         {
             constraintDef.getConstraint().evaluate(existingValue);
         }
    	}
    }
    catch (ConstraintException ce)
    {
        if(priorDef != null) {
            Integer defaultVal = Integer.valueOf(priorDef.getDefaultValue());
            if (logger.isDebugEnabled())
            {
                logger.debug("Task priority value ("+existingValue+") was invalid so it was set to the default value of "+defaultVal+". Task:"+task.getName());
            }
            defaultValues.put(WorkflowModel.PROP_PRIORITY, defaultVal);
        }
    }    
    
    // Special case for task description default value
    String description = (String) existingValues.get(WorkflowModel.PROP_DESCRIPTION);
    if (description == null || description.length() == 0)
    {
        //Try the localised task description first
        String processDefinitionKey = ((ProcessDefinition) ((TaskEntity)task).getExecution().getProcessDefinition()).getKey();
        description = factory.getTaskDescription(typeDefinition, factory.buildGlobalId(processDefinitionKey), null, task.getTaskDefinitionKey());
        if (description != null && description.length() > 0) {
            defaultValues.put(WorkflowModel.PROP_DESCRIPTION,  description);
        } else {
            String descriptionKey = factory.mapQNameToName(WorkflowModel.PROP_WORKFLOW_DESCRIPTION);
            description = (String) task.getExecution().getVariable(descriptionKey); 
            if (description != null && description.length() > 0) {
                defaultValues.put(WorkflowModel.PROP_DESCRIPTION,  description); 
            } else {
                defaultValues.put(WorkflowModel.PROP_DESCRIPTION,  task.getName());
            }
        }
         
    }

    // Assign the default values to the task
    if (defaultValues.size() > 0)
    {
        setTaskProperties(task, defaultValues);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:78,代码来源:ActivitiPropertyConverter.java

示例11: createOverriddenProperty

import org.alfresco.service.cmr.dictionary.PropertyDefinition; //导入方法依赖的package包/类
/**
 * Create a property definition whose values are overridden
 * 
 * @param propertyDef  the property definition to override
 * @param override  the overridden values
 * @return  the property definition
 */
private M2Property createOverriddenProperty(
        PropertyDefinition propertyDef,
        M2PropertyOverride override,
        NamespacePrefixResolver prefixResolver,
        Map<QName, ConstraintDefinition> modelConstraints)
{
    M2Property property = new M2Property();
    property.setOverride(true);
    
    // Process Default Value
    String defaultValue = override.getDefaultValue();
    property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue);

    // Process Mandatory Value
    Boolean isOverrideMandatory = override.isMandatory();
    Boolean isOverrideMandatoryEnforced = override.isMandatoryEnforced();
    if (isOverrideMandatory != null && propertyDef.isMandatory())
    {
        // the override specified whether the property should be mandatory or not
        // check that the mandatory enforcement is not relaxed
        if (!isOverrideMandatory)
        {
            throw new DictionaryException(
                    "d_dictionary.property.err.cannot_relax_mandatory",
                    propertyDef.getName().toPrefixString());
        }
        else if ((isOverrideMandatoryEnforced != null) && !isOverrideMandatoryEnforced && propertyDef.isMandatoryEnforced())
        {
            throw new DictionaryException(
                    "d_dictionary.property.err.cannot_relax_mandatory_enforcement",
                    propertyDef.getName().toPrefixString());
        }
    }
    property.setMandatory(isOverrideMandatory == null ? propertyDef.isMandatory() : isOverrideMandatory);
    property.setMandatoryEnforced(isOverrideMandatoryEnforced == null ? propertyDef.isMandatoryEnforced() : isOverrideMandatoryEnforced);

    // inherit or override constraints
    List<M2Constraint> overrideConstraints = override.getConstraints();
    if (overrideConstraints != null)
    {
        constraintDefs = buildConstraints(
                overrideConstraints,
                this,
                prefixResolver,
                modelConstraints);
    }
    else
    {
        this.constraintDefs = propertyDef.getConstraints();
    }

    // Copy all other properties as they are
    property.setDescription(propertyDef.getDescription(null));
    property.setIndexed(propertyDef.isIndexed());
    property.setIndexedAtomically(propertyDef.isIndexedAtomically());
    property.setMultiValued(propertyDef.isMultiValued());
    property.setProtected(propertyDef.isProtected());
    property.setStoredInIndex(propertyDef.isStoredInIndex());
    property.setTitle(propertyDef.getTitle(null));
    property.setIndexTokenisationMode(propertyDef.getIndexTokenisationMode());
    
    return property;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:71,代码来源:M2PropertyDefinition.java


注:本文中的org.alfresco.service.cmr.dictionary.PropertyDefinition.getConstraints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。