use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class CheckoutTest method testCheckoutNonVersionableNodeJcr2.
/**
* Test calling VersionManager.checkout(P) with P denoting the absolute
* path of a non-versionable node.
*/
public void testCheckoutNonVersionableNodeJcr2() throws RepositoryException {
VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager();
String path = nonVersionableNode.getPath();
try {
versionManager.checkout(path);
fail("VersionManager.checkout(P) with P denoting the absolute path of a non-versionable node must throw UnsupportedRepositoryOperationException");
} catch (UnsupportedRepositoryOperationException e) {
//success
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class NodeTypeManagerImplTest method testUnregisterNodeTypes.
public void testUnregisterNodeTypes() throws RepositoryException {
NodeTypeTemplate test = ntMgr.createNodeTypeTemplate();
test.setName("testNodeType2");
ntMgr.registerNodeType(test, true);
NodeType nt = ntMgr.getNodeType("testNodeType2");
assertNotNull(nt);
assertEquals("testNodeType2", nt.getName());
boolean supported = false;
try {
ntMgr.unregisterNodeType(test.getName());
supported = true;
} catch (UnsupportedRepositoryOperationException e) {
// ok
} catch (RepositoryException e) {
// TODO improve
if (e.getMessage().contains("not yet implemented")) {
// ok (original message in jr-core)
} else {
throw e;
}
}
if (supported) {
try {
ntMgr.getNodeType("testNodeType2");
fail("should not be available any more");
} catch (NoSuchNodeTypeException e) {
// success
}
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class EventFactory method fromJCREvent.
public Event fromJCREvent(javax.jcr.observation.Event e) throws RepositoryException {
Path p = e.getPath() != null ? resolver.getQPath(e.getPath()) : null;
Path parent = p != null ? p.getAncestor(1) : null;
int type = e.getType();
NodeId parentId = parent != null ? idFactory.createNodeId((String) null, parent) : null;
String identifier = e.getIdentifier();
ItemId itemId;
Node node = null;
if (identifier != null) {
itemId = idFactory.fromJcrIdentifier(e.getIdentifier());
try {
node = session.getItem(e.getPath()).getParent();
} catch (RepositoryException re) {
// ignore. TODO improve
}
} else {
switch(type) {
case Event.NODE_ADDED:
case Event.NODE_MOVED:
node = session.getItem(e.getPath()).getParent();
case Event.NODE_REMOVED:
itemId = idFactory.createNodeId((String) null, p);
break;
case Event.PROPERTY_ADDED:
case Event.PROPERTY_CHANGED:
node = session.getItem(e.getPath()).getParent();
case Event.PROPERTY_REMOVED:
itemId = idFactory.createPropertyId(parentId, p.getName());
break;
case Event.PERSIST:
default:
itemId = null;
}
}
Name nodeTypeName = null;
Name[] mixinTypes = Name.EMPTY_ARRAY;
if (node != null) {
try {
parentId = idFactory.createNodeId(node.getUUID(), null);
} catch (UnsupportedRepositoryOperationException ex) {
// not referenceable
}
nodeTypeName = resolver.getQName(node.getPrimaryNodeType().getName());
mixinTypes = getNodeTypeNames(node.getMixinNodeTypes(), resolver);
}
Map<Name, QValue> info = new HashMap<Name, QValue>();
Map<String, Object> jcrInfo = e.getInfo();
for (Map.Entry<String, Object> entry : jcrInfo.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Name name = resolver.getQName(key);
if (value != null) {
// event information is generated for NODE_MOVED only in which
// case all values are of type PATH.
QValue v = ValueFormat.getQValue(value.toString(), PropertyType.PATH, resolver, qValueFactory);
info.put(name, v);
} else {
info.put(name, null);
}
}
return new EventImpl(e.getType(), p, itemId, parentId, nodeTypeName, mixinTypes, e.getUserID(), e.getUserData(), e.getDate(), info);
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method checkout.
/**
* Performs a checkout on a versionable tree.
*
* @param workspaceRoot a fresh workspace root without pending changes.
* @param versionablePath the absolute path to the versionable node to check out.
* @throws UnsupportedRepositoryOperationException
* if the versionable tree isn't actually
* versionable.
* @throws RepositoryException if an error occurs while checking the
* node type of the tree.
* @throws IllegalStateException if the workspaceRoot has pending changes.
* @throws IllegalArgumentException if the {@code versionablePath} is
* not absolute.
*/
public void checkout(@Nonnull Root workspaceRoot, @Nonnull String versionablePath) throws UnsupportedRepositoryOperationException, InvalidItemStateException, RepositoryException {
checkState(!workspaceRoot.hasPendingChanges());
checkArgument(PathUtils.isAbsolute(versionablePath));
Tree versionable = workspaceRoot.getTree(versionablePath);
if (!isVersionable(versionable)) {
throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
}
if (!isCheckedOut(versionable)) {
versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.TRUE, Type.BOOLEAN);
try {
workspaceRoot.commit();
refresh();
} catch (CommitFailedException e) {
workspaceRoot.refresh();
throw e.asRepositoryException();
}
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method checkin.
/**
* Performs a checkin on a versionable tree and returns the tree that
* represents the created version.
*
* @param versionable the versionable node to check in.
* @return the created version.
* @throws InvalidItemStateException if the current root has pending
* changes.
* @throws UnsupportedRepositoryOperationException
* if the versionable tree isn't actually
* versionable.
* @throws RepositoryException if an error occurs while checking the
* node type of the tree.
*/
@Nonnull
public Tree checkin(@Nonnull Tree versionable) throws RepositoryException, InvalidItemStateException, UnsupportedRepositoryOperationException {
if (sessionDelegate.hasPendingChanges()) {
throw new InvalidItemStateException("Unable to perform checkin. " + "Session has pending changes.");
}
if (!isVersionable(versionable)) {
throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
}
if (isCheckedOut(versionable)) {
Tree baseVersion = getExistingBaseVersion(versionable);
versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.FALSE, Type.BOOLEAN);
PropertyState created = baseVersion.getProperty(JCR_CREATED);
if (created != null) {
long c = ISO8601.parse(created.getValue(Type.DATE)).getTimeInMillis();
while (System.currentTimeMillis() == c) {
// busy-wait for System.currentTimeMillis to change
// so that the new version has a distinct timestamp
}
}
try {
sessionDelegate.commit();
refresh();
} catch (CommitFailedException e) {
sessionDelegate.refresh(true);
throw e.asRepositoryException();
}
}
return getExistingBaseVersion(getWorkspaceRoot().getTree(versionable.getPath()));
}
Aggregations