Search in sources :

Example 1 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class NodeImpl method internalSetProperty.

private Property internalSetProperty(final String jcrName, final Value[] values, final int type, final boolean exactTypeMatch) throws RepositoryException {
    final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
    final PropertyState state = createMultiState(oakName, compact(values), Type.fromTag(type, true));
    if (values.length > MV_PROPERTY_WARN_THRESHOLD) {
        LOG.warn("Large multi valued property [{}/{}] detected ({} values).", dlg.getPath(), jcrName, values.length);
    }
    return perform(new ItemWriteOperation<Property>("internalSetProperty") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut() && getOPV(dlg.getTree(), state) != OnParentVersionAction.IGNORE) {
                throw new VersionException(format("Cannot set property. Node [%s] is checked in.", getNodePath()));
            }
        }

        @Nonnull
        @Override
        public Property perform() throws RepositoryException {
            return new PropertyImpl(dlg.setProperty(state, exactTypeMatch, false), sessionContext);
        }

        @Override
        public String toString() {
            return format("Setting property [%s/%s]", dlg.getPath(), jcrName);
        }
    });
}
Also used : Nonnull(javax.annotation.Nonnull) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) VersionException(javax.jcr.version.VersionException)

Example 2 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class ObservationTest method testAggregate3.

@Test
public void testAggregate3() throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setAbsPath("/parent");
    filter.setIsDeep(true);
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**" });
    oManager.addEventListener(listener, filter);
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expect(parent.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node child = parent.addNode("child", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(child);
    Node file = child.addNode("file", "oak:Unstructured");
    listener.expect(file.getPath(), "/parent/child/file", NODE_ADDED);
    listener.expect(file.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
    Node jcrContent = file.addNode("jcr:content", "nt:unstructured");
    listener.expect(jcrContent.getPath(), "/parent/child/file", NODE_ADDED);
    listener.expect(jcrContent.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
    Property jcrDataProperty = jcrContent.setProperty("jcr:data", "foo");
    listener.expect(jcrDataProperty.getPath(), "/parent/child/file", PROPERTY_ADDED);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) Property(javax.jcr.Property) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 3 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class ReadDeepTreeTest method createDeepTree.

protected void createDeepTree() throws Exception {
    Node rn = adminSession.getRootNode();
    allPaths.clear();
    String testNodeName = getTestNodeName();
    long start = System.currentTimeMillis();
    if (!rn.hasNode(testNodeName)) {
        testRoot = adminSession.getRootNode().addNode(testNodeName, "nt:unstructured");
        InputStream in = getClass().getClassLoader().getResourceAsStream(getImportFileName());
        adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        adminSession.save();
    } else {
        testRoot = rn.getNode(testNodeName);
    }
    System.out.println("Import deep tree: " + (System.currentTimeMillis() - start));
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            visitingNode(node, i);
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            visitingProperty(prop, i);
            super.entering(prop, i);
        }
    };
    v.visit(testRoot);
    System.out.println("All paths: " + allPaths.size());
}
Also used : ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) InputStream(java.io.InputStream) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 4 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class ConcurrentEveryoneACLTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    Session session = loginWriter();
    AccessControlManager acMgr = session.getAccessControlManager();
    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
    final Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
        Node node = root.addNode("node" + i, "nt:unstructured");
        for (int j = 0; j < NODE_COUNT; j++) {
            Node newNode = node.addNode("node" + j, "nt:unstructured");
            JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, newNode.getPath());
            acl.addEntry(EveryonePrincipal.getInstance(), privileges, true);
            acMgr.setPolicy(newNode.getPath(), acl);
        }
        session.save();
    }
    // deny everyone on root node
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, root.getPath());
    acl.addEntry(EveryonePrincipal.getInstance(), privileges, false);
    acMgr.setPolicy(root.getPath(), acl);
    session.save();
    final int[] numACEs = new int[1];
    ItemVisitor v = new TraversingItemVisitor.Default() {

        @Override
        protected void entering(Node node, int i) throws RepositoryException {
            if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
                numACEs[0]++;
            }
            super.entering(node, i);
        }

        @Override
        protected void entering(Property prop, int i) throws RepositoryException {
            super.entering(prop, i);
        }
    };
    v.visit(root);
    System.out.println("Num ACEs: " + numACEs[0]);
    session.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 5 with Property

use of javax.jcr.Property in project jackrabbit-oak by apache.

the class RepositoryTest method addMultiValuedLong.

@Test
public void addMultiValuedLong() throws RepositoryException {
    Node parentNode = getNode(TEST_PATH);
    Value[] values = new Value[2];
    values[0] = getAdminSession().getValueFactory().createValue(42L);
    values[1] = getAdminSession().getValueFactory().createValue(84L);
    parentNode.setProperty("multi long", values);
    parentNode.getSession().save();
    Session session2 = createAnonymousSession();
    try {
        Property property = session2.getProperty(TEST_PATH + "/multi long");
        assertTrue(property.isMultiple());
        assertEquals(PropertyType.LONG, property.getType());
        Value[] values2 = property.getValues();
        assertEquals(values.length, values2.length);
        assertEquals(values[0], values2[0]);
        assertEquals(values[1], values2[1]);
    } finally {
        session2.logout();
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

Property (javax.jcr.Property)559 Node (javax.jcr.Node)321 Test (org.junit.Test)118 Value (javax.jcr.Value)115 RepositoryException (javax.jcr.RepositoryException)105 PropertyIterator (javax.jcr.PropertyIterator)101 Session (javax.jcr.Session)96 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)36 NodeIterator (javax.jcr.NodeIterator)32 ArrayList (java.util.ArrayList)31 QValue (org.apache.jackrabbit.spi.QValue)29 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)26 PathNotFoundException (javax.jcr.PathNotFoundException)25 Item (javax.jcr.Item)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 HashMap (java.util.HashMap)21 AccessDeniedException (javax.jcr.AccessDeniedException)21 Version (javax.jcr.version.Version)19