use of javax.jcr.ItemExistsException in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflictJcr2_3.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionManager.restore(versionableNode.getPath(), v.getName(), false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.ItemExistsException in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflictJcr2_2.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testRestoreWithUUIDConflictJcr2_2() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionManager.restore(v, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.ItemExistsException in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithUUIDConflictJcr2.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testWorkspaceRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException {
try {
// Verify that nodes used for the test are indeed versionable
NodeDefinition nd = wVersionableNode.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Nodes must be versionable in order to run this test.");
}
VersionManager versionManager = wVersionableNode.getSession().getWorkspace().getVersionManager();
String path = wVersionableNode.getPath();
Version v = versionManager.checkin(path);
versionManager.checkout(path);
wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName());
wSuperuser.save();
wSuperuser.getWorkspace().getVersionManager().restore(new Version[] { v }, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.ItemExistsException in project jackrabbit by apache.
the class NodeEntryImpl method addNewPropertyEntry.
/**
* @see NodeEntry#addNewPropertyEntry(Name, QPropertyDefinition, QValue[], int)
*/
public PropertyEntry addNewPropertyEntry(Name propName, QPropertyDefinition definition, QValue[] values, int propertyType) throws ItemExistsException, RepositoryException {
// check for an existing property
PropertyEntry existing = properties.get(propName);
if (existing != null) {
try {
PropertyState existingState = existing.getPropertyState();
int status = existingState.getStatus();
if (Status.isTerminal(status)) {
// an old property-entry that is not valid any more
properties.remove(existing);
} else if (status == Status.EXISTING_REMOVED) {
// transiently removed -> move it to the attic
propertiesInAttic.put(propName, existing);
} else {
// existing is still existing -> cannot add same-named property
throw new ItemExistsException(propName.toString());
}
} catch (ItemNotFoundException e) {
// entry does not exist on the persistent layer
// -> therefore remove from properties map
properties.remove(existing);
} catch (RepositoryException e) {
// some other error -> remove from properties map
properties.remove(existing);
}
}
PropertyEntry entry = factory.createPropertyEntry(this, propName);
PropertyState state = getItemStateFactory().createNewPropertyState(entry, definition, values, propertyType);
entry.setItemState(state);
// add the property entry if creating the new state was successful
properties.add(entry);
return entry;
}
use of javax.jcr.ItemExistsException in project jackrabbit by apache.
the class SessionImpl method importXML.
/**
* @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
*/
@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException {
// NOTE: checks are performed by 'getImportContentHandler'
ImportHandler handler = (ImportHandler) getImportContentHandler(parentAbsPath, uuidBehavior);
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
SAXParser parser = factory.newSAXParser();
parser.parse(new InputSource(in), handler);
} catch (SAXException se) {
// check for wrapped repository exception
Exception e = se.getException();
if (e != null && e instanceof RepositoryException) {
throw (RepositoryException) e;
} else {
String msg = "failed to parse XML stream";
log.debug(msg);
throw new InvalidSerializedDataException(msg, se);
}
} catch (ParserConfigurationException e) {
throw new RepositoryException("SAX parser configuration error", e);
} finally {
// JCR-2903
in.close();
}
}
Aggregations