Search in sources :

Example 6 with Operation

use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.

the class PropertyImpl method setInternalValues.

/**
     *
     * @param qValues
     * @param valueType
     * @throws ConstraintViolationException
     * @throws RepositoryException
     */
private void setInternalValues(QValue[] qValues, int valueType) throws ConstraintViolationException, RepositoryException {
    // check for null value
    if (qValues == null) {
        // setting a property to null removes it automatically
        remove();
        return;
    }
    // modify the state of this property
    Operation op = SetPropertyValue.create(getPropertyState(), qValues, valueType);
    session.getSessionItemStateManager().execute(op);
}
Also used : Operation(org.apache.jackrabbit.jcr2spi.operation.Operation)

Example 7 with Operation

use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.

the class NodeImpl method createProperty.

/**
     *
     * @param qName
     * @param type
     * @param def
     * @param qvs
     * @return
     * @throws PathNotFoundException
     * @throws ConstraintViolationException
     * @throws RepositoryException
     */
private Property createProperty(Name qName, int type, QPropertyDefinition def, QValue[] qvs) throws ConstraintViolationException, RepositoryException {
    Operation op = AddProperty.create(getNodeState(), qName, type, def, qvs);
    session.getSessionItemStateManager().execute(op);
    return getProperty(qName);
}
Also used : Operation(org.apache.jackrabbit.jcr2spi.operation.Operation)

Example 8 with Operation

use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.

the class WorkspaceImpl method move.

/**
     * @see javax.jcr.Workspace#move(String, String)
     */
public void move(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException {
    session.checkSupportedOption(Repository.LEVEL_2_SUPPORTED);
    session.checkIsAlive();
    Path srcPath = session.getQPath(srcAbsPath);
    Path destPath = session.getQPath(destAbsPath);
    Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getPathResolver(), false);
    getUpdatableItemStateManager().execute(op);
}
Also used : Path(org.apache.jackrabbit.spi.Path) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation)

Example 9 with Operation

use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.

the class SessionImporter method resolveUUIDConflict.

//----------------------------------------------------< Private methods >---
/**
     * @param parent
     * @param conflicting
     * @param nodeInfo
     * @return
     * @throws RepositoryException
     */
