use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class CopyNodeTypesUpgradeTest method customNodeTypesAreRegistered.
@Test
public void customNodeTypesAreRegistered() throws RepositoryException {
final JackrabbitSession adminSession = createAdminSession();
final NodeTypeManager nodeTypeManager = adminSession.getWorkspace().getNodeTypeManager();
final NodeType testFolderNodeType = nodeTypeManager.getNodeType("test:Folder");
final NodeDefinition[] cnd = testFolderNodeType.getChildNodeDefinitions();
final PropertyDefinition[] pd = testFolderNodeType.getPropertyDefinitions();
assertEquals("More than one child node definition", 1, cnd.length);
assertEquals("Incorrect default primary type", "test:Folder", cnd[0].getDefaultPrimaryTypeName());
assertEquals("More than two property definitions", 4, pd.length);
adminSession.logout();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AbstractVersionTest method setUp.
protected void setUp() throws Exception {
super.setUp();
super.checkSupportedOption(Repository.OPTION_VERSIONING_SUPPORTED);
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
// assert that this repository support versioning
try {
NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
if (versionableNt == null) {
fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
}
} catch (NoSuchNodeTypeException e) {
fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
}
// retrieve versionable nodetype
String versionableNodeTypeName = getProperty("versionableNodeType");
try {
versionableNodeType = ntMgr.getNodeType(versionableNodeTypeName);
if (versionableNodeType == null) {
fail("Property 'versionableNodeType' does not define a valid nodetype: '" + versionableNodeTypeName + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'versionableNodeType' does not define an existing nodetype: '" + versionableNodeTypeName + "'");
}
// make sure 'non-versionable' nodetype is properly defined
try {
nonVersionableNodeType = ntMgr.getNodeType(testNodeType);
if (nonVersionableNodeType == null || nonVersionableNodeType.isNodeType(mixVersionable)) {
fail("Property 'testNodeType' does define a versionable nodetype: '" + testNodeType + "'");
}
} catch (NoSuchNodeTypeException e) {
fail("Property 'testNodeType' does not define an existing nodetype: '" + testNodeType + "'");
}
// build persistent versionable and non-versionable nodes
try {
versionableNode = createVersionableNode(testRootNode, nodeName1, versionableNodeType);
} catch (RepositoryException e) {
fail("Failed to create versionable test node." + e.getMessage());
}
try {
nonVersionableNode = testRootNode.addNode(nodeName3, nonVersionableNodeType.getName());
testRootNode.getSession().save();
} catch (RepositoryException e) {
fail("Failed to create non-versionable test node." + e.getMessage());
}
propertyValue = getProperty("propertyValue");
if (propertyValue == null) {
fail("Property 'propertyValue' is not defined.");
}
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AbstractMergeTest method setUp.
/**
* Initialising used variables coming from the properties file.<br> Setup
* some nodes on the 2 workspaces.<br>
*/
protected void setUp() throws Exception {
super.setUp();
super.checkSupportedOption(Repository.OPTION_VERSIONING_SUPPORTED);
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
// versionable node type
versionableNodeType = getProperty(PROP_VERSIONABLE_NODE_TYPE);
if (versionableNodeType == null) {
fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' is not defined.");
}
NodeType vNt = ntm.getNodeType(versionableNodeType);
if (!vNt.isNodeType(mixVersionable)) {
fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' does not define a versionable nodetype.");
}
// non versionable node type
// test node type defines always a non versionable node type
nonVersionableNodeType = testNodeType;
if (nonVersionableNodeType == null) {
fail("Property '" + testNodeType + "' is not defined.");
}
NodeType nvNt = ntm.getNodeType(nonVersionableNodeType);
if (nvNt.isNodeType(mixVersionable)) {
fail("Property '" + testNodeType + "' does define a versionable nodetype.");
}
// initialise a new session on second workspace as superuser
superuserW2 = getHelper().getSuperuserSession(workspaceName);
workspace = superuser.getWorkspace();
workspaceW2 = superuserW2.getWorkspace();
// get/create test root node on second workspace
testRootNodeW2 = cleanUpTestRoot(superuserW2);
// initialize test nodes
initNodes();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
/**
* {@inheritDoc}
*/
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
for (Name nodetypeName : nodetypeNames) {
try {
String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
NodeType nt = ntMgr.getNodeType(ntName);
defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
// in addition pack all supertypes into the return value
NodeType[] supertypes = nt.getSupertypes();
for (NodeType supertype : supertypes) {
defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
}
return defs.iterator();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class RepositoryServiceImpl method unregisterNodeTypes.
/**
* {@inheritDoc}
*/
public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames) throws UnsupportedRepositoryOperationException, NoSuchNodeTypeException, RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
String[] names = new String[nodeTypeNames.length];
for (int i = 0; i < nodeTypeNames.length; i++) {
names[i] = sInfo.getNamePathResolver().getJCRName(nodeTypeNames[i]);
}
ntMgr.unregisterNodeTypes(names);
}
Aggregations