Search in sources :

Example 21 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class InternalActivityImpl method removeVersion.

/**
     * Removes the given version from the list of references
     * @param v the version
     * @throws RepositoryException if an error occurs
     */
public void removeVersion(InternalVersionImpl v) throws RepositoryException {
    List<InternalValue> versions = new LinkedList<InternalValue>();
    if (node.hasProperty(NameConstants.REP_VERSIONS)) {
        NodeId vId = v.getId();
        for (InternalValue ref : node.getPropertyValues(NameConstants.REP_VERSIONS)) {
            if (!vId.equals(ref.getNodeId())) {
                versions.add(ref);
            }
        }
    }
    node.setPropertyValues(NameConstants.REP_VERSIONS, PropertyType.REFERENCE, versions.toArray(new InternalValue[versions.size()]));
    node.store();
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) LinkedList(java.util.LinkedList)

Example 22 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class InternalActivityImpl method getChangeSet.

/**
     * {@inheritDoc}
     */
public VersionSet getChangeSet() throws RepositoryException {
    Map<NodeId, InternalVersion> changeset = new HashMap<NodeId, InternalVersion>();
    if (node.hasProperty(NameConstants.REP_VERSIONS)) {
        for (InternalValue ref : node.getPropertyValues(NameConstants.REP_VERSIONS)) {
            InternalVersion v = vMgr.getVersion(ref.getNodeId());
            changeset.put(v.getVersionHistory().getId(), v);
        }
    }
    return new VersionSet(changeset);
}
Also used : HashMap(java.util.HashMap) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue)

Example 23 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class InternalFrozenNodeImpl method checkin.

/**
     * Checks-in a <code>src</code> node. It creates a new child node of
     * <code>parent</code> with the given <code>name</code> and adds the
     * source nodes properties according to their OPV value to the
     * list of frozen properties. It creates frozen child nodes for each child
     * node of <code>src</code> according to its OPV value.
     *
     * @param parent destination parent
     * @param name new node name
     * @param src source node state
     * @param forceCopy if <code>true</code> the OPV is ignored and a COPY is performed
     * @return the nde node state
     * @throws RepositoryException if an error occurs
     * @throws ItemStateException if an error during reading the items occurs
     */
private static NodeStateEx checkin(NodeStateEx parent, Name name, NodeStateEx src, boolean forceCopy) throws RepositoryException, ItemStateException {
    // create new node
    NodeStateEx node = parent.addNode(name, NameConstants.NT_FROZENNODE, null, true);
    // initialize the internal properties
    node.setPropertyValue(NameConstants.JCR_FROZENUUID, InternalValue.create(src.getNodeId().toString()));
    node.setPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE, InternalValue.create(src.getState().getNodeTypeName()));
    if (src.hasProperty(NameConstants.JCR_MIXINTYPES)) {
        node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, src.getPropertyValues(NameConstants.JCR_MIXINTYPES));
    }
    // add the properties
    for (PropertyState prop : src.getProperties()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = src.getDefinition(prop).getOnParentVersion();
        }
        Name propName = prop.getName();
        if (opv == OnParentVersionAction.ABORT) {
            parent.reload();
            throw new VersionException("Checkin aborted due to OPV abort in " + propName);
        } else if (opv == OnParentVersionAction.VERSION || opv == OnParentVersionAction.COPY) {
            // ignore frozen properties
            if (!propName.equals(NameConstants.JCR_PRIMARYTYPE) && !propName.equals(NameConstants.JCR_MIXINTYPES) && !propName.equals(NameConstants.JCR_UUID) && // JCR-3635: should never occur in normal content...
            !propName.equals(NameConstants.JCR_FROZENPRIMARYTYPE) && !propName.equals(NameConstants.JCR_FROZENMIXINTYPES) && !propName.equals(NameConstants.JCR_FROZENUUID)) {
                node.copyFrom(prop);
            }
        }
    }
    // add the frozen children and histories
    boolean isFull = src.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE);
    for (NodeStateEx child : src.getChildNodes()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = child.getDefinition().getOnParentVersion();
        }
        if (opv == OnParentVersionAction.ABORT) {
            throw new VersionException("Checkin aborted due to OPV in " + child);
        } else if (opv == OnParentVersionAction.VERSION) {
            if (isFull && child.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                // create frozen versionable child
                NodeId histId = child.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
                NodeStateEx newChild = node.addNode(child.getName(), NameConstants.NT_VERSIONEDCHILD, null, false);
                newChild.setPropertyValue(NameConstants.JCR_CHILDVERSIONHISTORY, InternalValue.create(histId));
            } else {
                // else copy
                checkin(node, child.getName(), child, true);
            }
        } else if (opv == OnParentVersionAction.COPY) {
            checkin(node, child.getName(), child, true);
        }
    }
    return node;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 24 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class SharedItemStateManager method validateAdded.

