use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.
/**
* Test orphan version history cleaning in multiple workspace.
* @throws RepositoryException if an error occurs.
*/
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
Session session = n.getSession();
VersionHistory vh = n.getVersionHistory();
String vhUuid = vh.getUUID();
assertExists(session, vhUuid);
// First version
Version v10 = n.checkin();
n.checkout();
Workspace defaultWorkspace = n.getSession().getWorkspace();
Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
// Clone the node in another workspace
otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
Node otherWsRootNode = otherWsSession.getRootNode();
Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
// Ensure that version histories are the same
assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
Version v11 = clonedNode.checkin();
clonedNode.checkout();
// Remove node
n.remove();
testRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the first version
vh.removeVersion(v10.getName());
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove cloned node
clonedNode.remove();
otherWsRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the last version
vh.removeVersion(v11.getName());
try {
session.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the default workspace");
} catch (ItemNotFoundException e) {
// Expected
}
try {
otherWsSession.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the other workspace");
} catch (ItemNotFoundException e) {
// Expected
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NamePropertyTest method testGetNode.
/**
* Since JCR 2.0 a path property can be dereferenced if it points to a
* Node.
* TODO: create several tests out of this one
*/
public void testGetNode() throws RepositoryException {
if (!multiple) {
String path = prop.getString();
if (prop.getParent().hasNode(path)) {
Node n = prop.getNode();
assertEquals("The name of the dereferenced property must be equal to the value", path, n.getName());
} else {
try {
prop.getNode();
fail("Calling Property.getNode() for a NAME value that doesn't have a corresponding Node, ItemNotFoundException is expected");
} catch (ItemNotFoundException e) {
// success.
}
}
} else {
try {
prop.getNode();
fail("Property.getNode() called on a multivalue property " + "should throw a ValueFormatException.");
} catch (ValueFormatException vfe) {
//ok
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class Move method create.
//------------------------------------------------------------< Factory >---
public static Operation create(Path srcPath, Path destPath, HierarchyManager hierMgr, PathResolver resolver, boolean sessionMove) throws ItemExistsException, NoSuchNodeTypeException, RepositoryException {
// src must not be ancestor of destination
if (srcPath.isAncestorOf(destPath)) {
String msg = "Invalid destination path: cannot be descendant of source path (" + LogUtil.safeGetJCRPath(destPath, resolver) + "," + LogUtil.safeGetJCRPath(srcPath, resolver) + ")";
log.debug(msg);
throw new RepositoryException(msg);
}
// destination must not contain an index
int index = destPath.getIndex();
if (index != Path.INDEX_UNDEFINED) {
// subscript in name element
String msg = "Invalid destination path: subscript in name element is not allowed (" + LogUtil.safeGetJCRPath(destPath, resolver) + ")";
log.debug(msg);
throw new RepositoryException(msg);
}
// root node cannot be moved:
if (srcPath.denotesRoot() || destPath.denotesRoot()) {
String msg = "Cannot move the root node.";
log.debug(msg);
throw new RepositoryException(msg);
}
NodeState srcState = getNodeState(srcPath, hierMgr);
NodeState srcParentState = getNodeState(srcPath.getAncestor(1), hierMgr);
NodeState destParentState = getNodeState(destPath.getAncestor(1), hierMgr);
Name destName = destPath.getName();
if (sessionMove) {
NodeEntry destEntry = (NodeEntry) destParentState.getHierarchyEntry();
// force child node entries list to be present before the move is executed
// on the hierarchy entry.
assertChildNodeEntries(srcParentState);
assertChildNodeEntries(destParentState);
if (destEntry.hasNodeEntry(destName)) {
NodeEntry existing = destEntry.getNodeEntry(destName, Path.INDEX_DEFAULT);
if (existing != null && sessionMove) {
try {
if (!existing.getNodeState().getDefinition().allowsSameNameSiblings()) {
throw new ItemExistsException("Node existing at move destination does not allow same name siblings.");
}
} catch (ItemNotFoundException e) {
// existing apparent not valid any more -> probably no conflict
}
}
}
}
Move move = new Move(srcState, srcParentState, destParentState, destName, sessionMove);
return move;
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class RepositoryServiceImpl method getPropertyInfo.
/**
* @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
*/
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
Path p = getPath(propertyId, sessionInfo);
String uri = getURI(p, sessionInfo);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, LAZY_PROPERTY_NAME_SET, DavConstants.DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length != 1) {
throw new ItemNotFoundException("Unable to retrieve the PropertyInfo. No such property " + uri);
}
MultiStatusResponse mresponse = mresponses[0];
DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
int propertyType = PropertyType.valueFromName(props.get(JCR_TYPE).getValue().toString());
if (propertyType == PropertyType.BINARY) {
DavProperty<?> lengthsProp = props.get(JCR_LENGTHS);
if (lengthsProp != null) {
// multivalued binary property
long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
QValue[] qValues = new QValue[lengths.length];
for (int i = 0; i < lengths.length; i++) {
qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], uri, i);
}
return new PropertyInfoImpl(propertyId, p, propertyType, qValues);
} else {
// single valued binary property
long length = Long.parseLong(props.get(JCR_LENGTH).getValue().toString());
QValue qValue = getQValueFactory(sessionInfo).create(length, uri, QValueFactoryImpl.NO_INDEX);
return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
}
} else if (props.contains(JCR_GET_STRING)) {
// single valued non-binary property
Object v = props.get(JCR_GET_STRING).getValue();
String str = (v == null) ? "" : v.toString();
QValue qValue = ValueFormat.getQValue(str, propertyType, getNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
return new PropertyInfoImpl(propertyId, p, propertyType, qValue);
} else {
// didn't expose the JCR_GET_STRING dav property.
return super.getPropertyInfo(sessionInfo, propertyId);
}
} catch (IOException e) {
log.error("Internal error while retrieving ItemInfo.", e);
throw new RepositoryException(e.getMessage());
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ValueLoader method loadType.
int loadType(String uri) throws RepositoryException, IOException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DavConstants.DEPTH_0);
HttpResponse response = client.execute(request, context);
request.checkSuccess(response);
MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (responses.length == 1) {
DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
DavProperty<?> type = props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
if (type != null) {
return PropertyType.valueFromName(type.getValue().toString());
} else {
throw new RepositoryException("Internal error. Cannot retrieve property type at " + uri);
}
} else {
throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
}
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations