Search in sources :

Example 71 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class GetReferencesNodeTest method testGetReferencesNeverFromVersions.

/**
     * Node.getReferences() never returns a reference that is stored in a
     * version. 1. Create some test nodes 2. Create a version 1.0 with reference
     * 3. Create a new version 1.1 after changing reference 4. Check if
     * reference is found by getReferences()
     */
public void testGetReferencesNeverFromVersions() throws RepositoryException, NotExecutableException {
    // create some test nodes
    initTestNodes();
    // create a version 1.0 and reference test node
    testNode.checkout();
    ensureCanSetProperty(testNode, propertyName1, PropertyType.REFERENCE, false);
    testNode.setProperty(propertyName1, nodeToBeReferenced);
    testRootNode.getSession().save();
    testNode.checkin();
    // create a version 1.1 and remove reference
    testNode.checkout();
    testNode.getProperty(propertyName1).remove();
    testRootNode.getSession().save();
    testNode.checkin();
    // check if reference is returned
    boolean nodeToBeReferencedIsReference = false;
    PropertyIterator propIter = nodeToBeReferenced.getReferences();
    while (propIter.hasNext()) {
        nodeToBeReferencedIsReference = true;
        fail("Reference found in version.");
    // not successful
    }
    // references in versions should not be found
    assertFalse(nodeToBeReferencedIsReference);
}
Also used : PropertyIterator(javax.jcr.PropertyIterator)

Example 72 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class NodeImpl method removeMixin.

/**
     * @see Node#removeMixin(String)
     */
public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
    checkIsWritable();
    Name ntName = getQName(mixinName);
    List<Name> mixinValue = getMixinTypes();
    // remove name of target mixin
    if (!mixinValue.remove(ntName)) {
        throw new NoSuchNodeTypeException("Cannot remove mixin '" + mixinName + "': Nodetype is not present on this node.");
    }
    // mix:referenceable needs additional assertion: the mixin cannot be
    // removed, if any references are left to this node.
    NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
    if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            PropertyIterator iter = getReferences();
            if (iter.hasNext()) {
                throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
            }
        }
    }
    /*
         * mix:lockable: the mixin cannot be removed if the node is currently
         * locked even if the editing session is the lock holder.
         */
    if (mixin.isNodeType((NameConstants.MIX_LOCKABLE))) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE) && isLocked()) {
            throw new ConstraintViolationException(mixinName + " can not be removed: the node is locked.");
        }
    }
    // delegate to operation
    Name[] mixins = mixinValue.toArray(new Name[mixinValue.size()]);
    Operation op = SetMixin.create(getNodeState(), mixins);
    session.getSessionItemStateManager().execute(op);
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeTypeImpl(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeImpl) PropertyIterator(javax.jcr.PropertyIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 73 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class HierarchyNodeTest method dump.

/** Recursively outputs the contents of the given node. */
private void dump(Node node) throws RepositoryException {
    // Then output the properties
    PropertyIterator properties = node.getProperties();
    Set<String> set = new HashSet<String>();
    while (properties.hasNext()) {
        Property property = properties.nextProperty();
        set.add(property.getName());
    }
    if (node.getPrimaryNodeType().getName().equals(ntFolder)) {
        assertTrue(hierarchyNodeProps.size() == set.size() && hierarchyNodeProps.containsAll(set));
    } else if (node.getPrimaryNodeType().getName().equals(ntFile)) {
        assertTrue(hierarchyNodeProps.size() == set.size() && hierarchyNodeProps.containsAll(set));
    } else if (node.getPrimaryNodeType().getName().equals(ntResource)) {
        assertTrue(resourceProps.size() == set.size() && resourceProps.containsAll(set));
    }
    // Finally output all the child nodes recursively
    NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        dump(nodes.nextNode());
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) HashSet(java.util.HashSet)

Example 74 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class GetPropertyTest method testGetDeepProperty.

public void testGetDeepProperty() throws RepositoryException {
    Node n2 = testRootNode.getNode(nodeName1).addNode(nodeName2);
    testRootNode.save();
    // other session directly accesses n2.
    // consequently n1 is not yet resolved
    Node node2 = (Node) readOnly.getItem(n2.getPath());
    // now try to access properties below n1 -> should be existing although
    // n1 has not yet been resolved.
    assertTrue(readOnly.itemExists(prop1Path));
    Property p1 = (Property) readOnly.getItem(prop1Path);
    assertTrue(p1.isSame(node2.getProperty("../" + Text.getName(prop1Path))));
    PropertyIterator it = node2.getParent().getProperties();
    assertTrue(it.getSize() >= 3);
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 75 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class RepositoryServiceImpl method getReferences.

/**
     * {@inheritDoc}
     */
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Node node = getNode(nodeId, sInfo);
    String jcrName = (propertyName == null) ? null : sInfo.getNamePathResolver().getJCRName(propertyName);
    List<PropertyId> ids = new ArrayList<PropertyId>();
    PropertyIterator it;
    if (weakReferences) {
        it = node.getWeakReferences(jcrName);
    } else {
        it = node.getReferences(jcrName);
    }
    while (it.hasNext()) {
        ids.add(idFactory.createPropertyId(it.nextProperty(), sInfo.getNamePathResolver()));
    }
    return ids.iterator();
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)96 Property (javax.jcr.Property)68 Node (javax.jcr.Node)57 NodeIterator (javax.jcr.NodeIterator)28 Value (javax.jcr.Value)23 Test (org.junit.Test)16 RepositoryException (javax.jcr.RepositoryException)15 Session (javax.jcr.Session)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)10 PathNotFoundException (javax.jcr.PathNotFoundException)8 HashMap (java.util.HashMap)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 NodeImpl (org.apache.jackrabbit.core.NodeImpl)5 PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)5 NoSuchElementException (java.util.NoSuchElementException)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 ValueFormatException (javax.jcr.ValueFormatException)3 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3