Package javax.jcr

Examples of javax.jcr.ItemExistsException


        AccessManager accessManager = context.getAccessManager();
        Root root = sessionDelegate.getContentSession().getLatestRoot();
        // check destination
        Tree dest = root.getTree(destPath);
        if (dest.exists()) {
            throw new ItemExistsException(destPath);
        }

        // check parent of destination
        String destParentPath = PathUtils.getParentPath(destPath);
        Tree destParent = root.getTree(destParentPath);
View Full Code Here


            }
        } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW) {
            // if conflicting node is shareable, then clone it
            String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING) {
            if (conflicting == null) {
                // since the conflicting node can't be read,
                // we can't remove it
                String msg = "node with uuid " + conflictingId + " cannot be removed";
View Full Code Here

                    // (see http://issues.apache.org/jira/browse/JCR-1128)
                    String existingIdentifier = IdentifierManager.getIdentifier(existing);
                    if (!(existingIdentifier.equals(id)
                            && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                            || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING))) {
                        throw new ItemExistsException(
                                "Node with the same UUID exists:" + existing);
                    }
                    // fall through
                }
            }
View Full Code Here

                    throw new PathNotFoundException(relPath);
                }

                if (parent.getChild(oakName) != null) {
                    throw new ItemExistsException(relPath);
                }

                // check for NODE_TYPE_MANAGEMENT permission here as we cannot
                // distinguish between user-supplied and system-generated
                // modification of that property in the PermissionValidator
                if (oakTypeName != null) {
                    PropertyState prop = PropertyStates.createProperty(JCR_PRIMARYTYPE, oakTypeName, NAME);
                    sessionContext.getAccessManager().checkPermissions(dlg.getTree(), prop, Permissions.NODE_TYPE_MANAGEMENT);
                }

                NodeDelegate added = parent.addChild(oakName, oakTypeName);
                if (added == null) {
                    throw new ItemExistsException();
                }
                nodeAdded = added;

                return NodeImpl.createNode(added, sessionContext);
            }
View Full Code Here

        try {
            existing = getItemManager().getNode(destPath);
            // there's already a node with that name:
            // check same-name sibling setting of existing node
            if (!existing.getDefinition().allowsSameNameSiblings()) {
                throw new ItemExistsException(
                        "Same name siblings are not allowed: " + existing);
            }
        } catch (AccessDeniedException ade) {
            // FIXME by throwing ItemExistsException we're disclosing too much information
            throw new ItemExistsException(destAbsPath);
        } catch (PathNotFoundException pnfe) {
            // no name collision, fall through
        }

        // verify for both source and destination parent nodes that
        // - they are checked-out
        // - are not protected neither by node type constraints nor by retention/hold
        int options = ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_LOCK |
                ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
        getValidator().checkRemove(srcParentNode, options, Permission.NONE);
        getValidator().checkModify(destParentNode, options, Permission.NONE);

        // check constraints
        // get applicable definition of target node at new location
        NodeTypeImpl nt = (NodeTypeImpl) targetNode.getPrimaryNodeType();
        org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl newTargetDef;
        try {
            newTargetDef = destParentNode.getApplicableChildNodeDefinition(destName.getName(), nt.getQName());
        } catch (RepositoryException re) {
            String msg = destAbsPath + ": no definition found in parent node's node type for new node";
            log.debug(msg);
            throw new ConstraintViolationException(msg, re);
        }
        // if there's already a node with that name also check same-name sibling
        // setting of new node; just checking same-name sibling setting on
        // existing node is not sufficient since same-name sibling nodes don't
        // necessarily have identical definitions
        if (existing != null && !newTargetDef.allowsSameNameSiblings()) {
            throw new ItemExistsException(
                    "Same name siblings not allowed: " + existing);
        }

        NodeId targetId = targetNode.getNodeId();
        int index = srcName.getIndex();
