Search in sources :

Example 76 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class NodeImpl method createProperty.

/**
     * Create a new multi valued property
     *
     * @param qName
     * @param type
     * @param values
     * @return
     * @throws ConstraintViolationException
     * @throws RepositoryException
     */
private Property createProperty(Name qName, Value[] values, int type) throws ConstraintViolationException, RepositoryException {
    QPropertyDefinition def = getApplicablePropertyDefinition(qName, type, true);
    int targetType = def.getRequiredType();
    // make sure, the final type is not set to undefined
    if (targetType == PropertyType.UNDEFINED) {
        if (type == PropertyType.UNDEFINED) {
            // try to retrieve type from the values array
            if (values.length > 0) {
                for (Value value : values) {
                    if (value != null) {
                        targetType = value.getType();
                        break;
                    }
                }
            }
            if (targetType == PropertyType.UNDEFINED) {
                // fallback
                targetType = PropertyType.STRING;
            }
        } else {
            targetType = type;
        }
    }
    Value[] targetValues = ValueHelper.convert(values, targetType, session.getValueFactory());
    QValue[] qvs = ValueFormat.getQValues(targetValues, session.getNamePathResolver(), session.getQValueFactory());
    return createProperty(qName, targetType, def, qvs);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value)

Example 77 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class AccessControlManagerImpl method addProperty.

private void addProperty(SetTree treeOperation, NodeState parent, Name propName, int propType, QValue[] values) throws RepositoryException {
    QPropertyDefinition definition = definitionProvider.getQPropertyDefinition(parent.getAllNodeTypeNames(), propName, propType);
    Operation ap = treeOperation.addChildProperty(parent, propName, propType, values, definition);
    itemStateMgr.execute(ap);
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation)

Example 78 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class ItemStateValidator method validate.

/**
     * Checks whether the given node state satisfies the constraints specified
     * by its primary and mixin node types. The following validations/checks are
     * performed:
     * <ul>
     * <li>check if its node type satisfies the 'required node types' constraint
     * specified in its definition</li>
     * <li>check if all 'mandatory' child items exist</li>
     * <li>for every property: check if the property value satisfies the
     * value constraints specified in the property's definition</li>
     * </ul>
     *
     * @param nodeState state of node to be validated
     * @throws ConstraintViolationException if any of the validations fail
     * @throws RepositoryException          if another error occurs
     */
public void validate(NodeState nodeState) throws ConstraintViolationException, RepositoryException {
    // effective primary node type
    EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
    QNodeDefinition def = nodeState.getDefinition();
    // check if primary type satisfies the 'required node types' constraint
    Name[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
    for (int i = 0; i < requiredPrimaryTypes.length; i++) {
        if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
            String msg = safeGetJCRPath(nodeState) + ": missing required primary type " + requiredPrimaryTypes[i];
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        }
    }
    // mandatory properties
    // effective node type (primary type incl. mixins)
    Name[] ntNames = nodeState.getAllNodeTypeNames();
    EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
    QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
    for (int i = 0; i < pda.length; i++) {
        QPropertyDefinition pd = pda[i];
        if (!nodeState.hasPropertyName(pd.getName())) {
            String msg = safeGetJCRPath(nodeState) + ": mandatory property " + pd.getName() + " does not exist";
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        }
    }
    // mandatory child nodes
    QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
    for (int i = 0; i < cnda.length; i++) {
        QNodeDefinition cnd = cnda[i];
        if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getName())) {
            String msg = safeGetJCRPath(nodeState) + ": mandatory child node " + cnd.getName() + " does not exist";
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        }
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 79 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class ItemStateValidator method checkSetProperty.

/**
     *
     * @param propState
     * @param options bit-wise OR'ed flags specifying the checks that should be
     * performed; any combination of the following constants:
     * <ul>
     * <li><code>{@link #CHECK_ACCESS}</code>: make sure current session is
     * granted read access on parent node and can add a child node with the
     * given name.</li>
     * <li><code>{@link #CHECK_LOCK}</code>: make sure there's no foreign lock
     * on parent node</li>
     * <li><code>{@link #CHECK_VERSIONING}</code>: make sure parent node is
     * checked-out</li>
     * <li><code>{@link #CHECK_CONSTRAINTS}</code>: make sure no node type
     * constraints would be violated</li>
     * <li><code>{@link #CHECK_COLLISION}</code>: check for collision with
     * existing properties or nodes</li>
     * </ul>
     *
     * @throws ConstraintViolationException
     * @throws AccessDeniedException
     * @throws VersionException
     * @throws LockException
     * @throws ItemNotFoundException
     * @throws ItemExistsException
     * @throws PathNotFoundException
     * @throws RepositoryException
     */
public void checkSetProperty(PropertyState propState, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, PathNotFoundException, RepositoryException {
    NodeState parent = propState.getParent();
    QPropertyDefinition def = propState.getDefinition();
    checkWriteProperty(parent, propState.getName(), def, options);
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Example 80 with QPropertyDefinition

use of org.apache.jackrabbit.spi.QPropertyDefinition in project jackrabbit by apache.

the class PropertyDefinitionImpl method getDefaultValues.

//-------------------------------------------------< PropertyDefinition >---
/**
     * {@inheritDoc}
     */
public Value[] getDefaultValues() {
    QPropertyDefinition pDef = ((QPropertyDefinition) itemDef);
    QValue[] defVals = pDef.getDefaultValues();
    if (defVals == null) {
        return null;
    }
    Value[] values = new Value[defVals.length];
    for (int i = 0; i < defVals.length; i++) {
        try {
            values[i] = ValueFormat.getJCRValue(defVals[i], resolver, valueFactory);
        } catch (RepositoryException e) {
            // should never get here
            String propName = (getName() == null) ? "[null]" : getName();
            log.error("illegal default value specified for property " + propName + " in node type " + getDeclaringNodeType(), e);
            return null;
        }
    }
    return values;
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) Value(javax.jcr.Value) QValue(org.apache.jackrabbit.spi.QValue) RepositoryException(javax.jcr.RepositoryException) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint)

Aggregations

QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)81 Name (org.apache.jackrabbit.spi.Name)32 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)22 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)19 RepositoryException (javax.jcr.RepositoryException)14 QValue (org.apache.jackrabbit.spi.QValue)12 QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)9 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)9 ArrayList (java.util.ArrayList)8 Value (javax.jcr.Value)7 InternalValue (org.apache.jackrabbit.core.value.InternalValue)7 ItemExistsException (javax.jcr.ItemExistsException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 PropertyState (org.apache.jackrabbit.core.state.PropertyState)5 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)5 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)5 NodeState (org.apache.jackrabbit.core.state.NodeState)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4