Search in sources :

Example 26 with PropertyIterator

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

the class AuthorizableImplTest method testUserGetProperties.

public void testUserGetProperties() throws RepositoryException, NotExecutableException {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    NodeImpl n = user.getNode();
    for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
        PropertyImpl p = (PropertyImpl) it.nextProperty();
        if (p.getDefinition().isProtected()) {
            assertFalse(user.hasProperty(p.getName()));
            assertNull(user.getProperty(p.getName()));
        } else {
            // authorizable defined property
            assertTrue(user.hasProperty(p.getName()));
            assertNotNull(user.getProperty(p.getName()));
        }
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) PropertyIterator(javax.jcr.PropertyIterator) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl)

Example 27 with PropertyIterator

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

the class VersionItemCollection method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null && exists()) {
        Version v = (Version) item;
        try {
            if (VERSION_NAME.equals(name)) {
                // required, protected DAV:version-name property
                prop = new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true);
            } else if (VERSION_HISTORY.equals(name)) {
                // required DAV:version-history (computed) property
                String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
                prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
            } else if (PREDECESSOR_SET.equals(name)) {
                // required DAV:predecessor-set (protected) property
                prop = getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
            } else if (SUCCESSOR_SET.equals(name)) {
                // required DAV:successor-set (computed) property
                prop = getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
            } else if (LABEL_NAME_SET.equals(name)) {
                // required, protected DAV:label-name-set property
                String[] labels = getVersionHistoryItem().getVersionLabels(v);
                prop = new LabelSetProperty(labels);
            } else if (CHECKOUT_SET.equals(name)) {
                // required DAV:checkout-set (computed) property
                PropertyIterator it = v.getReferences();
                List<Node> nodeList = new ArrayList<Node>();
                while (it.hasNext()) {
                    Property p = it.nextProperty();
                    if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
                        Node n = p.getParent();
                        if (n.isCheckedOut()) {
                            nodeList.add(n);
                        }
                    }
                }
                prop = getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
    return prop;
}
Also used : LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) List(java.util.List) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Example 28 with PropertyIterator

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

the class JsonWriterTest method testDoubleOutput.

@Test
public void testDoubleOutput() throws Exception {
    StringWriter writer = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(writer);
    Node parent = createMock(Node.class);
    Property doubleProperty = createMock(Property.class);
    Value doublePropertyValue = createMock(Value.class);
    expect(doubleProperty.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
    expect(doubleProperty.getName()).andReturn("singleValued").anyTimes();
    expect(doubleProperty.isMultiple()).andReturn(false).anyTimes();
    expect(doubleProperty.getValue()).andReturn(doublePropertyValue).anyTimes();
    expect(doublePropertyValue.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
    expect(doublePropertyValue.getDouble()).andReturn(5d).anyTimes();
    expect(doublePropertyValue.getString()).andReturn("5").anyTimes();
    Property mvDoubleProperty = createMock(Property.class);
    Value mvDoublePropertyValue1 = createMock(Value.class);
    Value mvDoublePropertyValue2 = createMock(Value.class);
    expect(mvDoubleProperty.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
    expect(mvDoubleProperty.getName()).andReturn("multiValued").anyTimes();
    expect(mvDoubleProperty.isMultiple()).andReturn(true).anyTimes();
    expect(mvDoubleProperty.getValues()).andReturn(new Value[] { mvDoublePropertyValue1, mvDoublePropertyValue2 }).anyTimes();
    expect(mvDoublePropertyValue1.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
    expect(mvDoublePropertyValue1.getDouble()).andReturn(42d).anyTimes();
    expect(mvDoublePropertyValue1.getString()).andReturn("42").anyTimes();
    expect(mvDoublePropertyValue2.getType()).andReturn(PropertyType.DOUBLE).anyTimes();
    expect(mvDoublePropertyValue2.getDouble()).andReturn(98.6).anyTimes();
    expect(mvDoublePropertyValue2.getString()).andReturn("98.6").anyTimes();
    final List<Property> properties = new ArrayList<Property>();
    properties.add(doubleProperty);
    properties.add(mvDoubleProperty);
    expect(parent.getProperties()).andAnswer(new IAnswer<PropertyIterator>() {

        @Override
        public PropertyIterator answer() throws Throwable {
            return new PropertyIteratorAdapter(properties.iterator());
        }
    });
    expect(parent.getNodes()).andAnswer(new IAnswer<NodeIterator>() {

        @Override
        public NodeIterator answer() throws Throwable {
            return new NodeIteratorAdapter(Collections.<Node>emptyIterator());
        }
    });
    replayAll();
    jsonWriter.write(parent, 1);
    assertEquals("{\":singleValued\":\"Double\",\"singleValued\":5,\":multiValued\":\"Double\",\"multiValued\":[42,98.6],\"::NodeIteratorSize\":0}", writer.toString());
    verifyAll();
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIteratorAdapter(org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) NodeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter) StringWriter(java.io.StringWriter) Value(javax.jcr.Value) Property(javax.jcr.Property) Test(org.junit.Test)

Example 29 with PropertyIterator

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

the class PropertyUtil method searchMultivalProp.

/**
 * Helper method to find a multivalue property.
 *
 * @param node the node to start the search from.
 * @return a multivalue property or null if not found any.
 */
public static Property searchMultivalProp(Node node) throws RepositoryException {
    Property multiVal = null;
    for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
        Property property = props.nextProperty();
        if (property.getDefinition().isMultiple()) {
            multiVal = property;
            break;
        }
    }
    if (multiVal == null) {
        for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
            Node n = nodes.nextNode();
            multiVal = searchMultivalProp(n);
            if (multiVal != null) {
                break;
            }
        }
    }
    return multiVal;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 30 with PropertyIterator

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

the class PropertyUtil method searchMultivalProp.

/**
 * Helper method to find a multivalue property of a given type.
 *
 * @param node the node to start the search from.
 * @param type the property type.
 * @return a multivalue property or null if not found any.
 */
public static Property searchMultivalProp(Node node, int type) throws RepositoryException {
    Property multiVal = null;
    for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
        Property property = props.nextProperty();
        if (property.getDefinition().isMultiple() && property.getType() == type) {
            multiVal = property;
            break;
        }
    }
    if (multiVal == null) {
        for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
            Node n = nodes.nextNode();
            multiVal = searchMultivalProp(n, type);
            if (multiVal != null) {
                break;
            }
        }
    }
    return multiVal;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) 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