Search in sources :

Example 96 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.

the class CanSetPropertyBooleanTest method testValueConstraintNotSatisfiedMultiple.

/**
     * Tests if canSetProperty(String propertyName, Value[] values) returns
     * false if values do not satisfy the value constraints of the property def
     */
public void testValueConstraintNotSatisfiedMultiple() throws NotExecutableException, ParseException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, true, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value[] values = new Value[] { value };
    assertFalse("canSetProperty(String propertyName, Value[] values) must " + "return false if values do not match the value constraints.", nodeType.canSetProperty(propDef.getName(), values));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 97 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.

the class QueryImpl method getColumns.

/**
     * Returns the columns for this query.
     *
     * @return array of columns.
     * @throws RepositoryException if an error occurs.
     */
protected ColumnImpl[] getColumns() throws RepositoryException {
    SessionImpl session = sessionContext.getSessionImpl();
    QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
    // get columns
    Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
    for (Name name : root.getSelectProperties()) {
        String pn = sessionContext.getJCRName(name);
        ColumnImpl col = (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), pn, pn);
        columns.put(name, col);
    }
    if (columns.size() == 0) {
        // use node type constraint
        LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
        final Name[] ntName = new Name[1];
        steps[steps.length - 1].acceptOperands(new DefaultQueryNodeVisitor() {

            public Object visit(AndQueryNode node, Object data) throws RepositoryException {
                return node.acceptOperands(this, data);
            }

            public Object visit(NodeTypeQueryNode node, Object data) {
                ntName[0] = node.getValue();
                return data;
            }
        }, null);
        if (ntName[0] == null) {
            ntName[0] = NameConstants.NT_BASE;
        }
        NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
        PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
        for (PropertyDefinition pd : propDefs) {
            QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
            if (!propDef.definesResidual() && !propDef.isMultiple()) {
                columns.put(propDef.getName(), columnForName(propDef.getName()));
            }
        }
    }
    // add jcr:path and jcr:score if not selected already
    if (!columns.containsKey(NameConstants.JCR_PATH)) {
        columns.put(NameConstants.JCR_PATH, columnForName(NameConstants.JCR_PATH));
    }
    if (!columns.containsKey(NameConstants.JCR_SCORE)) {
        columns.put(NameConstants.JCR_SCORE, columnForName(NameConstants.JCR_SCORE));
    }
    return columns.values().toArray(new ColumnImpl[columns.size()]);
}
Also used : NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) LocationStepQueryNode(org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) LinkedHashMap(java.util.LinkedHashMap) Name(org.apache.jackrabbit.spi.Name) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) SessionImpl(org.apache.jackrabbit.core.SessionImpl) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) ColumnImpl(org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl) DefaultQueryNodeVisitor(org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeVisitor) NodeTypeQueryNode(org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode) AndQueryNode(org.apache.jackrabbit.spi.commons.query.AndQueryNode)

Example 98 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.

the class SetPropertyAssumeTypeTest method setUpNodeWithUndefinedProperty.

//--------------------------< internal >------------------------------------
private void setUpNodeWithUndefinedProperty(boolean multiple) throws NotExecutableException {
    try {
        // locate a property definition of type undefined
        PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.UNDEFINED, multiple, false, false, false);
        if (propDef == null) {
            throw new NotExecutableException("No testable property of type " + "UNDEFINED has been found.");
        }
        // create a node of type propDef.getDeclaringNodeType()
        String nodeType = propDef.getDeclaringNodeType().getName();
        testNode = testRootNode.addNode(nodeName1, nodeType);
        testPropName = propDef.getName();
    } catch (RepositoryException e) {
        throw new NotExecutableException("Not able to set up test items.");
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 99 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.

the class SetPropertyConstraintViolationExceptionTest method testBooleanProperty.

/**
     * Tests if setProperty(String name, boolean value) and setProperty(String
     * name, Value value) where value is a BooleanValue throw a
     * ConstraintViolationException either immediately (by setProperty()), or on
     * save, if the change would violate a node type constraint
     */
public void testBooleanProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BOOLEAN, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No boolean property def with " + "testable value constraints has been found");
    }
    // find a Value that does not satisfy the ValueConstraints of propDef
    Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    if (valueNotSatisfied == null) {
        throw new NotExecutableException("No boolean property def with " + "testable value constraints has been found");
    }
    // create a sub node of testRootNode of type propDef.getDeclaringNodeType()
    Node node;
    try {
        String nodeType = propDef.getDeclaringNodeType().getName();
        node = testRootNode.addNode(nodeName2, nodeType);
        testRootNode.getSession().save();
    } catch (ConstraintViolationException e) {
        // implementation specific constraints do not allow to set up test environment
        throw new NotExecutableException("Not able to create required test items.");
    }
    // test of signature setProperty(String name, boolean value)
    try {
        node.setProperty(propDef.getName(), valueNotSatisfied.getBoolean());
        node.save();
        fail("setProperty(String name, boolean value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    }
    // test of signature setProperty(String name, Value value)
    try {
        node.setProperty(propDef.getName(), valueNotSatisfied);
        node.save();
        fail("setProperty(String name, boolean value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 100 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.

the class SetPropertyConstraintViolationExceptionTest method testDoubleProperty.

/**
     * Tests if setProperty(String name, double value) and setProperty(String
     * name, Value value) where value is a DoubleValue throw a
     * ConstraintViolationException either immediately (by setProperty()), or on
     * save, if the change would violate a node type constraint
     */
public void testDoubleProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.DOUBLE, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
    }
    // find a Value that does not satisfy the ValueConstraints of propDef
    Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    if (valueNotSatisfied == null) {
        throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
    }
    // create a sub node of testRootNode of type propDef.getDeclaringNodeType()
    Node node;
    try {
        String nodeType = propDef.getDeclaringNodeType().getName();
        node = testRootNode.addNode(nodeName2, nodeType);
        testRootNode.getSession().save();
    } catch (ConstraintViolationException e) {
        // implementation specific constraints do not allow to set up test environment
        throw new NotExecutableException("Not able to create required test items.");
    }
    // test of signature setProperty(String name, double value)
    try {
        node.setProperty(propDef.getName(), valueNotSatisfied.getDouble());
        node.save();
        fail("setProperty(String name, double value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    }
    // test of signature setProperty(String name, Value value)
    try {
        node.setProperty(propDef.getName(), valueNotSatisfied);
        node.save();
        fail("setProperty(String name, Value value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Aggregations

PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)141 NodeType (javax.jcr.nodetype.NodeType)79 Value (javax.jcr.Value)70 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)61 Node (javax.jcr.Node)27 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)22 Property (javax.jcr.Property)20 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)15 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)14 RepositoryException (javax.jcr.RepositoryException)13 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)11 Test (org.junit.Test)11 InputStream (java.io.InputStream)5 Session (javax.jcr.Session)5 ValueFormatException (javax.jcr.ValueFormatException)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 Name (org.apache.jackrabbit.spi.Name)4