Search in sources :

Example 51 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class VersionManagerImplBase method checkoutCheckin.

/**
     * Performs a checkin or checkout operation. if <code>checkin</code> is
     * <code>true</code> the node is checked in. if <code>checkout</code> is
     * <code>true</code> the node is checked out. if both flags are <code>true</code>
     * the checkin is performed prior to the checkout and the operation is
     * equivalent to a checkpoint operation.
     *
     * @param state node state
     * @param checkin if <code>true</code> the node is checked in.
     * @param checkout if <code>true</code> the node is checked out.
     * @param created create time of the new version (if any),
     *                or <code>null</code> for the current time
     * @return the node id of the base version or <code>null</code> for a pure
     *         checkout.
     * @throws RepositoryException if an error occurs
     */
protected NodeId checkoutCheckin(NodeStateEx state, boolean checkin, boolean checkout, Calendar created) throws RepositoryException {
    assert (checkin || checkout);
    // check if versionable
    boolean isFull = checkVersionable(state);
    // check flags
    if (isCheckedOut(state)) {
        if (checkout && !checkin) {
            // pure checkout
            String msg = safeGetJCRPath(state) + ": Node is already checked-out. ignoring.";
            log.debug(msg);
            return null;
        }
    } else {
        if (!checkout) {
            // pure checkin
            String msg = safeGetJCRPath(state) + ": Node is already checked-in. ignoring.";
            log.debug(msg);
            if (isFull) {
                return getBaseVersionId(state);
            } else {
                // get base version from version history
                return vMgr.getHeadVersionOfNode(state.getNodeId()).getId();
            }
        }
        checkin = false;
    }
    NodeId baseId = isFull && checkout ? vMgr.canCheckout(state, currentActivity) : null;
    // perform operation
    WriteOperation ops = startWriteOperation();
    try {
        // the 2 cases could be consolidated but is clearer this way
        if (checkin) {
            // check for configuration
            if (state.getEffectiveNodeType().includesNodeType(NameConstants.NT_CONFIGURATION)) {
                // collect the base versions and the the rep:versions property of the configuration
                Set<NodeId> baseVersions = collectBaseVersions(state);
                InternalValue[] vs = new InternalValue[baseVersions.size()];
                int i = 0;
                for (NodeId id : baseVersions) {
                    vs[i++] = InternalValue.create(id);
                }
                state.setPropertyValues(NameConstants.REP_VERSIONS, PropertyType.REFERENCE, vs);
                state.store();
            }
            InternalVersion v = vMgr.checkin(session, state, created);
            baseId = v.getId();
            if (isFull) {
                state.setPropertyValue(NameConstants.JCR_BASEVERSION, InternalValue.create(baseId));
                state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, InternalValue.EMPTY_ARRAY);
                state.removeProperty(NameConstants.JCR_ACTIVITY);
            }
        }
        if (checkout) {
            if (isFull) {
                state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, new InternalValue[] { InternalValue.create(baseId) });
                if (currentActivity != null) {
                    state.setPropertyValue(NameConstants.JCR_ACTIVITY, InternalValue.create(currentActivity));
                }
            }
        }
        state.setPropertyValue(NameConstants.JCR_ISCHECKEDOUT, InternalValue.create(checkout));
        state.store();
        ops.save();
        return baseId;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 52 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class NodeStateEx method moveFrom.

/**
     * Moves the source node to this node using the given name.
     * @param src shareable source node
     * @param name name of new node
     * @param createShare if <code>true</code> a share is created instead.
     * @return child node
     * @throws RepositoryException if an error occurs
     */
