Search in sources :

Example 31 with NodeTypeTemplate

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

the class CompatibilityIssuesTest method addNodeTest.

@Test
public void addNodeTest() throws RepositoryException {
    Session session = getAdminSession();
    // node type with default child-node type of to nt:base
    String ntName = "test";
    NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    ntt.setName(ntName);
    NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
    child.setName("*");
    child.setDefaultPrimaryTypeName("nt:base");
    child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
    List<NodeDefinition> children = ntt.getNodeDefinitionTemplates();
    children.add(child);
    ntm.registerNodeType(ntt, true);
    // try to create a node with the default nt:base
    Node node = session.getRootNode().addNode("defaultNtBase", ntName);
    // See OAK-1013
    node.addNode("nothrow");
    try {
        node.addNode("throw", "nt:hierarchyNode");
        fail("Abstract primary type should cause ConstraintViolationException");
    } catch (ConstraintViolationException expected) {
    }
    session.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 32 with NodeTypeTemplate

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

the class RepositoryTest method mixin.

@Test
public void mixin() throws RepositoryException {
    NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
    NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
    mixTest.setName("mix:test");
    mixTest.setMixin(true);
    ntMgr.registerNodeType(mixTest, false);
    Node testNode = getNode(TEST_PATH);
    NodeType[] mix = testNode.getMixinNodeTypes();
    assertEquals(0, mix.length);
    testNode.addMixin("mix:test");
    testNode.getSession().save();
    Session session2 = createAnonymousSession();
    try {
        mix = session2.getNode(TEST_PATH).getMixinNodeTypes();
        assertEquals(1, mix.length);
        assertEquals("mix:test", mix[0].getName());
    } finally {
        session2.logout();
    }
    testNode.removeMixin("mix:test");
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Session(javax.jcr.Session) Test(org.junit.Test)

Example 33 with NodeTypeTemplate

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

the class NodeTypeTest method trivialUpdates.

@Test
public void trivialUpdates() throws Exception {
    // test various trivial updates that should not trigger repository scans
    // whether or not the repository scan happens can not be checked directly;
    // it requires inspecting the INFO level log 
    String[] types = new String[] { "trivial1", "trivial2" };
    ArrayList<NodeTypeTemplate> ntt = new ArrayList<NodeTypeTemplate>();
    // adding node types
    Session session = getAdminSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    for (String t : types) {
        NodeTypeTemplate nt = manager.createNodeTypeTemplate();
        nt.setName(t);
        ntt.add(nt);
    }
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), false);
    // adding an optional property
    ntt = new ArrayList<NodeTypeTemplate>();
    for (String t : types) {
        NodeTypeDefinition ntd = manager.getNodeType(t);
        PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
        opt.setMandatory(false);
        opt.setName("optional");
        opt.setRequiredType(PropertyType.STRING);
        PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
        opts.setMandatory(false);
        opts.setMultiple(true);
        opts.setName("optionals");
        opts.setRequiredType(PropertyType.STRING);
        NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
        List pdt = nt.getPropertyDefinitionTemplates();
        pdt.add(opt);
        pdt.add(opts);
        ntt.add(nt);
    }
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
    // make one optional property mandatory
    ntt = new ArrayList<NodeTypeTemplate>();
    for (String t : types) {
        NodeTypeDefinition ntd = manager.getNodeType(t);
        PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
        opt.setMandatory("trivial2".equals(t));
        opt.setName("optional");
        opt.setRequiredType(PropertyType.STRING);
        PropertyDefinitionTemplate opts = manager.createPropertyDefinitionTemplate();
        opts.setMandatory("trivial2".equals(t));
        opts.setMultiple(true);
        opts.setName("optionals");
        opts.setRequiredType(PropertyType.STRING);
        NodeTypeTemplate nt = manager.createNodeTypeTemplate(ntd);
        List pdt = nt.getPropertyDefinitionTemplates();
        pdt.add(opt);
        pdt.add(opts);
        ntt.add(nt);
    }
    // but update both node types
    manager.registerNodeTypes(ntt.toArray(new NodeTypeTemplate[0]), true);
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ArrayList(java.util.ArrayList) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 34 with NodeTypeTemplate

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

the class ObservationRefreshTest method setup.

@Before
public void setup() throws RepositoryException {
    Session session = getAdminSession();
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
    mixTest.setName(TEST_TYPE);
    mixTest.setMixin(true);
    ntMgr.registerNodeType(mixTest, false);
    Node n = session.getRootNode().addNode(TEST_NODE, TEST_NODE_TYPE);
    n.addMixin(TEST_TYPE);
    Node refNode = n.addNode(REFERENCEABLE_NODE);
    refNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
    session.save();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(RepositoryImpl.REFRESH_INTERVAL, 0);
    observingSession = ((JackrabbitRepository) getRepository()).login(new SimpleCredentials("admin", "admin".toCharArray()), null, attrs);
    observationManager = observingSession.getWorkspace().getObservationManager();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) HashMap(java.util.HashMap) Node(javax.jcr.Node) Session(javax.jcr.Session) Before(org.junit.Before)

Example 35 with NodeTypeTemplate

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

the class RepositoryTest method nodeTypeRegistry.

@Test
public void nodeTypeRegistry() throws RepositoryException {
    NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
    assertFalse(ntMgr.hasNodeType("foo"));
    NodeTypeTemplate ntd = ntMgr.createNodeTypeTemplate();
    ntd.setName("foo");
    ntMgr.registerNodeType(ntd, false);
    assertTrue(ntMgr.hasNodeType("foo"));
    ntMgr.unregisterNodeType("foo");
    assertFalse(ntMgr.hasNodeType("foo"));
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Test(org.junit.Test)

Aggregations

NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)46 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)29 Node (javax.jcr.Node)17 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)13 Test (org.junit.Test)12 Session (javax.jcr.Session)11 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)11 List (java.util.List)7 Workspace (javax.jcr.Workspace)7 NamespaceRegistry (javax.jcr.NamespaceRegistry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)5 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 AccessDeniedException (javax.jcr.AccessDeniedException)4 RepositoryException (javax.jcr.RepositoryException)4 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)4 BigDecimal (java.math.BigDecimal)3