NodeState resolveUUIDConflict(NodeState parent, NodeEntry conflicting, NodeInfo nodeInfo) throws ItemExistsException, RepositoryException {
    NodeState nodeState;
    switch(uuidBehavior) {
        case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
            String originalUUID = nodeInfo.getUUID();
            String newUUID = UUID.randomUUID().toString();
            // reset id on nodeInfo to force creation with new uuid:
            nodeInfo.setUUID(newUUID);
            nodeState = importNode(nodeInfo, parent);
            if (nodeState != null) {
                // remember uuid mapping
                refTracker.mappedUUIDs(originalUUID, newUUID);
            }
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
            String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
            // make sure conflicting node is not importTarget or an ancestor thereof
            Path p0 = importTarget.getPath();
            Path p1 = conflicting.getPath();
            if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                msg = "cannot remove ancestor node";
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
            // do remove conflicting (recursive) including validation check
            try {
                Operation op = Remove.create(conflicting.getNodeState());
                stateMgr.execute(op);
            } catch (ItemNotFoundException e) {
            // conflicting does not exist any more. no need for a removal
            }
            // create new with given uuid:
            nodeState = importNode(nodeInfo, parent);
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
            if (conflicting.getNodeState().isRoot()) {
                msg = "Root node cannot be replaced";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
            // 'replace' current parent with parent of conflicting
            parent = conflicting.getParent().getNodeState();
            // do remove conflicting (recursive), including validation checks
            Operation op = Remove.create(conflicting.getNodeState());
            stateMgr.execute(op);
            // create new with given uuid at same location as conflicting
            nodeState = importNode(nodeInfo, parent);
            break;
        default:
            msg = "Unknown uuidBehavior: " + uuidBehavior;
            log.debug(msg);
            throw new RepositoryException(msg);
    }
    return nodeState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 10 with Operation

use of org.apache.jackrabbit.jcr2spi.operation.Operation in project jackrabbit by apache.

the class TransientItemStateManager method getChangeLog.

/**
     * Create the change log for the tree starting at <code>target</code>. This
     * includes a  check if the ChangeLog to be created is totally 'self-contained'
     * and independent; items within the scope of this update operation (i.e.
     * below the target) must not have dependencies outside of this tree (e.g.
     * moving a node requires that the target node including both old and new
     * parents are saved).
     *
     * @param target
     * @param throwOnStale Throws InvalidItemStateException if either the given
     * <code>ItemState</code> or any of its descendants is stale and the flag is true.
     * @return
     * @throws InvalidItemStateException if a stale <code>ItemState</code> is
     * encountered while traversing the state hierarchy. The <code>changeLog</code>
     * might have been populated with some transient item states. A client should
     * therefore not reuse the <code>changeLog</code> if such an exception is thrown.
     * @throws RepositoryException if <code>state</code> is a new item state.
     */
ChangeLog getChangeLog(ItemState target, boolean throwOnStale) throws InvalidItemStateException, ConstraintViolationException, RepositoryException {
    // fail-fast test: check status of this item's state
    if (target.getStatus() == Status.NEW) {
        String msg = "Cannot save/revert an item with status NEW (" + target + ").";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    if (throwOnStale && Status.isStale(target.getStatus())) {
        String msg = "Attempt to save/revert an item, that has been externally modified (" + target + ").";
        log.debug(msg);
        throw new InvalidItemStateException(msg);
    }
    Set<Operation> ops = new LinkedHashSet<Operation>();
    Set<ItemState> affectedStates = new LinkedHashSet<ItemState>();
    HierarchyEntry he = target.getHierarchyEntry();
    if (he.getParent() == null) {
        // simplicity. collecting ops, states can be omitted.
        if (throwOnStale && !staleStates.isEmpty()) {
            String msg = "Cannot save changes: States has been modified externally.";
            log.debug(msg);
            throw new InvalidItemStateException(msg);
        } else {
            affectedStates.addAll(staleStates);
        }
        ops.addAll(operations);
        affectedStates.addAll(addedStates);
        affectedStates.addAll(modifiedStates);
        affectedStates.addAll(removedStates);
    } else {
        // - check if there is a stale state in the scope (save only)
        if (throwOnStale) {
            for (ItemState state : staleStates) {
                if (containedInTree(target, state)) {
                    String msg = "Cannot save changes: States has been modified externally.";
                    log.debug(msg);
                    throw new InvalidItemStateException(msg);
                }
            }
        }
        // - collect all affected states within the scope of save/undo
        Iterator[] its = new Iterator[] { addedStates.iterator(), removedStates.iterator(), modifiedStates.iterator() };
        IteratorChain chain = new IteratorChain(its);
        if (!throwOnStale) {
            chain.addIterator(staleStates.iterator());
        }
        while (chain.hasNext()) {
            ItemState state = (ItemState) chain.next();
            if (containedInTree(target, state)) {
                affectedStates.add(state);
            }
        }
        //   changelog.
        for (Operation op : operations) {
            Collection<ItemState> opStates = op.getAffectedItemStates();
            for (ItemState state : opStates) {
                if (affectedStates.contains(state)) {
                    // operation needs to be included
                    if (!affectedStates.containsAll(opStates)) {
                        // incomplete changelog: need to save a parent as well
                        String msg = "ChangeLog is not self contained.";
                        throw new ConstraintViolationException(msg);
                    }
                    // no violation: add operation an stop iteration over
                    // all affected states present in the operation.
                    ops.add(op);
                    break;
                }
            }
        }
    }
    ChangeLog cl = new ChangeLog(target, ops, affectedStates);
    return cl;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidItemStateException(javax.jcr.InvalidItemStateException) RepositoryException(javax.jcr.RepositoryException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry) IteratorChain(org.apache.commons.collections.iterators.IteratorChain) Iterator(java.util.Iterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Aggregations

Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)32 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 Path (org.apache.jackrabbit.spi.Path)6 Name (org.apache.jackrabbit.spi.Name)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 RepositoryException (javax.jcr.RepositoryException)4 AddNode (org.apache.jackrabbit.jcr2spi.operation.AddNode)3 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)3 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)3 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)3 ItemExistsException (javax.jcr.ItemExistsException)2 HierarchyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)2 EffectiveNodeType (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 Node (javax.jcr.Node)1