Search in sources :

Example 11 with NodeTypeDefinition

use of javax.jcr.nodetype.NodeTypeDefinition 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 12 with NodeTypeDefinition

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

the class NodeTypeCreationTest method testNonEmptyNodeTypeTemplate.

public void testNonEmptyNodeTypeTemplate() throws Exception {
    NodeTypeDefinition ntd = ntm.getNodeType("nt:address");
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(ntm.getNodeType("nt:address"));
    assertEquals(ntt.getName(), ntd.getName());
    assertEquals(ntt.isMixin(), ntd.isMixin());
    assertEquals(ntt.isAbstract(), ntd.isAbstract());
    assertEquals(ntt.hasOrderableChildNodes(), ntd.hasOrderableChildNodes());
    assertEquals(ntt.isQueryable(), ntd.isQueryable());
    assertEquals(ntt.getPrimaryItemName(), ntd.getPrimaryItemName());
    assertTrue(Arrays.equals(ntt.getDeclaredSupertypeNames(), ntd.getDeclaredSupertypeNames()));
    NodeDefinition[] nda = ntt.getDeclaredChildNodeDefinitions();
    NodeDefinition[] nda1 = ntd.getDeclaredChildNodeDefinitions();
    assertEquals(nda.length, nda1.length);
    for (int i = 0; i < nda.length; i++) {
        assertEquals(nda[i].getName(), nda1[i].getName());
        assertEquals(nda[i].allowsSameNameSiblings(), nda1[i].allowsSameNameSiblings());
        assertTrue(Arrays.equals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames()));
        assertEquals(nda[i].getDefaultPrimaryTypeName(), nda1[i].getDefaultPrimaryTypeName());
        assertEquals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames());
    }
    PropertyDefinition[] pda = ntt.getDeclaredPropertyDefinitions();
    PropertyDefinition[] pda1 = ntd.getDeclaredPropertyDefinitions();
    assertEquals(pda.length, pda1.length);
    for (int i = 0; i < pda.length; i++) {
        assertEquals(pda[i].getName(), pda1[i].getName());
        assertEquals(pda[i].getRequiredType(), pda1[i].getRequiredType());
        assertTrue(Arrays.equals(pda[i].getAvailableQueryOperators(), pda1[i].getAvailableQueryOperators()));
        assertTrue(Arrays.equals(pda[i].getValueConstraints(), pda1[i].getValueConstraints()));
        assertEquals(pda[i].isFullTextSearchable(), pda1[i].isFullTextSearchable());
        assertEquals(pda[i].isMultiple(), pda1[i].isMultiple());
        assertEquals(pda[i].isQueryOrderable(), pda1[i].isQueryOrderable());
    }
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) NodeDefinition(javax.jcr.nodetype.NodeDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 13 with NodeTypeDefinition

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

the class NodeTypeCreationTest method testRegisterNodeTypes.

public void testRegisterNodeTypes() throws Exception {
    NodeTypeDefinition[] defs = new NodeTypeDefinition[5];
    for (int i = 0; i < defs.length; i++) {
        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
        ntt.setName("mix:foo" + i);
        ntt.setAbstract(false);
        ntt.setMixin(true);
        ntt.setOrderableChildNodes(false);
        ntt.setQueryable(false);
        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
        pdt.setAutoCreated(false);
        pdt.setName("foo" + i);
        pdt.setMultiple(false);
        pdt.setRequiredType(PropertyType.STRING);
        List pdefs = ntt.getPropertyDefinitionTemplates();
        pdefs.add(pdt);
        defs[i] = ntt;
    }
    ntm.registerNodeTypes(defs, true);
    try {
        ntm.registerNodeTypes(defs, false);
        fail("NodeTypeExistsException expected.");
    } catch (NodeTypeExistsException e) {
    // success
    }
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) List(java.util.List)

Example 14 with NodeTypeDefinition

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

the class CompactNodeTypeDefWriter method write.

/**
     * Write one QNodeTypeDefinition to this writer
     *
     * @param ntd node type definition
     * @throws IOException if an I/O error occurs
     */
public void write(QNodeTypeDefinition ntd) throws IOException {
    NodeTypeDefinition def = new NodeTypeDefinitionImpl(ntd, npResolver, new ValueFactoryQImpl(QValueFactoryImpl.getInstance(), npResolver));
    super.write(def);
}
Also used : NodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl)

Example 15 with NodeTypeDefinition

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

the class RepositoryServiceImpl method registerNodeTypes.

/**
     * {@inheritDoc}
     */
public void registerNodeTypes(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    NodeTypeDefinition[] defs = new NodeTypeDefinition[nodeTypeDefinitions.length];
    for (int i = 0; i < nodeTypeDefinitions.length; i++) {
        defs[i] = new NodeTypeDefinitionImpl(nodeTypeDefinitions[i], sInfo.getNamePathResolver(), sInfo.getSession().getValueFactory()) {
        };
    }
    ntMgr.registerNodeTypes(defs, allowUpdate);
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition)

Aggregations

NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)15 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)6 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)5 ArrayList (java.util.ArrayList)4 Session (javax.jcr.Session)4 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)4 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)4 Test (org.junit.Test)4 Node (javax.jcr.Node)3 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3 NodeType (javax.jcr.nodetype.NodeType)3 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)3 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)3 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)3 StringReader (java.io.StringReader)2 List (java.util.List)2 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)2 NodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl)2 ValueFactory (javax.jcr.ValueFactory)1 InvalidNodeTypeDefinitionException (javax.jcr.nodetype.InvalidNodeTypeDefinitionException)1