use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class NodeImpl method restore.
/**
* Common internal restore method for the various Node#restore calls.
*
* @param targetNode
* @param relQPath
* @param version
* @param removeExisting
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws VersionException
* @throws ConstraintViolationException
* @throws UnsupportedRepositoryOperationException
* @throws LockException
* @throws InvalidItemStateException
* @throws RepositoryException
*/
private void restore(NodeImpl targetNode, Path relQPath, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
if (relQPath == null) {
/* restore target already exists. */
// target must be versionable
targetNode.checkIsVersionable();
VersionHistory vH = targetNode.getVersionHistory();
// version must be a version of the target node
if (!vH.isSame(version.getContainingHistory())) {
throw new VersionException("Version " + version + " does not correspond to the restore target.");
}
// version must not be the root version
if (vH.getRootVersion().isSame(version)) {
throw new VersionException("Attempt to restore root version.");
}
targetNode.checkIsWritable();
targetNode.checkIsLocked();
} else {
/* If no node exists at relPath then a VersionException is thrown if
the parent node is not checked out. */
if (!targetNode.isCheckedOut()) {
throw new VersionException("Parent " + targetNode.safeGetJCRPath() + " for non-existing restore target '" + LogUtil.safeGetJCRPath(relQPath, session.getPathResolver()) + "' must be checked out.");
}
targetNode.checkIsLocked();
// NOTE: check for nodetype constraint violation is left to the 'server'
}
NodeState versionState = session.getVersionState(version);
session.getVersionStateManager().restore(targetNode.getNodeState(), relQPath, versionState, removeExisting);
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class NodeImpl method resolveMergeConflict.
/**
* Internal method covering both {@link #doneMerge(Version)} and {@link #cancelMerge(Version)}.
*
* @param version
* @param done
* @throws VersionException
* @throws InvalidItemStateException
* @throws UnsupportedRepositoryOperationException
* @throws RepositoryException
*/
private void resolveMergeConflict(Version version, boolean done) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException {
checkIsVersionable();
checkHasPendingChanges();
checkIsLocked();
// check if checked out
if (!isCheckedOut()) {
String msg = "Unable to resolve merge conflict. Node is checked-in: " + safeGetJCRPath();
log.error(msg);
throw new VersionException(msg);
}
// check if version is in mergeFailed list
boolean isConflicting = false;
if (hasProperty(NameConstants.JCR_MERGEFAILED)) {
Value[] vals = getProperty(NameConstants.JCR_MERGEFAILED).getValues();
for (int i = 0; i < vals.length && !isConflicting; i++) {
isConflicting = vals[i].getString().equals(version.getUUID());
}
}
if (!isConflicting) {
String msg = "Unable to resolve merge conflict. Specified version is not in jcr:mergeFailed property: " + safeGetJCRPath();
log.error(msg);
throw new VersionException(msg);
}
NodeState versionState = session.getVersionState(version);
session.getVersionStateManager().resolveMergeConflict(getNodeState(), versionState, done);
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class AccessControlManagerImpl method getSupportedPrivileges.
public Privilege[] getSupportedPrivileges(String absPath) throws PathNotFoundException, RepositoryException {
NodeState state = getNodeState(npResolver.getQPath(absPath));
Map<String, Privilege> privileges = acProvider.getSupportedPrivileges(sessionInfo, state.getNodeId(), npResolver);
return privileges.values().toArray(new Privilege[privileges.size()]);
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class AccessControlManagerImpl method createAceNode.
private void createAceNode(SetTree operation, NodeState parentState, AccessControlEntry entry) throws RepositoryException {
AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
String uuid = null;
boolean isAllow = ace.isAllow();
Name nodeName = getUniqueNodeName(parentState, (isAllow) ? "allow" : "deny");
Name nodeTypeName = (isAllow) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
NodeState aceNode = addNode(operation, parentState, nodeName, uuid, nodeTypeName);
// add rep:principalName property
String valueStr = ace.getPrincipal().getName();
QValue value = qvf.create(valueStr, PropertyType.STRING);
addProperty(operation, aceNode, N_REP_PRINCIPAL_NAME, PropertyType.STRING, new QValue[] { value });
// add rep:privileges MvProperty
Privilege[] privs = ace.getPrivileges();
QValue[] vls = new QValue[privs.length];
Name privilegeName = null;
try {
for (int i = 0; i < privs.length; i++) {
privilegeName = npResolver.getQName(privs[i].getName());
vls[i] = qvf.create(privilegeName.toString(), PropertyType.NAME);
}
} catch (ValueFormatException e) {
throw new RepositoryException(e.getMessage());
}
addProperty(operation, aceNode, N_REP_PRIVILEGES, PropertyType.NAME, vls);
// TODO: add single and mv restrictions
}
use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.
the class AccessControlManagerImpl method setPolicy.
public void setPolicy(String absPath, AccessControlPolicy policy) throws RepositoryException {
checkValidNodePath(absPath);
checkValidPolicy(policy);
checkAcccessControlItem(absPath);
SetTree operation;
NodeState aclNode = getAclNode(absPath);
if (aclNode == null) {
// policy node doesn't exist at absPath -> create one.
Name name = (absPath == null) ? N_REPO_POLICY : N_POLICY;
NodeState parent = null;
Name mixinType = null;
if (absPath == null) {
parent = getRootNodeState();
mixinType = NT_REP_REPO_ACCESS_CONTROLLABLE;
} else {
parent = getNodeState(absPath);
mixinType = NT_REP_ACCESS_CONTROLLABLE;
}
setMixin(parent, mixinType);
operation = SetTree.create(itemStateMgr, parent, name, NT_REP_ACL, null);
aclNode = operation.getTreeState();
} else {
Iterator<NodeEntry> it = getNodeEntry(aclNode).getNodeEntries();
while (it.hasNext()) {
it.next().transientRemove();
}
operation = SetTree.create(aclNode);
}
// create the entry nodes
for (AccessControlEntry entry : ((AccessControlListImpl) policy).getAccessControlEntries()) {
createAceNode(operation, aclNode, entry);
}
itemStateMgr.execute(operation);
}
Aggregations