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();
}
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());
}
}
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
}
}
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);
}
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);
}
Aggregations