Search in sources :

Example 1 with NodeDefinitionTemplate

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

the class AddMixinTest method testAddItemsDefinedByMixin.

public void testAddItemsDefinedByMixin() throws NotExecutableException, RepositoryException {
    // register mixin
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testMixin");
    ntd.setMixin(true);
    NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
    nodeDef.setName("child");
    nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
    ntd.getNodeDefinitionTemplates().add(nodeDef);
    ntm.registerNodeType(ntd, true);
    // create node and add mixin
    Node node = testRootNode.addNode(nodeName1, "nt:resource");
    node.setProperty("jcr:data", "abc");
    node.addMixin("testMixin");
    superuser.save();
    // create a child node defined by the mixin
    node.addNode("child", "nt:folder");
    node.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node)

Example 2 with NodeDefinitionTemplate

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

the class AddMixinTest method testAddItemsDefinedByMixin3.

public void testAddItemsDefinedByMixin3() throws NotExecutableException, RepositoryException {
    // register mixin
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testMixin");
    ntd.setMixin(true);
    NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
    nodeDef.setName("child");
    nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
    nodeDef.setDefaultPrimaryTypeName("nt:folder");
    ntd.getNodeDefinitionTemplates().add(nodeDef);
    ntm.registerNodeType(ntd, true);
    // create node and add mixin
    Node node = testRootNode.addNode(nodeName1, "nt:resource");
    node.setProperty("jcr:data", "abc");
    node.addMixin("testMixin");
    superuser.save();
    // create a child node defined by the mixin without specifying the
    // node type -> must succeed since default primary type is specified
    // in the child node def
    Node c = node.addNode("child");
    assertEquals("nt:folder", c.getPrimaryNodeType().getName());
    superuser.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node)

Example 3 with NodeDefinitionTemplate

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

the class AddMixinTest method testAddItemsDefinedByMixin2.

public void testAddItemsDefinedByMixin2() throws NotExecutableException, RepositoryException {
    // register mixin
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
    ntd.setName("testMixin");
    ntd.setMixin(true);
    NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
    nodeDef.setName("child");
    nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
    ntd.getNodeDefinitionTemplates().add(nodeDef);
    ntm.registerNodeType(ntd, true);
    // create node and add mixin
    Node node = testRootNode.addNode(nodeName1, "nt:resource");
    node.setProperty("jcr:data", "abc");
    node.addMixin("testMixin");
    superuser.save();
    // node type
    try {
        node.addNode("child");
        fail();
    } catch (ConstraintViolationException e) {
    // success as ChildNode Definition doesn't specify a default primary
    // type -> see comment in ItemDefinitionProvider#getQNodeDefinition
    }
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 4 with NodeDefinitionTemplate

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

the class NodeTypeCreationTest method testInvalidJCRNames.

public void testInvalidJCRNames() throws Exception {
    String invalidName = ":ab[2]";
    // invalid name(s) passed to NT-template methods
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    try {
        ntt.setName(invalidName);
        fail("ConstraintViolationException expected. Nt-name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ntt.setDeclaredSuperTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
        fail("ConstraintViolationException expected. One of the super type names is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ntt.setPrimaryItemName(invalidName);
        fail("ConstraintViolationException expected. Primary item name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    // invalid name(s) passed to NodeDefinitionTemplate
    NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
    try {
        ndt.setName(invalidName);
        fail("ConstraintViolationException expected. Name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ndt.setRequiredPrimaryTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
        fail("ConstraintViolationException expected. One of the required primary type names is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ndt.setDefaultPrimaryTypeName(invalidName);
        fail("ConstraintViolationException expected. Default primary type name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    // invalid name(s) passed to PropertyDefinitionTemplate
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    try {
        pdt.setName(invalidName);
        fail("ConstraintViolationException expected. Name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 5 with NodeDefinitionTemplate

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

the class NodeTypeCreationTest method testEmptyNodeDefinitionTemplate.

public void testEmptyNodeDefinitionTemplate() throws Exception {
    NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
    assertNull(ndt.getName());
    assertFalse(ndt.isAutoCreated());
    assertFalse(ndt.isMandatory());
    assertFalse(ndt.isProtected());
    assertEquals(OnParentVersionAction.COPY, ndt.getOnParentVersion());
    assertNull(ndt.getDeclaringNodeType());
    assertNull(ndt.getRequiredPrimaryTypes());
    assertNull(ndt.getRequiredPrimaryTypeNames());
    assertNull(ndt.getDefaultPrimaryType());
    assertNull(ndt.getDefaultPrimaryTypeName());
    assertFalse(ndt.allowsSameNameSiblings());
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate)

Aggregations

NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)20 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)11 Node (javax.jcr.Node)8 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)7 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)4 VersionManager (javax.jcr.version.VersionManager)3 Test (org.junit.Test)3 NodeDefinition (javax.jcr.nodetype.NodeDefinition)2 Name (org.apache.jackrabbit.spi.Name)2 List (java.util.List)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)1 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)1 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)1 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)1 ReadWriteNodeTypeManager (org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1