use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testObservation.
//------------------------------------------------------ specification tests
/**
* Verify that observation events are sent only once (6.13.15).
*/
public void testObservation() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.save();
// add mixin
b1.addMixin("mix:shareable");
b1.save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
// event listener that counts events received
class EventCounter implements SynchronousEventListener {
private int count;
public void onEvent(EventIterator events) {
while (events.hasNext()) {
events.nextEvent();
count++;
}
}
public int getEventCount() {
return count;
}
public void resetCount() {
count = 0;
}
}
EventCounter el = new EventCounter();
ObservationManager om = superuser.getWorkspace().getObservationManager();
// add node underneath shared set: verify it generates one event only
om.addEventListener(el, Event.NODE_ADDED, testRootNode.getPath(), true, null, null, false);
b1.addNode("c");
b1.save();
superuser.getWorkspace().getObservationManager().removeEventListener(el);
assertEquals(1, el.getEventCount());
// remove node underneath shared set: verify it generates one event only
el.resetCount();
om.addEventListener(el, Event.NODE_REMOVED, testRootNode.getPath(), true, null, null, false);
b1.getNode("c").remove();
b1.save();
superuser.getWorkspace().getObservationManager().removeEventListener(el);
assertEquals(1, el.getEventCount());
// add property underneath shared set: verify it generates one event only
el.resetCount();
om.addEventListener(el, Event.PROPERTY_ADDED, testRootNode.getPath(), true, null, null, false);
b1.setProperty("c", "1");
b1.save();
superuser.getWorkspace().getObservationManager().removeEventListener(el);
assertEquals(1, el.getEventCount());
// modify property underneath shared set: verify it generates one event only
el.resetCount();
om.addEventListener(el, Event.PROPERTY_CHANGED, testRootNode.getPath(), true, null, null, false);
b1.setProperty("c", "2");
b1.save();
superuser.getWorkspace().getObservationManager().removeEventListener(el);
assertEquals(1, el.getEventCount());
// remove property underneath shared set: verify it generates one event only
el.resetCount();
om.addEventListener(el, Event.PROPERTY_REMOVED, testRootNode.getPath(), true, null, null, false);
b1.getProperty("c").remove();
b1.save();
superuser.getWorkspace().getObservationManager().removeEventListener(el);
assertEquals(1, el.getEventCount());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ShareableNodeTest method testName.
public void testName() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
Node s = n1.addNode(nodeName3);
s.addMixin(mixShareable);
testRootNode.save();
Workspace wsp = superuser.getWorkspace();
wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + nodeName4, false);
String stmt = testPath + "//" + nodeName3;
NodeIterator nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//" + nodeName4;
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
// remove a node from the shared set
s.removeShare();
testRootNode.save();
s = n2.getNode(nodeName4);
stmt = testPath + "//" + nodeName3;
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "//" + nodeName4;
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
// remove remaining node from the shared set
s.removeShare();
testRootNode.save();
stmt = testPath + "//" + nodeName3;
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "//" + nodeName4;
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class AbstractItemResource method copy.
/**
* Copies the underlying repository item to the indicated destination. If
* the locator of the specified destination resource indicates a different
* workspace, {@link Workspace#copy(String, String, String)} is used to perform
* the copy operation, {@link Workspace#copy(String, String)} otherwise.
* <p>
* Note, that this implementation does not support shallow copy.
*
* @param destination
* @param shallow
* @throws DavException
* @see DavResource#copy(DavResource, boolean)
* @see Workspace#copy(String, String)
* @see Workspace#copy(String, String, String)
*/
@Override
public void copy(DavResource destination, boolean shallow) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
// TODO: support shallow and deep copy is required by RFC 2518
if (shallow) {
throw new DavException(DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy.");
}
try {
String itemPath = getLocator().getRepositoryPath();
String destItemPath = destination.getLocator().getRepositoryPath();
Workspace workspace = getRepositorySession().getWorkspace();
if (getLocator().isSameWorkspace(destination.getLocator())) {
workspace.copy(itemPath, destItemPath);
} else {
log.error("Copy between workspaces is not yet implemented (src: '" + getHref() + "', dest: '" + destination.getHref() + "')");
throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
}
} catch (PathNotFoundException e) {
// according to RFC 2518, should not occur
throw new DavException(DavServletResponse.SC_NOT_FOUND, e.getMessage());
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class JcrRemotingServlet method clone.
private static String clone(Session session, String[] cloneArgs, DavResourceLocator reqLocator) throws RepositoryException {
Workspace wsp = session.getWorkspace();
String destPath = null;
for (String cloneArg : cloneArgs) {
String[] args = cloneArg.split(",");
if (args.length == 4) {
wsp.clone(args[0], args[1], args[2], Boolean.valueOf(args[3]));
destPath = args[2];
} else {
throw new RepositoryException(":clone parameter must have a value consisting of the 4 args needed for a Workspace.clone() call.");
}
}
return buildLocationHref(session, destPath, reqLocator);
}
use of javax.jcr.Workspace in project jackrabbit by apache.
the class ItemManagerImpl method dispose.
//--------------------------------------------------------< ItemManager >---
/**
* @see ItemManager#dispose()
*/
public void dispose() {
// stop listening
Workspace wsp = session.getWorkspace();
if (wsp instanceof WorkspaceImpl) {
((WorkspaceImpl) wsp).getItemStateFactory().removeCreationListener(this);
}
// ... and clear the cache.
itemCache.clear();
}
Aggregations