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

The following examples show how to use org.alfresco.service.cmr.dictionary.PropertyDefinition#isMandatoryEnforced() . 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: IncompleteNodeTagger.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param propertyDefs the property definitions to check
 * @param properties the properties
 * @return Returns true if the property definitions were all satisified
 */
private boolean checkProperties(
        Collection<PropertyDefinition> propertyDefs,
        Map<QName, Serializable> properties)
{
    for (PropertyDefinition propertyDef : propertyDefs)
    {
        if (propertiesToIgnore.contains(propertyDef.getName()))
        {
            continue;
        }
        
        if (!propertyDef.isMandatory())
        {
            // The property isn't mandatory in any way
            continue;
        }
        else if (propertyDef.isMandatoryEnforced())
        {
            // The mandatory nature of the property is fully enforced
            // Leave these for integrity
            continue;
        }
        // The mandatory nature of the property is 'soft' a.k.a. 'required'
        // Check that the property value has been supplied
        if (properties.get(propertyDef.getName()) == null)
        {
            // property NOT supplied
            return false;
        }
    }
    // all properties were present
    return true;
}
 
Example 2
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));
            }
        }
    }
}
 
Example 3
Source File: M2PropertyDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: DataDictionaryBuilderImpl.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
private String classDefinitionToString(final ClassDefinition definition)
{
    StringBuilder result = null;
    
    if (definition != null)
    {
        result = new StringBuilder(1024);
        result.append("\n\t\t\t");
        result.append(definition.getName().toPrefixString());
        
        result.append("\n\t\t\t\tParent: ");
        result.append(definition.getParentName() == null ? "<none>" : definition.getParentName().getPrefixString());
        
        result.append("\n\t\t\t\tProperties:");
        Map<QName,PropertyDefinition> properties = definition.getProperties();
        if (properties != null && properties.size() > 0)
        {
            for (QName propertyName : properties.keySet())
            {
                PropertyDefinition propertyDefinition = properties.get(propertyName);
                
                result.append("\n\t\t\t\t\t");
                result.append(propertyName.toPrefixString());
                result.append(" (");
                result.append(propertyDefinition.getDataType().getName().getPrefixString());
                result.append(")");
                
                if (propertyDefinition.isMultiValued())
                {
                    result.append(" (multi-valued)");
                }
                
                if (propertyDefinition.isMandatoryEnforced())
                {
                    result.append(" (mandatory)");
                }
                
                List<ConstraintDefinition> propertyConstraints = propertyDefinition.getConstraints();
                if (propertyConstraints != null && propertyConstraints.size() > 0)
                {
                    result.append(" (constraints: ");
                    for (ConstraintDefinition propertyConstraint : propertyConstraints)
                    {
                        result.append(propertyConstraint.getName().toPrefixString());
                        result.append(", ");
                    }
                    
                    result.delete(result.length() - ", ".length(), result.length());
                    result.append(")");
                }
            }
        }
        else
        {
            result.append("\n\t\t\t\t\t<none>");
        }
        
        result.append("\n\t\t\t\tAssociations:");
        Map<QName, AssociationDefinition> associations = definition.getAssociations();
        if (associations != null && associations.size() > 0)
        {
            for (QName associationName : associations.keySet())
            {
                AssociationDefinition associationDefinition = associations.get(associationName);
                
                result.append("\n\t\t\t\t\t");
                result.append(associationName.toPrefixString());
                
                result.append(associationDefinition.isChild() ? " (parent/child)" : " (peer)");
                
                result.append(" (source: ");
                result.append(associationDefinition.getSourceClass().getName().toPrefixString());
                result.append(")");
                
                result.append(" (target: ");
                result.append(associationDefinition.getTargetClass().getName().toPrefixString());
                result.append(")");
            }
        }
        else
        {
            result.append("\n\t\t\t\t\t<none>");
        }
    }
    
    return(result == null ? null : result.toString());
}