use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class AuthorizablePropertiesImpl method checkProtectedProperty.
private void checkProtectedProperty(@Nonnull Tree parent, @Nonnull PropertyState property) throws RepositoryException {
ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager();
PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false);
if (def.isProtected()) {
throw new ConstraintViolationException("Attempt to set an protected property " + property.getName());
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class UpgradeOldSegmentTest method upgradeFrom10.
@Test
public void upgradeFrom10() throws Exception {
File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName());
FileUtils.deleteDirectory(testFolder);
File oldRepo = new File(testFolder, "test-repo-1.0");
oldRepo.mkdirs();
try (InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip")) {
Util.unzip(in, oldRepo);
}
SegmentTarNodeStoreContainer newRepoContainer = new SegmentTarNodeStoreContainer();
OakUpgrade.main("segment-old:" + oldRepo.getPath(), newRepoContainer.getDescription());
Repository repo = new Jcr(newRepoContainer.open()).createRepository();
Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
assertTrue(ntMgr.hasNodeType("test:MyType"));
NodeType nt = ntMgr.getNodeType("test:MyType");
PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertTrue(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
// flip mandatory flag for test:mandatory
String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)\n" + " - test:optional (string)";
CndImporter.registerNodeTypes(new StringReader(cnd), s, true);
myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
nt = ntMgr.getNodeType("test:MyType");
pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertFalse(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
s.logout();
if (repo instanceof JackrabbitRepository) {
((JackrabbitRepository) repo).shutdown();
}
newRepoContainer.close();
newRepoContainer.clean();
deleteRecursive(testFolder);
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method verifyCustomNodeTypes.
@Test
public void verifyCustomNodeTypes() throws Exception {
Session session = createAdminSession();
try {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
assertTrue(manager.hasNodeType("test:unstructured"));
NodeType type = manager.getNodeType("test:unstructured");
assertFalse(type.isMixin());
assertTrue(type.isNodeType("nt:unstructured"));
boolean foundDefaultString = false;
boolean foundDefaultPath = false;
for (PropertyDefinition pDef : type.getPropertyDefinitions()) {
if ("defaultString".equals(pDef.getName())) {
assertEquals(PropertyType.STRING, pDef.getRequiredType());
assertNotNull(pDef.getDefaultValues());
assertEquals(1, pDef.getDefaultValues().length);
assertEquals("stringValue", pDef.getDefaultValues()[0].getString());
foundDefaultString = true;
} else if ("defaultPath".equals(pDef.getName())) {
assertEquals(PropertyType.PATH, pDef.getRequiredType());
assertNotNull(pDef.getDefaultValues());
assertEquals(1, pDef.getDefaultValues().length);
assertEquals("/jcr:path/nt:value", pDef.getDefaultValues()[0].getString());
foundDefaultPath = true;
}
}
assertTrue("Expected property definition with name \"defaultString\"", foundDefaultString);
assertTrue("Expected property definition with name \"defaultPath\"", foundDefaultPath);
} finally {
session.logout();
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class PropertyTest method testMixTitleOnUnstructured.
public void testMixTitleOnUnstructured() throws Exception {
Node n = testRootNode.addNode("unstructured", JcrConstants.NT_UNSTRUCTURED);
n.addMixin("mix:title");
superuser.save();
// create jcr:title property with type LONG => declaring NT is nt:unstructured
Property title = n.setProperty("jcr:title", 12345);
assertEquals(PropertyType.LONG, title.getType());
PropertyDefinition def = title.getDefinition();
assertEquals(JcrConstants.NT_UNSTRUCTURED, def.getDeclaringNodeType().getName());
assertEquals(PropertyType.UNDEFINED, def.getRequiredType());
// changing value to STRING => ValueFormatException expected
try {
title.setValue("str");
fail();
} catch (ValueFormatException e) {
// success
}
// re-setting property to STRING -> change definition => declaring NT is mix:title
n.setProperty("jcr:title", "str");
assertEquals(PropertyType.STRING, title.getType());
assertEquals(PropertyType.STRING, title.getValue().getType());
def = title.getDefinition();
assertEquals("mix:title", def.getDeclaringNodeType().getName());
assertEquals(PropertyType.STRING, def.getRequiredType());
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class PropertyTest method testRequiredTypeLongChangeBoolean.
public void testRequiredTypeLongChangeBoolean() throws Exception {
Property p = node.setProperty(LONG_PROP_NAME, 12345);
assertEquals(PropertyType.LONG, p.getType());
assertEquals(PropertyType.LONG, p.getValue().getType());
PropertyDefinition def = p.getDefinition();
assertEquals(PropertyType.LONG, def.getRequiredType());
assertEquals(NT_NAME, def.getDeclaringNodeType().getName());
superuser.save();
try {
p.setValue(true);
fail("Conversion from BOOLEAN to LONG must throw ValueFormatException");
} catch (ValueFormatException e) {
// success
}
try {
node.setProperty(LONG_PROP_NAME, true);
fail("Conversion from BOOLEAN to LONG must throw ValueFormatException");
} catch (ValueFormatException e) {
// success
}
}
Aggregations