Java Code Examples for org.alfresco.service.cmr.dictionary.PropertyDefinition#getDefaultValue()

The following examples show how to use org.alfresco.service.cmr.dictionary.PropertyDefinition#getDefaultValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomModelServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
                }
            }
        }
    }
}
 
Example 2
Source File: PropertyFieldProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Object getDefaultValue(QName name, ContentModelItemData<?> data)
{
    PropertyDefinition propDef = data.getPropertyDefinition(name);
    if (propDef != null)
    {
        QName typeQName = propDef.getDataType().getName();
        String strDefaultValue = propDef.getDefaultValue();
        if (NodePropertyValue.isDataTypeSupported(typeQName))
        {
            // convert to the appropriate type
            NodePropertyValue pv = new NodePropertyValue(typeQName, strDefaultValue);
            return pv.getValue(typeQName);
        }
        return strDefaultValue;
    }
    return null;
}
 
Example 3
Source File: RepoDictionaryDAOTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testPropertyOverride()
{
    TypeDefinition type1 = service.getType(QName.createQName(TEST_URL, "overridetype1"));
    Map<QName, PropertyDefinition> props1 = type1.getProperties();
    PropertyDefinition prop1 = props1.get(QName.createQName(TEST_URL, "propoverride"));
    String def1 = prop1.getDefaultValue();
    assertEquals("one", def1);
    
    TypeDefinition type2 = service.getType(QName.createQName(TEST_URL, "overridetype2"));
    Map<QName, PropertyDefinition> props2 = type2.getProperties();
    PropertyDefinition prop2 = props2.get(QName.createQName(TEST_URL, "propoverride"));
    String def2 = prop2.getDefaultValue();
    assertEquals("two", def2);

    TypeDefinition type3 = service.getType(QName.createQName(TEST_URL, "overridetype3"));
    Map<QName, PropertyDefinition> props3 = type3.getProperties();
    PropertyDefinition prop3 = props3.get(QName.createQName(TEST_URL, "propoverride"));
    String def3 = prop3.getDefaultValue();
    assertEquals("three", def3);
}
 
Example 4
Source File: M2ClassDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultValues()
 */
public Map<QName, Serializable> getDefaultValues()
{
    Map<QName, Serializable> result = new HashMap<QName, Serializable>(5);
    
    for(Map.Entry<QName, PropertyDefinition> entry : inheritedProperties.entrySet())
    {
        PropertyDefinition propertyDefinition = entry.getValue();
        String defaultValue = propertyDefinition.getDefaultValue();
        if (defaultValue != null)
        {
            result.put(entry.getKey(), defaultValue);
        }
    }
    
    return Collections.unmodifiableMap(result);
}
 
Example 5
Source File: M2AnonymousTypeDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultValues()
 */
public Map<QName, Serializable> getDefaultValues()
{
    Map<QName, Serializable> result = new HashMap<QName, Serializable>(5);
    
    for(Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
    {
        PropertyDefinition propertyDefinition = entry.getValue();
        String defaultValue = propertyDefinition.getDefaultValue();
        if (defaultValue != null)
        {
            result.put(entry.getKey(), defaultValue);
        }
    }
    
    return Collections.unmodifiableMap(result);
}
 
Example 6
Source File: DictionaryDAOTest.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testPropertyOverride()
{
    TypeDefinition type1 = service.getType(QName.createQName(TEST_URL, "overridetype1"));
    Map<QName, PropertyDefinition> props1 = type1.getProperties();
    PropertyDefinition prop1 = props1.get(QName.createQName(TEST_URL, "propoverride"));
    String def1 = prop1.getDefaultValue();
    assertEquals("one", def1);
    
    TypeDefinition type2 = service.getType(QName.createQName(TEST_URL, "overridetype2"));
    Map<QName, PropertyDefinition> props2 = type2.getProperties();
    PropertyDefinition prop2 = props2.get(QName.createQName(TEST_URL, "propoverride"));
    String def2 = prop2.getDefaultValue();
    assertEquals("two", def2);

    TypeDefinition type3 = service.getType(QName.createQName(TEST_URL, "overridetype3"));
    Map<QName, PropertyDefinition> props3 = type3.getProperties();
    PropertyDefinition prop3 = props3.get(QName.createQName(TEST_URL, "propoverride"));
    String def3 = prop3.getDefaultValue();
    assertEquals("three", def3);
}
 
Example 7
Source File: WorkflowModelBuilder.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Map<String, Object> buildQNameProperties(Map<QName, Serializable> properties, Collection<QName> keys,
        WorkflowTask task)
{
    Map<QName, PropertyDefinition> propDefs = task.getDefinition().getMetadata().getProperties();
    Map<String, Object> model = new HashMap<String, Object>();
    for (QName key : keys)
    {
        Object value = convertValue(properties.get(key));
        String strKey = qNameConverter.mapQNameToName(key);
        PropertyDefinition propDef = propDefs.get(key);
        if ((value == null) && (propDef != null))
        {
            value = propDef.getDefaultValue();
        }
        model.put(strKey, value);
    }
    return model;
}
 
Example 8
Source File: CustomModelProperty.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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));
            }
        }
    }
}