Search in sources :

Example 36 with NodeTypeTemplate

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

the class ObservationTest 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);
    n.setProperty("test_property1", 42);
    n.setProperty("test_property2", "forty_two");
    n.addMixin(TEST_TYPE);
    Node refNode = n.addNode(REFERENCEABLE_NODE);
    refNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
    test_uuid = refNode.getProperty(JcrConstants.JCR_UUID).getString();
    session.save();
    observingSession = createAdminSession();
    observationManager = observingSession.getWorkspace().getObservationManager();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Session(javax.jcr.Session) Before(org.junit.Before)

Example 37 with NodeTypeTemplate

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

the class ObservationTest method deepNodeTypeMixinHierarchy.

@Test
public void deepNodeTypeMixinHierarchy() throws Exception {
    NodeTypeManager ntm = getAdminSession().getWorkspace().getNodeTypeManager();
    NodeTypeTemplate parentMixin = ntm.createNodeTypeTemplate();
    parentMixin.setName("parentmixin");
    parentMixin.setMixin(true);
    ntm.registerNodeType(parentMixin, false);
    NodeTypeTemplate childMixin = ntm.createNodeTypeTemplate();
    childMixin.setName("childmixin");
    childMixin.setMixin(true);
    childMixin.setDeclaredSuperTypeNames(new String[] { "parentmixin" });
    ntm.registerNodeType(childMixin, false);
    NodeTypeTemplate mytype = ntm.createNodeTypeTemplate();
    mytype.setName("mytype");
    mytype.setMixin(false);
    mytype.setDeclaredSuperTypeNames(new String[] { "childmixin" });
    NodeDefinitionTemplate child = ntm.createNodeDefinitionTemplate();
    child.setName("*");
    child.setDefaultPrimaryTypeName("nt:base");
    child.setRequiredPrimaryTypeNames(new String[] { "nt:base" });
    List<NodeDefinition> children = mytype.getNodeDefinitionTemplates();
    children.add(child);
    ntm.registerNodeType(mytype, false);
    getAdminSession().save();
    // create a fresh session here to catch the above new node type definitions
    observingSession = createAdminSession();
    observationManager = observingSession.getWorkspace().getObservationManager();
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath("/").setIsDeep(true).setNodeTypes(new String[] { "parentmixin" }).setEventTypes(ALL_EVENTS);
    oManager.addEventListener(listener, filter);
    Node n = getNode(TEST_PATH).addNode("n", "mytype");
    listener.expect(n.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node m = n.addNode("m", "nt:unstructured");
    listener.expect(m.getPath(), NODE_ADDED);
    getAdminSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Event(javax.jcr.observation.Event) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 38 with NodeTypeTemplate

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

the class OpvIgnoreTest method createNodeDefinitionWithIgnoreOPVNode.

private NodeDefinitionTemplate createNodeDefinitionWithIgnoreOPVNode(String nodeTypeName) throws RepositoryException {
    NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
    NodeDefinitionTemplate def = manager.createNodeDefinitionTemplate();
    def.setOnParentVersion(OnParentVersionAction.IGNORE);
    def.setName("child");
    def.setRequiredPrimaryTypeNames(new String[] { JcrConstants.NT_BASE });
    NodeTypeTemplate tmpl = manager.createNodeTypeTemplate();
    tmpl.setName(nodeTypeName);
    tmpl.setMixin(true);
    tmpl.getNodeDefinitionTemplates().add(def);
    manager.registerNodeType(tmpl, true);
    return def;
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate)

Example 39 with NodeTypeTemplate

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

the class IndexingConfigurationImplTest method testAddNodeTypeToRegistry.

public void testAddNodeTypeToRegistry() throws Exception {
    IndexingConfiguration config = createConfig("config4");
    // add node type
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    String baseName = "indexingTextNodeType";
    int i = 0;
    String nt;
    do {
        nt = baseName + "_" + i++;
    } while (ntMgr.hasNodeType(nt));
    // register node type
    NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
    ntTemplate.setName(nt);
    ntTemplate.setDeclaredSuperTypeNames(new String[] { ntUnstructured });
    ntMgr.registerNodeType(ntTemplate, false);
    // create node
    Node n = testRootNode.addNode(nodeName2, nt);
    session.save();
    // get state
    NodeState state = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(new NodeId(n.getIdentifier()));
    assertTrue(config.isIndexed(state, FOO));
    assertFalse(config.isIncludedInNodeScopeIndex(state, FOO));
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeState(org.apache.jackrabbit.core.state.NodeState) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 40 with NodeTypeTemplate

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

the class NodeTypeCreationTest method testEmptyNodeTypeTemplate.

public void testEmptyNodeTypeTemplate() throws Exception {
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    assertNull(ntt.getName());
    assertFalse(ntt.isMixin());
    assertFalse(ntt.isAbstract());
    assertFalse(ntt.hasOrderableChildNodes());
    // note: isQueryable cannot be tested as defautl value is defined
    // by the implementation
    assertNotNull(ntt.getDeclaredSupertypeNames());
    assertEquals(0, ntt.getDeclaredSupertypeNames().length);
    assertNull(ntt.getPrimaryItemName());
    assertNull(ntt.getDeclaredChildNodeDefinitions());
    assertNull(ntt.getDeclaredPropertyDefinitions());
    assertNotNull(ntt.getNodeDefinitionTemplates());
    assertTrue(ntt.getNodeDefinitionTemplates().isEmpty());
    assertNotNull(ntt.getPropertyDefinitionTemplates());
    assertTrue(ntt.getPropertyDefinitionTemplates().isEmpty());
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate)

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