Search in sources :

Example 16 with NodeTypeTemplate

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

the class OpvIgnoreTest method testWritePropertyWithIgnoreOPVAfterCheckIn.

//OAK-3328
public void testWritePropertyWithIgnoreOPVAfterCheckIn() throws RepositoryException {
    Node ignoreTestNode = testRootNode.addNode("ignoreTestNode", JcrConstants.NT_UNSTRUCTURED);
    String ignoredPropertyName = "ignoredProperty";
    NodeTypeTemplate mixinWithIgnoreProperty = createNodeTypeWithIgnoreOPVProperty(ignoredPropertyName);
    Node node = ignoreTestNode.addNode("testNode", testNodeType);
    node.addMixin(mixinWithIgnoreProperty.getName());
    node.setProperty(ignoredPropertyName, "initial value");
    node.addMixin(mixVersionable);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    if (!node.isCheckedOut()) {
        vMgr.checkout(node.getPath());
    }
    vMgr.checkin(node.getPath());
    node.setProperty(ignoredPropertyName, "next value");
    superuser.save();
    Property ignoreProperty = node.getProperty(ignoredPropertyName);
    assertEquals("next value", ignoreProperty.getString());
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) Property(javax.jcr.Property)

Example 17 with NodeTypeTemplate

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

the class OpvIgnoreTest method testRemovePropertyWithIgnoreOPVAfterCheckIn.

//OAK-3328
public void testRemovePropertyWithIgnoreOPVAfterCheckIn() throws RepositoryException {
    Node ignoreTestNode = testRootNode.addNode("ignoreTestNode", JcrConstants.NT_UNSTRUCTURED);
    String ignoredPropertyName = "test:ignoredProperty";
    NodeTypeTemplate mixinWithIgnoreProperty = createNodeTypeWithIgnoreOPVProperty(ignoredPropertyName);
    Node node = ignoreTestNode.addNode("testNode", testNodeType);
    node.addMixin(mixinWithIgnoreProperty.getName());
    node.setProperty(ignoredPropertyName, "initial value");
    node.addMixin(mixVersionable);
    superuser.save();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    if (!node.isCheckedOut()) {
        vMgr.checkout(node.getPath());
    }
    vMgr.checkin(node.getPath());
    node.getProperty(ignoredPropertyName).remove();
    superuser.save();
    assertFalse(node.hasProperty(ignoredPropertyName));
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 18 with NodeTypeTemplate

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

the class OpvAbortTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    vMgr = superuser.getWorkspace().getVersionManager();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeDefinitionTemplate def = ntMgr.createNodeDefinitionTemplate();
    def.setOnParentVersion(OnParentVersionAction.ABORT);
    def.setName("child");
    def.setRequiredPrimaryTypeNames(new String[] { NT_BASE });
    NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
    tmpl.setName("OpvAbortTest");
    tmpl.setMixin(true);
    tmpl.getNodeDefinitionTemplates().add(def);
    ntMgr.registerNodeType(tmpl, true);
    testRootNode.addMixin(MIX_VERSIONABLE);
    superuser.save();
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate)

Example 19 with NodeTypeTemplate

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

the class PropertyTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate template = ntMgr.createNodeTypeTemplate();
    template.setName(NT_NAME);
    template.setDeclaredSuperTypeNames(new String[] { JcrConstants.NT_BASE });
    template.setMixin(false);
    PropertyDefinitionTemplate pdt = ntMgr.createPropertyDefinitionTemplate();
    pdt.setName(BOOLEAN_PROP_NAME);
    pdt.setRequiredType(PropertyType.BOOLEAN);
    template.getPropertyDefinitionTemplates().add(pdt);
    pdt = ntMgr.createPropertyDefinitionTemplate();
    pdt.setName(LONG_PROP_NAME);
    pdt.setRequiredType(PropertyType.LONG);
    template.getPropertyDefinitionTemplates().add(pdt);
    ntMgr.registerNodeType(template, true);
    node = testRootNode.addNode(nodeName2, NT_NAME);
    assertEquals(NT_NAME, node.getPrimaryNodeType().getName());
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 20 with NodeTypeTemplate

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

the class NodeTypeTest method updateNodeType.

@Test
public void updateNodeType() throws Exception {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    ValueFactory vf = session.getValueFactory();
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    Node n = root.addNode("q1", "nt:query");
    n.setProperty("jcr:statement", vf.createValue("statement"));
    session.save();
    NodeTypeDefinition ntd = manager.getNodeType("nt:query");
    NodeTypeTemplate ntt = manager.createNodeTypeTemplate(ntd);
    try {
        manager.registerNodeType(ntt, true);
    // no changes to the type, so the registration should be a no-op
    } catch (ConstraintViolationException unexpected) {
        fail();
    }
    // make the (still missing) jcr:language property mandatory
    @SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> pdts = ntt.getPropertyDefinitionTemplates();
    for (PropertyDefinitionTemplate pdt : pdts) {
        if ("jcr:language".equals(pdt.getName())) {
            pdt.setMandatory(true);
        }
    }
    try {
        manager.registerNodeType(ntt, true);
        fail();
    } catch (ConstraintViolationException expected) {
    // the registration fails because of the would-be invalid content
    }
    // add the jcr:language property so it can be made mandatory
    n.setProperty("jcr:language", vf.createValue("language"));
    session.save();
    try {
        manager.registerNodeType(ntt, true);
    // now the mandatory property exists, so the type change is OK
    } catch (ConstraintViolationException unexpected) {
        fail();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) Node(javax.jcr.Node) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ValueFactory(javax.jcr.ValueFactory) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

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