Search in sources :

Example 51 with ItemExistsException

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
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 52 with ItemExistsException

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
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 53 with ItemExistsException

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
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) NodeDefinition(javax.jcr.nodetype.NodeDefinition) VersionManager(javax.jcr.version.VersionManager)

Example 54 with ItemExistsException

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;
}
Also used : ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 55 with ItemExistsException

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();
    }
}
Also used : InputSource(org.xml.sax.InputSource) ImportHandler(org.apache.jackrabbit.jcr2spi.xml.ImportHandler) SAXParser(javax.xml.parsers.SAXParser) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ItemExistsException(javax.jcr.ItemExistsException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) VersionException(javax.jcr.version.VersionException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemNotFoundException(javax.jcr.ItemNotFoundException) LoginException(javax.jcr.LoginException) SAXException(org.xml.sax.SAXException) AccessControlException(java.security.AccessControlException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) NamespaceException(javax.jcr.NamespaceException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

ItemExistsException (javax.jcr.ItemExistsException)63 Node (javax.jcr.Node)25 RepositoryException (javax.jcr.RepositoryException)25 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15 NodeDefinition (javax.jcr.nodetype.NodeDefinition)14 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 Version (javax.jcr.version.Version)13 NodeId (org.apache.jackrabbit.core.id.NodeId)12 Name (org.apache.jackrabbit.spi.Name)12 NodeState (org.apache.jackrabbit.core.state.NodeState)10 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)9 Path (org.apache.jackrabbit.spi.Path)8 PathNotFoundException (javax.jcr.PathNotFoundException)6 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)6 NodeImpl (org.apache.jackrabbit.core.NodeImpl)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 ArrayList (java.util.ArrayList)4 AccessDeniedException (javax.jcr.AccessDeniedException)4