Search in sources :

Example 11 with NodeTypeManager

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

the class NodeTypeDefinitionManagementTest method testUnRegisterNodeType.

@Test
public void testUnRegisterNodeType() throws Exception {
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testUnregisterNodeType");
    ntd.setMixin(true);
    ntm.registerNodeType(ntd, true);
    Workspace testWsp = testSession.getWorkspace();
    try {
        try {
            NodeTypeManager testNtm = testWsp.getNodeTypeManager();
            testNtm.unregisterNodeType(ntd.getName());
            fail("Node type unregistration should be denied.");
        } catch (AccessDeniedException e) {
        // success
        }
        try {
            NodeTypeManager testNtm = testWsp.getNodeTypeManager();
            testNtm.unregisterNodeTypes(new String[] { ntd.getName() });
            fail("Node type unregistration should be denied.");
        } catch (AccessDeniedException e) {
        // success
        }
    } finally {
        // NOTE: diff to jr-core where unregisterNt was not supported
        ntm.unregisterNodeType(ntd.getName());
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 12 with NodeTypeManager

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

the class OpvIgnoreTest method createNodeTypeWithIgnoreOPVProperty.

private NodeTypeTemplate createNodeTypeWithIgnoreOPVProperty(String propertyName) throws RepositoryException {
    NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate nt = manager.createNodeTypeTemplate();
    nt.setName("testType");
    nt.setMixin(true);
    PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
    opt.setMandatory(false);
    opt.setName(propertyName);
    opt.setRequiredType(PropertyType.STRING);
    opt.setOnParentVersion(OnParentVersionAction.IGNORE);
    List pdt = nt.getPropertyDefinitionTemplates();
    pdt.add(opt);
    manager.registerNodeType(nt, true);
    return nt;
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) List(java.util.List)

Example 13 with NodeTypeManager

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

the class OpvAbortTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    vMgr = superuser.getWorkspace().getVersionManager();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeDefinitionTemplate def = ntMgr.createNodeDefinitionTemplate();
    def.setOnParentVersion(OnParentVersionAction.ABORT);
    def.setName("child");
    def.setRequiredPrimaryTypeNames(new String[] { NT_BASE });
    NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
    tmpl.setName("OpvAbortTest");
    tmpl.setMixin(true);
    tmpl.getNodeDefinitionTemplates().add(def);
    ntMgr.registerNodeType(tmpl, true);
    testRootNode.addMixin(MIX_VERSIONABLE);
    superuser.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate)

Example 14 with NodeTypeManager

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

the class RepositoryCopierTest method verifyTargetRepository.

private void verifyTargetRepository() throws Exception {
    RepositoryImpl repository = RepositoryImpl.create(RepositoryConfig.create(TARGET));
    try {
        Session session = repository.login(CREDENTIALS);
        try {
            assertEquals("http://www.example.org/", session.getNamespaceURI("test"));
            NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
            assertTrue(manager.hasNodeType("test:unstructured"));
            NodeType type = manager.getNodeType("test:unstructured");
            assertFalse(type.isMixin());
            assertTrue(type.isNodeType("nt:unstructured"));
            assertTrue(session.nodeExists("/properties"));
            Node properties = session.getNode("/properties");
            assertEquals(PropertyType.BOOLEAN, properties.getProperty("boolean").getType());
            assertEquals(true, properties.getProperty("boolean").getBoolean());
            assertEquals(PropertyType.BINARY, properties.getProperty("binary").getType());
            Binary binary = properties.getProperty("binary").getBinary();
            try {
                InputStream stream = binary.getStream();
                try {
                    for (int i = 0; i < BINARY.length; i++) {
                        assertEquals(BINARY[i], (byte) stream.read());
                    }
                    assertEquals(-1, stream.read());
                } finally {
                    stream.close();
                }
            } finally {
                binary.dispose();
            }
            assertEquals(PropertyType.DATE, properties.getProperty("date").getType());
            assertEquals(DATE.getTimeInMillis(), properties.getProperty("date").getDate().getTimeInMillis());
            assertEquals(PropertyType.DECIMAL, properties.getProperty("decimal").getType());
            assertEquals(new BigDecimal(123), properties.getProperty("decimal").getDecimal());
            assertEquals(PropertyType.DOUBLE, properties.getProperty("double").getType());
            assertEquals(Math.PI, properties.getProperty("double").getDouble());
            assertEquals(PropertyType.LONG, properties.getProperty("long").getType());
            assertEquals(9876543210L, properties.getProperty("long").getLong());
            assertEquals(PropertyType.REFERENCE, properties.getProperty("reference").getType());
            assertEquals(identifier, properties.getProperty("reference").getString());
            assertEquals("/referenceable", properties.getProperty("reference").getNode().getPath());
            assertEquals(PropertyType.STRING, properties.getProperty("string").getType());
            assertEquals("test", properties.getProperty("string").getString());
            assertEquals(PropertyType.STRING, properties.getProperty("multiple").getType());
            Value[] values = properties.getProperty("multiple").getValues();
            assertEquals(3, values.length);
            assertEquals("a", values[0].getString());
            assertEquals("b", values[1].getString());
            assertEquals("c", values[2].getString());
        } finally {
            session.logout();
        }
    } finally {
        repository.shutdown();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeType(javax.jcr.nodetype.NodeType) Node(javax.jcr.Node) Value(javax.jcr.Value) Binary(javax.jcr.Binary) BigDecimal(java.math.BigDecimal) Session(javax.jcr.Session)

Example 15 with NodeTypeManager

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

the class NodeTypeTest method updateNodeType.

@Test
public void updateNodeType() throws Exception {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    ValueFactory vf = session.getValueFactory();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    Node n = root.addNode("q1", "nt:query");
    n.setProperty("jcr:statement", vf.createValue("statement"));
    session.save();
    NodeTypeDefinition ntd = manager.getNodeType("nt:query");
    NodeTypeTemplate ntt = manager.createNodeTypeTemplate(ntd);
    try {
        manager.registerNodeType(ntt, true);
    // no changes to the type, so the registration should be a no-op
    } catch (ConstraintViolationException unexpected) {
        fail();
    }
    // make the (still missing) jcr:language property mandatory
    @SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> pdts = ntt.getPropertyDefinitionTemplates();
    for (PropertyDefinitionTemplate pdt : pdts) {
        if ("jcr:language".equals(pdt.getName())) {
            pdt.setMandatory(true);
        }
    }
    try {
        manager.registerNodeType(ntt, true);
        fail();
    } catch (ConstraintViolationException expected) {
    // the registration fails because of the would-be invalid content
    }
    // add the jcr:language property so it can be made mandatory
    n.setProperty("jcr:language", vf.createValue("language"));
    session.save();
    try {
        manager.registerNodeType(ntt, true);
    // now the mandatory property exists, so the type change is OK
    } catch (ConstraintViolationException unexpected) {
        fail();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) Node(javax.jcr.Node) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)103 NodeType (javax.jcr.nodetype.NodeType)47 Node (javax.jcr.Node)38 Session (javax.jcr.Session)35 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)31 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 ArrayList (java.util.ArrayList)10 Workspace (javax.jcr.Workspace)10 InputStream (java.io.InputStream)9 NodeDefinition (javax.jcr.nodetype.NodeDefinition)9 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)9 InputStreamReader (java.io.InputStreamReader)8 NamespaceRegistry (javax.jcr.NamespaceRegistry)8 Value (javax.jcr.Value)8