Search in sources :

Example 41 with PropertyIterator

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

the class NodeReadMethodsTest method testGetReferences.

public void testGetReferences() throws NotExecutableException, RepositoryException {
    Node node = locateNodeWithReference(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node with a reference property set");
    }
    PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        Property p = properties.nextProperty();
        if (p.getType() == PropertyType.REFERENCE && !p.getDefinition().isMultiple()) {
            Node referencedNode = p.getNode();
            PropertyIterator refs = referencedNode.getReferences();
            boolean referenceFound = false;
            while (refs.hasNext()) {
                Property ref = refs.nextProperty();
                if (ref.isSame(p)) {
                    referenceFound = true;
                }
            }
            assertTrue("Correct reference not found", referenceFound);
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 42 with PropertyIterator

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

the class NodeReadMethodsTest method locateNodeWithReference.

/**
 * Returns the first descendant of <code>node</code> which has a property of
 * type {@link javax.jcr.PropertyType#REFERENCE} set and is <b>not</b>
 * multivalued.
 *
 * @param node <code>Node</code> to start traversal.
 * @return first node with a property of PropertType.REFERENCE
 */
private Node locateNodeWithReference(Node node) throws RepositoryException {
    PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
        Property p = properties.nextProperty();
        if (p.getType() == PropertyType.REFERENCE && !p.getDefinition().isMultiple()) {
            return node;
        }
    }
    NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
        Node returnedNode = locateNodeWithReference(nodes.nextNode());
        if (returnedNode != null) {
            return returnedNode;
        }
    }
    return null;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 43 with PropertyIterator

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

the class GetWeakReferencesTest method testSingleValueWithName.

public void testSingleValueWithName() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    referring.setProperty(propertyName1, weakRef);
    superuser.save();
    PropertyIterator it = target.getWeakReferences(propertyName1);
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 44 with PropertyIterator

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

the class GetWeakReferencesTest method testMultiValuesWithName.

public void testMultiValuesWithName() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    Value[] refs = new Value[] { weakRef, weakRef };
    referring.setProperty(propertyName1, refs);
    superuser.save();
    PropertyIterator it = target.getWeakReferences(propertyName1);
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 45 with PropertyIterator

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

the class GetWeakReferencesTest method testSingleValue.

public void testSingleValue() throws RepositoryException {
    Value weakRef = vf.createValue(target, true);
    referring.setProperty(propertyName1, weakRef);
    superuser.save();
    PropertyIterator it = target.getWeakReferences();
    assertTrue("no weak references returned", it.hasNext());
    Property p = it.nextProperty();
    assertEquals("wrong weak reference property", referring.getProperty(propertyName1).getPath(), p.getPath());
    assertFalse("no more weak references expected", it.hasNext());
}
Also used : Value(javax.jcr.Value) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)130 Property (javax.jcr.Property)97 Node (javax.jcr.Node)79 NodeIterator (javax.jcr.NodeIterator)31 RepositoryException (javax.jcr.RepositoryException)28 Value (javax.jcr.Value)28 Session (javax.jcr.Session)21 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)14 PathNotFoundException (javax.jcr.PathNotFoundException)13 HashMap (java.util.HashMap)12 AccessDeniedException (javax.jcr.AccessDeniedException)7 Item (javax.jcr.Item)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)4 AccessControlException (java.security.AccessControlException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)4