public NodeStateEx moveFrom(NodeStateEx src, Name name, boolean createShare) throws RepositoryException {
    if (name == null) {
        name = src.getName();
    }
    EffectiveNodeType ent = getEffectiveNodeType();
    // (4) check for name collisions
    QNodeDefinition def;
    try {
        def = ent.getApplicableChildNodeDef(name, nodeState.getNodeTypeName(), ntReg);
    } catch (RepositoryException re) {
        String msg = "no definition found in parent node's node type for new node";
        throw new ConstraintViolationException(msg, re);
    }
    ChildNodeEntry cne = nodeState.getChildNodeEntry(name, 1);
    if (cne != null) {
        // check same-name sibling setting of new node
        if (!def.allowsSameNameSiblings()) {
            throw new ItemExistsException(getNodeId() + "/" + name);
        }
        NodeState existingChild;
        try {
            // check same-name sibling setting of existing node
            existingChild = (NodeState) stateMgr.getItemState(cne.getId());
        } catch (ItemStateException e) {
            throw new RepositoryException(e);
        }
        QNodeDefinition existingChildDef = ent.getApplicableChildNodeDef(cne.getName(), existingChild.getNodeTypeName(), ntReg);
        if (!existingChildDef.allowsSameNameSiblings()) {
            throw new ItemExistsException(existingChild.toString());
        }
    } else {
        // check if 'add' is allowed
        if (getDefinition().isProtected()) {
            String msg = "not allowed to modify a protected node";
            throw new ConstraintViolationException(msg);
        }
    }
    if (createShare) {
        // (5) do clone operation
        NodeId parentId = getNodeId();
        src.addShareParent(parentId);
        // attach to this parent
        nodeState.addChildNodeEntry(name, src.getNodeId());
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return new NodeStateEx(stateMgr, ntReg, src.getState(), name);
    } else {
        // detach from parent
        NodeStateEx parent = getNode(src.getParentId());
        parent.nodeState.removeChildNodeEntry(src.getNodeId());
        if (parent.nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            parent.nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        // attach to this parent
        nodeState.addChildNodeEntry(name, src.getNodeId());
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        NodeState srcState = src.getState();
        srcState.setParentId(getNodeId());
        if (srcState.getStatus() == ItemState.STATUS_EXISTING) {
            srcState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return new NodeStateEx(stateMgr, ntReg, srcState, name);
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) NodeState(org.apache.jackrabbit.core.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 53 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class NodeStateEx method setPropertyValues.

/**
     * Sets the property values
     *
     * @param name name of the property
     * @param type type of the values
     * @param values values to set
     * @param multiple <code>true</code>for MV properties
     * @return the modified property state
     * @throws RepositoryException if an error occurs
     */
public PropertyState setPropertyValues(Name name, int type, InternalValue[] values, boolean multiple) throws RepositoryException {
    PropertyId propId = new PropertyId(nodeState.getNodeId(), name);
    if (stateMgr.hasItemState(propId)) {
        try {
            PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
            if (propState.getStatus() == ItemState.STATUS_EXISTING) {
                propState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            }
            // although this is not quite correct, we mark node as modified as well
            if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
                nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            }
            propState.setType(type);
            propState.setMultiValued(multiple);
            propState.setValues(values);
            return propState;
        } catch (ItemStateException e) {
            throw new RepositoryException("Unable to create property: " + e.toString());
        }
    } else {
        PropertyState propState = stateMgr.createNew(name, nodeState.getNodeId());
        propState.setType(type);
        propState.setMultiValued(multiple);
        propState.setValues(values);
        // need to store node state
        nodeState.addPropertyName(name);
        if (nodeState.getStatus() == ItemState.STATUS_EXISTING) {
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
        }
        return propState;
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 54 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class InternalVersionManagerBase method internalCreateVersionHistory.

/**
     * Creates a new Version History.
     *
     * @param node the node for which the version history is to be initialized
     * @param copiedFrom node id for the jcr:copiedFrom parameter
     * @return the identifiers of the newly created version history and root version
     * @throws RepositoryException if an error occurs
     */
NodeStateEx internalCreateVersionHistory(NodeState node, NodeId copiedFrom) throws RepositoryException {
    WriteOperation operation = startWriteOperation();
    try {
        // create deep path
        String uuid = node.getNodeId().toString();
        NodeStateEx parent = getParentNode(getHistoryRoot(), uuid, NameConstants.REP_VERSIONSTORAGE);
        Name name = getName(uuid);
        if (parent.hasNode(name)) {
            // already exists
            return null;
        }
        // create new history node in the persistent state
        NodeStateEx history = InternalVersionHistoryImpl.create(this, parent, name, node, copiedFrom);
        // end update
        operation.save();
        log.debug("Created new version history " + history.getNodeId() + " for " + node + ".");
        return history;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        operation.close();
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 55 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class InternalVersionManagerBase method createInternalVersionItem.

/**
     * Creates an {@link InternalVersionItem} based on the {@link NodeState}
     * identified by <code>id</code>.
     *
     * @param id    the node id of the version item.
     * @return the version item or <code>null</code> if there is no node state
     *         with the given <code>id</code>.
     * @throws RepositoryException if an error occurs while reading from the
     *                             version storage.
     */
protected InternalVersionItem createInternalVersionItem(NodeId id) throws RepositoryException {
    try {
        if (stateMgr.hasItemState(id)) {
            NodeState state = (NodeState) stateMgr.getItemState(id);
            NodeStateEx pNode = new NodeStateEx(stateMgr, ntReg, state, null);
            NodeId parentId = pNode.getParentId();
            InternalVersionItem parent = getItem(parentId);
            Name ntName = state.getNodeTypeName();
            if (ntName.equals(NameConstants.NT_FROZENNODE)) {
                return new InternalFrozenNodeImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSIONEDCHILD)) {
                return new InternalFrozenVHImpl(this, pNode, parent);
            } else if (ntName.equals(NameConstants.NT_VERSION)) {
                return ((InternalVersionHistory) parent).getVersion(id);
            } else if (ntName.equals(NameConstants.NT_VERSIONHISTORY)) {
                return new InternalVersionHistoryImpl(this, pNode);
            } else if (ntName.equals(NameConstants.NT_ACTIVITY)) {
                return new InternalActivityImpl(this, pNode);
            } else {
                return null;
            }
        } else {
            return null;
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)141 RepositoryException (javax.jcr.RepositoryException)87 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)86 NodeId (org.apache.jackrabbit.core.id.NodeId)44 NodeState (org.apache.jackrabbit.core.state.NodeState)39 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)31 IOException (java.io.IOException)28 InvalidItemStateException (javax.jcr.InvalidItemStateException)27 PropertyState (org.apache.jackrabbit.core.state.PropertyState)24 SQLException (java.sql.SQLException)23 PropertyId (org.apache.jackrabbit.core.id.PropertyId)22 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)19 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)19 Name (org.apache.jackrabbit.spi.Name)17 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 InternalValue (org.apache.jackrabbit.core.value.InternalValue)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)13 InputStream (java.io.InputStream)12