Search in sources :

Example 76 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager 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 77 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager 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)

Example 78 with NodeTypeManager

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

the class RepositoryTest method importNodeType.

// Regression test for OAK-299
@Test
public void importNodeType() throws RepositoryException, IOException, ParseException {
    Session session = getAdminSession();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    if (!manager.hasNodeType("myNodeType")) {
        StringBuilder defs = new StringBuilder();
        defs.append("[\"myNodeType\"]\n");
        defs.append("  - prop1\n");
        defs.append("  + * (nt:base) = nt:unstructured \n");
        Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
        CndImporter.registerNodeTypes(cndReader, session);
    }
    NodeType myNodeType = manager.getNodeType("myNodeType");
    assertTrue(myNodeType.isNodeType("nt:base"));
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeType(javax.jcr.nodetype.NodeType) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Session(javax.jcr.Session) Test(org.junit.Test)

Example 79 with NodeTypeManager

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

the class NodeTypeTest method removeMandatoryProperty.

@Test
public void removeMandatoryProperty() throws Exception {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string) mandatory";
    CndImporter.registerNodeTypes(new StringReader(cnd), session);
    Node n = root.addNode("test", "test:MyType");
    n.setProperty("test:mandatory", "value");
    session.save();
    try {
        n.getProperty("test:mandatory").remove();
        session.save();
        fail("Must fail with ConstraintViolationException");
    } catch (ConstraintViolationException e) {
        // expected
        session.refresh(false);
    }
    // remove the mandatory property
    cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured";
    CndImporter.registerNodeTypes(new StringReader(cnd), session, true);
    // check node type
    NodeTypeDefinition ntd = manager.getNodeType("test:MyType");
    assertEquals(0, ntd.getDeclaredPropertyDefinitions().length);
    // now we should be able to remove the property
    n.getProperty("test:mandatory").remove();
    session.save();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) StringReader(java.io.StringReader) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 80 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager 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)

Aggregations

NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)93 NodeType (javax.jcr.nodetype.NodeType)41 Node (javax.jcr.Node)32 Session (javax.jcr.Session)30 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)29 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)27 Test (org.junit.Test)24 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)14 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)14 RepositoryException (javax.jcr.RepositoryException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 ArrayList (java.util.ArrayList)8 Workspace (javax.jcr.Workspace)8 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)8 NodeDefinition (javax.jcr.nodetype.NodeDefinition)8 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)8 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)7 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)7 InputStream (java.io.InputStream)6