/**
     * Checks the parents and children of all added node states in the changelog.
     *
     * @param changeLog
     *            The local changelog the should be validated
     * @throws ItemStateException
     *             If the hierarchy changes are inconsistent.
     */
private void validateAdded(ChangeLog changeLog) throws ItemStateException {
    // Check each added node
    for (ItemState state : changeLog.addedStates()) {
        if (state instanceof NodeState) {
            // Get the next added node
            NodeState addedNodeState = (NodeState) state;
            NodeId id = addedNodeState.getNodeId();
            // Check the parent
            NodeId parentId = addedNodeState.getParentId();
            if (changeLog.has(parentId)) {
                // Added or modified
                // the modified state will be check later on
                checkParent(changeLog, addedNodeState, parentId);
            } else {
                String message = "Node with id " + id + " has been added, but the parent node isn't part of the changelog " + parentId;
                log.error(message);
                throw new ItemStateException(message);
            }
            // Check the children
            for (ChildNodeEntry entry : addedNodeState.getChildNodeEntries()) {
                // Get the next child
                NodeId childId = entry.getId();
                if (changeLog.has(childId)) {
                    NodeState childState = (NodeState) changeLog.get(childId);
                    checkParent(changeLog, childState, id);
                // the child state will be check later on
                } else {
                    String message = "Node with id " + id + " has been added, but the child node isn't part of the changelog " + childId;
                    log.error(message);
                    throw new ItemStateException(message);
                }
            }
        }
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 25 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class SharedItemStateManager method validateDeleted.

/**
     * Checks the parents and children of all deleted node states in the changelog.
     *
     * @param changeLog
     *            The local changelog the should be validated
     * @throws ItemStateException
     *             If the hierarchy changes are inconsistent.
     */
private void validateDeleted(ChangeLog changeLog) throws ItemStateException {
    // Check each deleted nodestate
    for (ItemState removedState : changeLog.deletedStates()) {
        if (removedState instanceof NodeState) {
            // Get the next state
            NodeState removedNodeState = (NodeState) removedState;
            NodeId id = removedNodeState.getNodeId();
            // Get and check the corresponding overlayed state
            NodeState overlayedState = (NodeState) removedState.getOverlayedState();
            if (overlayedState == null) {
                String message = "Unable to load persistent state for removed node " + id;
                overlayedState = (NodeState) SharedItemStateManager.this.getItemState(id);
                if (overlayedState == null) {
                    log.error(message);
                    throw new ItemStateException(message);
                }
            }
            // Check whether an version of this node has been restored
            boolean addedAndRemoved = changeLog.has(removedNodeState.getId());
            if (!addedAndRemoved) {
                // Check the old parent; it should be either also deleted
                // or at least modified to reflect the removal of a child
                NodeId oldParentId = overlayedState.getParentId();
                if (!changeLog.deleted(oldParentId) && !changeLog.isModified(oldParentId)) {
                    String message = "Node with id " + id + " has been removed, but the parent node isn't part of the changelog " + oldParentId;
                    log.error(message);
                    throw new ItemStateException(message);
                }
                // Get the original list of child ids
                for (ChildNodeEntry entry : overlayedState.getChildNodeEntries()) {
                    // Check the next child; it should be either also deleted
                    // or at least modified to reflect being moved elsewhere
                    NodeId childId = entry.getId();
                    if (!changeLog.deleted(childId) && !changeLog.isModified(childId)) {
                        String message = "Node with id " + id + " has been removed, but the old child node isn't part of the changelog " + childId;
                        log.error(message);
                        throw new ItemStateException(message);
                    }
                }
            }
        }
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)203 RepositoryException (javax.jcr.RepositoryException)68 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)37 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 NodeImpl (org.apache.jackrabbit.core.NodeImpl)20 InternalValue (org.apache.jackrabbit.core.value.InternalValue)20 ArrayList (java.util.ArrayList)19 PropertyId (org.apache.jackrabbit.core.id.PropertyId)16 HashSet (java.util.HashSet)15 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)14 PropertyState (org.apache.jackrabbit.core.state.PropertyState)14 Session (javax.jcr.Session)13 HashMap (java.util.HashMap)12 ItemExistsException (javax.jcr.ItemExistsException)12