use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class SessionItemStateManager method visit.
// ---------------------------------------------------< OperationVisitor >---
/**
* @see OperationVisitor#visit(AddNode)
*/
public void visit(AddNode operation) throws LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, NoSuchNodeTypeException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
NodeState parent = operation.getParentState();
ItemDefinitionProvider defProvider = mgrProvider.getItemDefinitionProvider();
QNodeDefinition def = defProvider.getQNodeDefinition(parent.getAllNodeTypeNames(), operation.getNodeName(), operation.getNodeTypeName());
List<ItemState> newStates = addNodeState(parent, operation.getNodeName(), operation.getNodeTypeName(), operation.getUuid(), def, operation.getOptions());
operation.addedState(newStates);
if (!(operation instanceof IgnoreOperation)) {
transientStateMgr.addOperation(operation);
}
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit-oak by apache.
the class RepositoryUpgrade method createNodeTypeTemplate.
private NodeTypeTemplate createNodeTypeTemplate(ValueFactory valueFactory, NodeTypeManager ntMgr, String oakName, QNodeTypeDefinition def) throws RepositoryException {
NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
tmpl.setName(oakName);
tmpl.setAbstract(def.isAbstract());
tmpl.setMixin(def.isMixin());
tmpl.setOrderableChildNodes(def.hasOrderableChildNodes());
tmpl.setQueryable(def.isQueryable());
Name primaryItemName = def.getPrimaryItemName();
if (primaryItemName != null) {
tmpl.setPrimaryItemName(getOakName(primaryItemName));
}
Name[] supertypes = def.getSupertypes();
if (supertypes != null && supertypes.length > 0) {
List<String> names = newArrayListWithCapacity(supertypes.length);
for (Name supertype : supertypes) {
names.add(getOakName(supertype));
}
tmpl.setDeclaredSuperTypeNames(names.toArray(new String[names.size()]));
}
List<PropertyDefinitionTemplate> propertyDefinitionTemplates = tmpl.getPropertyDefinitionTemplates();
for (QPropertyDefinition qpd : def.getPropertyDefs()) {
PropertyDefinitionTemplate pdt = createPropertyDefinitionTemplate(valueFactory, ntMgr, qpd);
propertyDefinitionTemplates.add(pdt);
}
// + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition protected sns
List<NodeDefinitionTemplate> nodeDefinitionTemplates = tmpl.getNodeDefinitionTemplates();
for (QNodeDefinition qnd : def.getChildNodeDefs()) {
NodeDefinitionTemplate ndt = createNodeDefinitionTemplate(ntMgr, qnd);
nodeDefinitionTemplates.add(ndt);
}
return tmpl;
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class BatchedItemOperations method checkAddNode.
// --------------------------------------< misc. high-level helper methods >
/**
* Checks if adding a child node called <code>nodeName</code> of node type
* <code>nodeTypeName</code> to the given parent node is allowed in the
* current context.
*
* @param parentState
* @param nodeName
* @param nodeTypeName
* @param options bit-wise OR'ed flags specifying the checks that should be
* performed; any combination of the following constants:
* <ul>
* <li><code>{@link #CHECK_ACCESS}</code>: make sure
* current session is granted read & write access on
* parent node</li>
* <li><code>{@link #CHECK_LOCK}</code>: make sure
* there's no foreign lock on parent node</li>
* <li><code>{@link #CHECK_CHECKED_OUT}</code>: make sure
* parent node is checked-out</li>
* <li><code>{@link #CHECK_CONSTRAINTS}</code>:
* make sure no node type constraints would be violated</li>
* <li><code>{@link #CHECK_HOLD}</code>: check for effective holds preventing the add operation</li>
* <li><code>{@link #CHECK_RETENTION}</code>: check for effective retention policy preventing the add operation</li>
* </ul>
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws LockException
* @throws ItemNotFoundException
* @throws ItemExistsException
* @throws RepositoryException
*/
public void checkAddNode(NodeState parentState, Name nodeName, Name nodeTypeName, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ItemExistsException, RepositoryException {
Path parentPath = hierMgr.getPath(parentState.getNodeId());
if ((options & CHECK_LOCK) == CHECK_LOCK) {
// make sure there's no foreign lock on parent node
verifyUnlocked(parentPath);
}
if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
// make sure parent node is checked-out
verifyCheckedOut(parentPath);
}
if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
AccessManager accessMgr = context.getAccessManager();
// make sure current session is granted read access on parent node
if (!accessMgr.isGranted(parentPath, Permission.READ)) {
throw new ItemNotFoundException(safeGetJCRPath(parentState.getNodeId()));
}
// make sure current session is granted write access on parent node
if (!accessMgr.isGranted(parentPath, nodeName, Permission.ADD_NODE)) {
throw new AccessDeniedException(safeGetJCRPath(parentState.getNodeId()) + ": not allowed to add child node");
}
// specified node type (and ev. mixins)
if (!accessMgr.isGranted(parentPath, nodeName, Permission.NODE_TYPE_MNGMT)) {
throw new AccessDeniedException(safeGetJCRPath(parentState.getNodeId()) + ": not allowed to add child node");
}
}
if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
QItemDefinition parentDef = context.getItemManager().getDefinition(parentState).unwrap();
// make sure parent node is not protected
if (parentDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(parentState.getNodeId()) + ": cannot add child node to protected parent node");
}
// make sure there's an applicable definition for new child node
EffectiveNodeType entParent = getEffectiveNodeType(parentState);
entParent.checkAddNodeConstraints(nodeName, nodeTypeName, context.getNodeTypeRegistry());
QNodeDefinition newNodeDef = findApplicableNodeDefinition(nodeName, nodeTypeName, parentState);
// check for name collisions
if (parentState.hasChildNodeEntry(nodeName)) {
// there's already a node with that name...
// get definition of existing conflicting node
ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
NodeState conflictingState;
NodeId conflictingId = entry.getId();
try {
conflictingState = (NodeState) stateMgr.getItemState(conflictingId);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(conflictingId);
log.debug(msg);
throw new RepositoryException(msg, ise);
}
QNodeDefinition conflictingTargetDef = context.getItemManager().getDefinition(conflictingState).unwrap();
// check same-name sibling setting of both target and existing node
if (!conflictingTargetDef.allowsSameNameSiblings() || !newNodeDef.allowsSameNameSiblings()) {
throw new ItemExistsException("cannot add child node '" + nodeName.getLocalName() + "' to " + safeGetJCRPath(parentState.getNodeId()) + ": colliding with same-named existing node");
}
}
}
RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
if ((options & CHECK_HOLD) == CHECK_HOLD) {
if (retentionReg.hasEffectiveHold(parentPath, false)) {
throw new RepositoryException("Unable to add node. Parent is affected by a hold.");
}
}
if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
if (retentionReg.hasEffectiveRetention(parentPath, false)) {
throw new RepositoryException("Unable to add node. Parent is affected by a retention.");
}
}
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class NodeImpl method getApplicableChildNodeDefinition.
/**
* Returns the applicable child node definition for a child node with the
* specified name and node type.
*
* @param nodeName
* @param nodeTypeName
* @return
* @throws ConstraintViolationException if no applicable child node definition
* could be found
* @throws RepositoryException if another error occurs
*/
protected NodeDefinitionImpl getApplicableChildNodeDefinition(Name nodeName, Name nodeTypeName) throws ConstraintViolationException, RepositoryException {
NodeTypeManagerImpl ntMgr = sessionContext.getNodeTypeManager();
QNodeDefinition cnd = getEffectiveNodeType().getApplicableChildNodeDef(nodeName, nodeTypeName, sessionContext.getNodeTypeRegistry());
return ntMgr.getNodeDefinition(cnd);
}
use of org.apache.jackrabbit.spi.QNodeDefinition in project jackrabbit by apache.
the class ItemManager method getDefinition.
NodeDefinitionImpl getDefinition(NodeState state) throws RepositoryException {
if (state.getId().equals(sessionContext.getRootNodeId())) {
// special handling required for root node
return rootNodeDef;
}
NodeId parentId = state.getParentId();
if (parentId == null) {
// removed state has parentId set to null
// get from overlayed state
ItemState overlaid = state.getOverlayedState();
if (overlaid != null) {
parentId = overlaid.getParentId();
} else {
throw new InvalidItemStateException("Could not find parent of node " + state.getNodeId());
}
}
NodeState parentState = null;
try {
// access the parent state circumventing permission check, since
// read permission on the parent isn't required in order to retrieve
// a node's definition. see also JCR-2418
ItemData parentData = getItemData(parentId, null, false);
parentState = (NodeState) parentData.getState();
if (state.getParentId() == null) {
// that used to be the actual parent
if (parentState.getStatus() == ItemState.STATUS_NEW) {
// force getting parent from attic
parentState = null;
} else {
parentState = (NodeState) parentState.getOverlayedState();
}
}
} catch (ItemNotFoundException e) {
// parent probably removed, get it from attic. see below
}
if (parentState == null) {
try {
// use overlayed state if available
parentState = (NodeState) sism.getAttic().getItemState(parentId).getOverlayedState();
} catch (ItemStateException ex) {
throw new RepositoryException(ex);
}
}
// get child node entry
ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
if (cne == null) {
throw new InvalidItemStateException("Could not find child " + state.getNodeId() + " of node " + parentState.getNodeId());
}
NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
try {
EffectiveNodeType ent = ntReg.getEffectiveNodeType(parentState.getNodeTypeName(), parentState.getMixinTypeNames());
QNodeDefinition def;
try {
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
} catch (ConstraintViolationException e) {
// fallback to child node definition of a nt:unstructured
ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
log.warn("Fallback to nt:unstructured due to unknown child " + "node definition for type '" + state.getNodeTypeName() + "'");
}
return sessionContext.getNodeTypeManager().getNodeDefinition(def);
} catch (NodeTypeConflictException e) {
throw new RepositoryException(e);
}
}
Aggregations