use of org.apache.jackrabbit.core.util.ReferenceChangeTracker in project jackrabbit by apache.
the class UserImporterTest method testInitTwice.
public void testInitTwice() {
UserImporter userImporter = createImporter();
assertTrue(userImporter.init(sImpl, sImpl, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new ReferenceChangeTracker()));
try {
userImporter.init(sImpl, sImpl, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, new ReferenceChangeTracker());
fail("calling init twice must fail");
} catch (IllegalStateException e) {
// success
}
}
use of org.apache.jackrabbit.core.util.ReferenceChangeTracker in project jackrabbit by apache.
the class BatchedItemOperations method copy.
/**
* Copies the tree at <code>srcPath</code> retrieved using the specified
* <code>srcStateMgr</code> to the new location at <code>destPath</code>.
* Returns the id of the node at its new position.
* <p>
* <b>Precondition:</b> the state manager needs to be in edit mode.
*
* @param srcPath
* @param srcStateMgr
* @param srcHierMgr
* @param srcAccessMgr
* @param destPath
* @param flag one of
* <ul>
* <li><code>COPY</code></li>
* <li><code>CLONE</code></li>
* <li><code>CLONE_REMOVE_EXISTING</code></li>
* </ul>
* @return the id of the node at its new position
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws LockException
* @throws RepositoryException
* @throws IllegalStateException if the state manager is not in edit mode.
*/
public NodeId copy(Path srcPath, ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, AccessManager srcAccessMgr, Path destPath, int flag) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException {
// check precondition
checkInEditMode();
// 1. check paths & retrieve state
NodeState srcState = getNodeState(srcStateMgr, srcHierMgr, srcPath);
Path destParentPath = destPath.getAncestor(1);
NodeState destParentState = getNodeState(destParentPath);
int ind = destPath.getIndex();
if (ind > 0) {
// subscript in name element
String msg = "invalid copy destination path: " + safeGetJCRPath(destPath) + " (subscript in name element is not allowed)";
log.debug(msg);
throw new RepositoryException(msg);
}
// 2. check access rights, lock status, node type constraints, etc.
// JCR-2269: store target node state in changelog early as a
// precautionary measure in order to isolate it from concurrent
// underlying changes while checking preconditions
stateMgr.store(destParentState);
checkAddNode(destParentState, destPath.getName(), srcState.getNodeTypeName(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
// check read access right on source node using source access manager
try {
if (!srcAccessMgr.isGranted(srcPath, Permission.READ)) {
throw new PathNotFoundException(safeGetJCRPath(srcPath));
}
} catch (ItemNotFoundException infe) {
String msg = "internal error: failed to check access rights for " + safeGetJCRPath(srcPath);
log.debug(msg);
throw new RepositoryException(msg, infe);
}
// 3. do copy operation (modify and store affected states)
ReferenceChangeTracker refTracker = new ReferenceChangeTracker();
// create deep copy of source node state
NodeState newState = copyNodeState(srcState, srcPath, srcStateMgr, srcAccessMgr, destParentState.getNodeId(), flag, refTracker);
// add to new parent
destParentState.addChildNodeEntry(destPath.getName(), newState.getNodeId());
// adjust references that refer to uuid's which have been mapped to
// newly generated uuid's on copy/clone
Iterator<Object> iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
if (adjusted != null) {
boolean weak = prop.getType() == PropertyType.WEAKREFERENCE;
newVals[i] = InternalValue.create(adjusted, weak);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = values[i];
}
}
if (modified) {
prop.setValues(newVals);
stateMgr.store(prop);
}
}
refTracker.clear();
// store states
stateMgr.store(newState);
stateMgr.store(destParentState);
return newState.getNodeId();
}
Aggregations