View Full Code Here

                    ops.close();
                }
            } else {
                String msg = "Unable to restore version. Versionable node already exists.";
                log.error(msg);
                throw new ItemExistsException(msg);
            }
        } else {
            WriteOperation ops = startWriteOperation();
            try {
                // create new node below parent
View Full Code Here

        // check uuid
        if (state.getEffectiveNodeType().includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            if (!state.getNodeId().equals(freeze.getFrozenId())) {
                String msg = "Unable to restore version of " + safeGetJCRPath(state) + ". UUID changed.";
                log.error(msg);
                throw new ItemExistsException(msg);
            }
        }

        // check primary type
        if (!freeze.getFrozenPrimaryType().equals(state.getState().getNodeTypeName())) {
            // todo: implement
            String msg = "Unable to restore version of " + safeGetJCRPath(state) + ". PrimaryType change not supported yet.";
            log.error(msg);
            throw new UnsupportedRepositoryOperationException(msg);
        }

        // adjust mixins
        state.setMixins(freeze.getFrozenMixinTypes());

        // For each property P present on F (other than jcr:frozenPrimaryType,
        // jcr:frozenMixinTypes and jcr:frozenUuid):
        // - If P has an OPV of COPY or VERSION then F/P is copied to N/P,
        //   replacing any existing N/P.
        // - F will never have a property with an OPV of IGNORE, INITIALIZE, COMPUTE
        //   or ABORT (see 15.2 Check-In: Creating a Version).
        Set<Name> propNames = new HashSet<Name>();
        PropertyState[] props = freeze.getFrozenProperties();
        for (PropertyState prop : props) {
            // don't restore jcr:activity
            Name name = prop.getName();
            if (!name.equals(NameConstants.JCR_ACTIVITY)) {
                state.copyFrom(prop);
                propNames.add(name);
            }
        }

        // For each property P present on N but not on F:
        // - If P has an OPV of COPY, VERSION or ABORT then N/P is removed. Note that
        //   while a node with a child item of OPV ABORT cannot be versioned, it is
        //   legal for a previously versioned node to have such a child item added to it
        //   and then for it to be restored to the state that it had before that item was
        //   added, as this step indicates.
        // - If P has an OPV of IGNORE then no change is made to N/P.
        // - If P has an OPV of INITIALIZE then, if N/P has a default value (either
        //   defined in the node type of N or implementation-defined) its value is
        //   changed to that default value. If N/P has no default value then it is left
        //   unchanged.
        // - If P has an OPV of COMPUTE then the value of N/P may be changed
        //   according to an implementation-specific mechanism.

        // remove properties that do not exist in the frozen representation
        for (PropertyState prop: state.getProperties()) {
            Name propName = prop.getName();
            if (!propNames.contains(propName)) {
                int opv = state.getDefinition(prop).getOnParentVersion();
                if (opv == OnParentVersionAction.COPY
                        || opv == OnParentVersionAction.VERSION
                        || opv == OnParentVersionAction.ABORT) {
                    state.removeProperty(propName);
                } else if (opv == OnParentVersionAction.INITIALIZE) {
                    InternalValue[] values = computeAutoValues(state, state.getDefinition(prop), true);
                    if (values != null) {
                        state.setPropertyValues(propName, prop.getType(), values, prop.isMultiValued());
                    }
                } else if (opv == OnParentVersionAction.COMPUTE) {
                    InternalValue[] values = computeAutoValues(state, state.getDefinition(prop), false);
                    if (values != null) {
                        state.setPropertyValues(propName, prop.getType(), values, prop.isMultiValued());
                    }
                }
            }
        }

        // add 'auto-create' properties that do not exist yet
        for (QPropertyDefinition def: state.getEffectiveNodeType().getAutoCreatePropDefs()) {
            if (!state.hasProperty(def.getName())) {
                InternalValue[] values = computeAutoValues(state, def, true);
                if (values != null) {
                    state.setPropertyValues(def.getName(), def.getRequiredType(), values, def.isMultiple());
                }
            }
        }

        // For each child node C present on N but not on F:
        // - If C has an OPV of COPY, VERSION or ABORT then N/C is removed.
        //   Note that while a node with a child item of OPV ABORT cannot be
        //   versioned, it is legal for a previously versioned node to have such
        //   a child item added to it and then for it to be restored to the state
        //   that it had before that item was added, as this step indicates.
        // - If C has an OPV of IGNORE then no change is made to N/C.
        // - If C has an OPV of INITIALIZE then N/C is re-initialized as if it
        //   were newly created, as defined in its node type.
        // - If C has an OPV of COMPUTE then N/C may be re-initialized according
        //   to an implementation-specific mechanism.
        LinkedList<ChildNodeEntry> toDelete = new LinkedList<ChildNodeEntry>();
        for (ChildNodeEntry entry: state.getState().getChildNodeEntries()) {
            if (!freeze.hasFrozenChildNode(entry.getName(), entry.getIndex())) {
                NodeStateEx child = state.getNode(entry.getName(), entry.getIndex());
                int opv = child.getDefinition().getOnParentVersion();
                if (copy || opv == OnParentVersionAction.COPY
                        || opv == OnParentVersionAction.VERSION
                        || opv == OnParentVersionAction.ABORT) {
                    toDelete.addFirst(entry);
                } else if (opv == OnParentVersionAction.INITIALIZE) {
                    log.warn("OPV.INITIALIZE not supported yet on restore of existing child nodes: " + safeGetJCRPath(child));
                } else if (opv == OnParentVersionAction.COMPUTE) {
                    log.warn("OPV.COMPUTE not supported yet on restore of existing child nodes: " + safeGetJCRPath(child));
                }
            }
        }
        for (ChildNodeEntry entry: toDelete) {
            state.removeNode(entry.getName(), entry.getIndex());
        }
        // need to sync with state manager
        state.store();

        // For each child node C present on F:
        // - F will never have a child node with an OPV of IGNORE, INITIALIZE,
        //   COMPUTE or ABORT (see 15.2 Check-In: Creating a Version).
        for (ChildNodeEntry entry : freeze.getFrozenChildNodes()) {
            InternalFreeze child = freeze.getFrozenChildNode(entry.getName(), entry.getIndex());
            NodeStateEx restoredChild = null;
            if (child instanceof InternalFrozenNode) {
                // - If C has an OPV of COPY or VERSION:
                //   - B is true, then F/C and its subgraph is copied to N/C, replacing
                //     any existing N/C and its subgraph and any node in the workspace
                //     with the same identifier as C or a node in the subgraph of C is
                //     removed.
                //   - B is false, then F/C and its subgraph is copied to N/C, replacing
                //     any existing N/C and its subgraph unless there exists a node in the
                //     workspace with the same identifier as C, or a node in the subgraph
                //     of C, in which case an ItemExistsException is thrown , all
                //     changes made by the restore are rolled back leaving N unchanged.

                InternalFrozenNode f = (InternalFrozenNode) child;

                // if node is present, remove it
                state.removeNode(entry.getName(), entry.getIndex());

                // check for existing
                if (f.getFrozenId() != null) {
                    if (stateMgr.hasItemState(f.getFrozenId())) {
                        NodeStateEx existing = state.getNode(f.getFrozenId());
                        if (removeExisting) {
                            NodeStateEx parent = existing.getParent();
                            parent.removeNode(existing);
                            parent.store();
                        } else if (existing.getState().isShareable()) {
                            // if existing node is shareable, then clone it
                            restoredChild = state.moveFrom(existing, existing.getName(), true);
                        } else if (!existing.hasAncestor(state.getNodeId())){
                            String msg = "Unable to restore node, item already exists " +
                                    "outside of restored tree: " + safeGetJCRPath(existing);
                            log.error(msg);
                            throw new ItemExistsException(msg);
                        }

                    }
                }
                if (restoredChild == null) {
                    restoredChild = state.addNode(f.getName(), f.getFrozenPrimaryType(), f.getFrozenId());
                    restoredChild.setMixins(f.getFrozenMixinTypes());
                }
                internalRestoreFrozen(restoredChild, f, vsel, restored, removeExisting, true);

            } else if (child instanceof InternalFrozenVersionHistory) {
                //   Each child node C of N where C has an OPV of VERSION and C is
                //   mix:versionable, is represented in F not as a copy of N/C but as
                //   special node containing a reference to the version history of
                //   C. On restore, the following occurs:
                //   - If the workspace currently has an already existing node corresponding
                //     to C's version history and the removeExisting flag of the restore is
                //     set to true, then that instance of C becomes the child of the restored N.
                //   - If the workspace currently has an already existing node corresponding
                //     to C's version history and the removeExisting flag of the restore is
                //     set to false then an ItemExistsException is thrown.
                //   - If the workspace does not have an instance of C then one is restored from
                //     C's version history:
                //     - If the restore was initiated through a restoreByLabel where L is
                //       the specified label and there is a version of C with the label L then
                //       that version is restored.
                //     - If the version history of C does not contain a version with the label
                //       L or the restore was initiated by a method call that does not specify
                //       a label then the workspace in which the restore is being performed
                //       will determine which particular version of C will be restored. This
                //       determination depends on the configuration of the workspace and
                //       is outside the scope of this specification.
                InternalFrozenVersionHistory fh = (InternalFrozenVersionHistory) child;
                InternalVersionHistory vh = vMgr.getVersionHistory(fh.getVersionHistoryId());
                // get desired version from version selector
                InternalVersion v = vsel.select(vh);
                Name oldVersion = null;

                // check if representing versionable already exists somewhere
                NodeId nodeId = vh.getVersionableId();
                if (stateMgr.hasItemState(nodeId)) {
                    restoredChild = state.getNode(nodeId);
                    if (restoredChild.getParentId().equals(state.getNodeId())) {
                        // if same parent, ignore
                    } else if (removeExisting) {
                        NodeStateEx parent = restoredChild.getNode(restoredChild.getParentId());
                        state.moveFrom(restoredChild, fh.getName(), false);
                        parent.store();

                        // get old version name
                        oldVersion = getBaseVersion(restoredChild).getName();
                    } else {
                        // since we delete the OPV=Copy children beforehand, all
                        // found nodes must be outside of this tree
                        String msg = "Unable to restore node, item already exists " +
                                "outside of restored tree: " + safeGetJCRPath(restoredChild);
                        log.error(msg);
                        throw new ItemExistsException(msg);
                    }
                }

                // check existing version of item exists
                if (restoredChild == null) {
View Full Code Here

                } 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);
View Full Code Here

            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
                    }
                }
View Full Code Here

                return null;
            }
            String msg = "a node with uuid " + nodeInfo.getId()
                    + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING) {
            // make sure conflicting node is not importTarget or an ancestor thereof
            Path p0 = hierMgr.getPath(importTarget.getNodeId());
            Path p1 = hierMgr.getPath(conflicting.getNodeId());
            try {
View Full Code Here

TOP

Related Classes of javax.jcr.ItemExistsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.