use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.
the class BatchedItemOperations method checkRemoveNode.
/**
* Checks if removing the given target node from the specifed parent
* is allowed in the current context.
*
* @param targetState
* @param parentId
* @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 access on parent
* and remove privilege on target 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_REFERENCES}</code>:
* make sure no references exist on target node</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 ReferentialIntegrityException
* @throws RepositoryException
*/
public void checkRemoveNode(NodeState targetState, NodeId parentId, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException {
if (targetState.getParentId() == null) {
// root or orphaned node
throw new ConstraintViolationException("cannot remove root node");
}
Path targetPath = hierMgr.getPath(targetState.getNodeId());
NodeState parentState = getNodeState(parentId);
Path parentPath = hierMgr.getPath(parentId);
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) {
try {
AccessManager accessMgr = context.getAccessManager();
// make sure current session is granted read access on parent node
if (!accessMgr.isGranted(targetPath, Permission.READ)) {
throw new PathNotFoundException(safeGetJCRPath(targetPath));
}
// make sure current session is allowed to remove target node
if (!accessMgr.isGranted(targetPath, Permission.REMOVE_NODE)) {
throw new AccessDeniedException(safeGetJCRPath(targetPath) + ": not allowed to remove node");
}
} catch (ItemNotFoundException infe) {
String msg = "internal error: failed to check access rights for " + safeGetJCRPath(targetPath);
log.debug(msg);
throw new RepositoryException(msg, infe);
}
}
if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
QItemDefinition parentDef = context.getItemManager().getDefinition(parentState).unwrap();
if (parentDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(parentId) + ": cannot remove child node of protected parent node");
}
QItemDefinition targetDef = context.getItemManager().getDefinition(targetState).unwrap();
if (targetDef.isMandatory()) {
throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove mandatory node");
}
if (targetDef.isProtected()) {
throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove protected node");
}
}
if ((options & CHECK_REFERENCES) == CHECK_REFERENCES) {
EffectiveNodeType ent = getEffectiveNodeType(targetState);
if (ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
NodeId targetId = targetState.getNodeId();
if (stateMgr.hasNodeReferences(targetId)) {
try {
NodeReferences refs = stateMgr.getNodeReferences(targetId);
if (refs.hasReferences()) {
throw new ReferentialIntegrityException(safeGetJCRPath(targetPath) + ": cannot remove node with references");
}
} catch (ItemStateException ise) {
String msg = "internal error: failed to check references on " + safeGetJCRPath(targetPath);
log.error(msg, ise);
throw new RepositoryException(msg, ise);
}
}
}
}
RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
if ((options & CHECK_HOLD) == CHECK_HOLD) {
if (retentionReg.hasEffectiveHold(targetPath, true)) {
throw new RepositoryException("Unable to perform removal. Node is affected by a hold.");
}
}
if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
if (retentionReg.hasEffectiveRetention(targetPath, true)) {
throw new RepositoryException("Unable to perform removal. Node is affected by a retention.");
}
}
}
use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.
the class RetentionRegistryImplTest method testAddMultipleHold.
public void testAddMultipleHold() throws RepositoryException, NotExecutableException {
SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
RetentionRegistry re = s.getRetentionRegistry();
try {
retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
superuser.save();
// hold is not deep -> only applies to childN2
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
retentionMgr.addHold(childN2.getPath(), getHoldName(), true);
superuser.save();
// now deep hold must be taken into account
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
} finally {
s.logout();
Hold[] hdls = retentionMgr.getHolds(childN2.getPath());
for (int i = 0; i < hdls.length; i++) {
retentionMgr.removeHold(childN2.getPath(), hdls[i]);
}
superuser.save();
}
}
use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.
the class RetentionRegistryImplTest method testRemoveRetentionPolicy.
public void testRemoveRetentionPolicy() throws RepositoryException {
SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
RetentionRegistry re = s.getRetentionRegistry();
try {
retentionMgr.removeRetentionPolicy(childNPath);
// retention must still be in effect.
assertTrue(re.hasEffectiveRetention(s.getQPath(childNPath), false));
superuser.save();
assertFalse(re.hasEffectiveRetention(s.getQPath(childNPath), false));
} finally {
s.logout();
}
}
use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.
the class RetentionRegistryImplTest method testAddHold.
public void testAddHold() throws RepositoryException, NotExecutableException {
SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
RetentionRegistry re = s.getRetentionRegistry();
Hold h = null;
try {
h = retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
// hold must not be effective yet
assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
superuser.save();
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
} finally {
s.logout();
if (h != null) {
retentionMgr.removeHold(childN2.getPath(), h);
superuser.save();
}
}
}
Aggregations