use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method createSourceContent.
@Override
@SuppressWarnings("unchecked")
protected void createSourceContent(Session session) throws Exception {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace("test", "http://www.example.org/");
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:unstructured");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" });
PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef1.setName("defaultString");
pDef1.setRequiredType(PropertyType.STRING);
Value stringValue = session.getValueFactory().createValue("stringValue");
pDef1.setDefaultValues(new Value[] { stringValue });
template.getPropertyDefinitionTemplates().add(pDef1);
PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef2.setName("defaultPath");
pDef2.setRequiredType(PropertyType.PATH);
Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH);
pDef2.setDefaultValues(new Value[] { pathValue });
template.getPropertyDefinitionTemplates().add(pDef2);
nodeTypeManager.registerNodeType(template, false);
template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:referenceable");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" });
nodeTypeManager.registerNodeType(template, false);
Node root = session.getRootNode();
Node referenceable = root.addNode("referenceable", "test:unstructured");
referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
versionable.addMixin(MIX_VERSIONABLE);
Node child = versionable.addNode("child", "test:referenceable");
child.addNode("child2", NT_UNSTRUCTURED);
session.save();
Node sns = root.addNode("sns");
sns.addNode("sibling");
sns.addNode("sibling");
sns.addNode("sibling");
session.getWorkspace().getVersionManager().checkin("/versionable");
Node properties = root.addNode("properties", "test:unstructured");
properties.setProperty("boolean", true);
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY));
try {
properties.setProperty("binary", binary);
} finally {
binary.dispose();
}
properties.setProperty("date", DATE);
properties.setProperty("decimal", new BigDecimal(123));
properties.setProperty("double", Math.PI);
properties.setProperty("long", 9876543210L);
properties.setProperty("reference", referenceable);
properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true));
properties.setProperty("mv_reference", new Value[] { session.getValueFactory().createValue(versionable, false) });
properties.setProperty("mv_weak_reference", new Value[] { session.getValueFactory().createValue(versionable, true) });
properties.setProperty("string", "test");
properties.setProperty("multiple", "a,b,c".split(","));
session.save();
binary = properties.getProperty("binary").getBinary();
try {
InputStream stream = binary.getStream();
try {
for (byte aBINARY : BINARY) {
assertEquals(aBINARY, (byte) stream.read());
}
assertEquals(-1, stream.read());
} finally {
stream.close();
}
} finally {
binary.dispose();
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class NodeTypeDefinitionManagementTest method testRegisterNodeType.
@Test
public void testRegisterNodeType() throws Exception {
Workspace testWsp = testSession.getWorkspace();
NodeTypeManager ntm = testWsp.getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testRegisterNodeType");
ntd.setMixin(true);
try {
ntm.registerNodeType(ntd, true);
fail("Node type registration should be denied.");
} catch (AccessDeniedException e) {
// success
}
try {
ntm.registerNodeType(ntd, false);
fail("Node type registration should be denied.");
} catch (AccessDeniedException e) {
// success
}
NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
ntds[0] = ntd;
ntds[1] = ntm.createNodeTypeTemplate();
ntds[1].setName("anotherRegisterNodeType");
ntds[1].setDeclaredSuperTypeNames(new String[] { "nt:file" });
try {
ntm.registerNodeTypes(ntds, true);
fail("Node type registration should be denied.");
} catch (AccessDeniedException e) {
// success
}
try {
ntm.registerNodeTypes(ntds, false);
fail("Node type registration should be denied.");
} catch (AccessDeniedException e) {
// success
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class NodeTypeDefinitionManagementTest method testRegisterNodeTypeWithPrivilege.
@Test
public void testRegisterNodeTypeWithPrivilege() throws Exception {
modify(null, JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), true);
try {
Workspace testWsp = testSession.getWorkspace();
NodeTypeManager ntm = testWsp.getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testRegisterNodeTypeWithPrivilege");
ntd.setMixin(true);
ntm.registerNodeType(ntd, true);
NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
ntds[0] = ntd;
ntds[1] = ntm.createNodeTypeTemplate();
ntds[1].setName("anotherRegisterNodeTypeWithPrivilege");
ntds[1].setDeclaredSuperTypeNames(new String[] { "nt:file" });
ntm.registerNodeTypes(ntds, true);
} finally {
modify(null, JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), false);
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class NodeTypeDefinitionManagementTest method testUnRegisterNodeType.
@Test
public void testUnRegisterNodeType() throws Exception {
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testUnregisterNodeType");
ntd.setMixin(true);
ntm.registerNodeType(ntd, true);
Workspace testWsp = testSession.getWorkspace();
try {
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeType(ntd.getName());
fail("Node type unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeTypes(new String[] { ntd.getName() });
fail("Node type unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
} finally {
// NOTE: diff to jr-core where unregisterNt was not supported
ntm.unregisterNodeType(ntd.getName());
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit-oak by apache.
the class OpvIgnoreTest method createNodeTypeWithIgnoreOPVProperty.
private NodeTypeTemplate createNodeTypeWithIgnoreOPVProperty(String propertyName) throws RepositoryException {
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate nt = manager.createNodeTypeTemplate();
nt.setName("testType");
nt.setMixin(true);
PropertyDefinitionTemplate opt = manager.createPropertyDefinitionTemplate();
opt.setMandatory(false);
opt.setName(propertyName);
opt.setRequiredType(PropertyType.STRING);
opt.setOnParentVersion(OnParentVersionAction.IGNORE);
List pdt = nt.getPropertyDefinitionTemplates();
pdt.add(opt);
manager.registerNodeType(nt, true);
return nt;
}
Aggregations