Search in sources :

Example 6 with ChildInfo

use of org.apache.jackrabbit.spi.ChildInfo in project jackrabbit by apache.

the class BatchTest method testReorder1.

public void testReorder1() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Batch b = rs.createBatch(si, nid);
    b.addNode(nid, resolver.getQName("2"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("3"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("1"), NameConstants.NT_UNSTRUCTURED, null);
    rs.submit(b);
    b = rs.createBatch(si, nid);
    b.reorderNodes(nid, getNodeId(testPath + "/1"), getNodeId(testPath + "/2"));
    rs.submit(b);
    Iterator<ChildInfo> it = rs.getChildInfos(si, nid);
    int i = 1;
    while (it.hasNext()) {
        ChildInfo ci = it.next();
        assertEquals(i, Integer.parseInt(ci.getName().getLocalName()));
        i++;
    }
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 7 with ChildInfo

use of org.apache.jackrabbit.spi.ChildInfo in project jackrabbit by apache.

the class BatchTest method testAddNode.

public void testAddNode() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Batch b = rs.createBatch(si, nid);
    b.addNode(nid, resolver.getQName("aNode"), NameConstants.NT_UNSTRUCTURED, null);
    b.addProperty(nid, resolver.getQName("aString"), rs.getQValueFactory().create("ba", PropertyType.STRING));
    b.addProperty(nid, resolver.getQName("aName"), new QValue[] { rs.getQValueFactory().create(NameConstants.JCR_ENCODING), rs.getQValueFactory().create(NameConstants.JCR_DATA) });
    b.addProperty(nid, resolver.getQName("aBinary"), rs.getQValueFactory().create(new byte[] { 'a', 'b', 'c' }));
    rs.submit(b);
    NodeId id = rs.getIdFactory().createNodeId(nid, resolver.getQPath("aNode"));
    Iterator<? extends ItemInfo> it = rs.getItemInfos(si, id);
    while (it.hasNext()) {
        ItemInfo info = it.next();
        if (info.denotesNode()) {
            NodeInfo nInfo = (NodeInfo) info;
            assertEquals(NameConstants.NT_UNSTRUCTURED, nInfo.getNodetype());
            Iterator<ChildInfo> childIt = nInfo.getChildInfos();
            assertTrue(childIt == null || !childIt.hasNext());
            assertEquals(id, nInfo.getId());
        }
    }
    b = rs.createBatch(si, nid);
    b.remove(id);
    rs.submit(b);
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 8 with ChildInfo

use of org.apache.jackrabbit.spi.ChildInfo in project jackrabbit by apache.

the class ChildNodeEntriesImpl method update.

/**
     * Update the child node entries according to the child-infos obtained
     * from the persistence layer.
     * NOTE: the status of the entries already present is not respected. Thus
     * new or removed entries are not touched in order not to modify the
     * transient status of the parent. Operations that affect the set or order
     * of child entries (AddNode, Move, Reorder) currently assert the
     * completeness of the ChildNodeEntries, therefore avoiding an update
     * resulting in inconsistent entries.
     *
     * @param childNodeInfos
     * @see HierarchyEntry#reload(boolean) that ignores items with
     * pending changes.
     * @see org.apache.jackrabbit.jcr2spi.operation.AddNode
     * @see org.apache.jackrabbit.jcr2spi.operation.Move
     * @see org.apache.jackrabbit.jcr2spi.operation.ReorderNodes
     */
synchronized void update(Iterator<ChildInfo> childNodeInfos) {
    // insert missing entries and reorder all if necessary.
    LinkedEntries.LinkNode prevLN = null;
    while (childNodeInfos.hasNext()) {
        ChildInfo ci = childNodeInfos.next();
        LinkedEntries.LinkNode ln = entriesByName.getLinkNode(ci.getName(), ci.getIndex(), ci.getUniqueID());
        if (ln == null) {
            // add missing at the correct position.
            NodeEntry entry = factory.createNodeEntry(parent, ci.getName(), ci.getUniqueID());
            ln = internalAddAfter(entry, ci.getIndex(), prevLN);
        } else if (prevLN != null) {
            // assert correct order of existing
            if (prevLN != ln) {
                reorderAfter(ln, prevLN);
            } else {
                // there was an existing entry but it's the same as the one
                // created/retrieved before. getting here indicates that
                // the SPI implementation provided invalid childNodeInfos.
                log.error("ChildInfo iterator contains multiple entries with the same name|index or uniqueID -> ignore ChildNodeInfo.");
            }
        }
        prevLN = ln;
    }
    // finally reset the status
    complete = true;
}
Also used : ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Example 9 with ChildInfo

use of org.apache.jackrabbit.spi.ChildInfo in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createNodeState.

/**
     * Create the node state with the information from <code>info</code>.
     *
     * @param info the <code>NodeInfo</code> to use to create the <code>NodeState</code>.
     * @param entry  the hierarchy entry for of this state
     * @return the new <code>NodeState</code>.
     * @throws ItemNotFoundException
     * @throws RepositoryException
     */
private NodeState createNodeState(NodeInfo info, NodeEntry entry) throws ItemNotFoundException, RepositoryException {
    // Make sure the entry has the correct ItemId
    // this may not be the case, if the hierarchy has not been completely
    // resolved yet -> if uniqueID is present, set it on this entry or on
    // the appropriate parent entry
    String uniqueID = info.getId().getUniqueID();
    Path path = info.getId().getPath();
    if (path == null) {
        entry.setUniqueID(uniqueID);
    } else if (uniqueID != null) {
        // uniqueID that applies to a parent NodeEntry -> get parentEntry
        NodeEntry parent = getAncestor(entry, path.getLength());
        parent.setUniqueID(uniqueID);
    }
    int previousStatus = entry.getStatus();
    if (Status.isTransient(previousStatus) || Status.isStale(previousStatus)) {
        log.debug("Node has pending changes; omit resetting the state.");
        return entry.getNodeState();
    }
    // update NodeEntry from the information present in the NodeInfo (prop entries)
    List<Name> propNames = new ArrayList<Name>();
    for (Iterator<PropertyId> it = info.getPropertyIds(); it.hasNext(); ) {
        PropertyId pId = it.next();
        Name propertyName = pId.getName();
        propNames.add(propertyName);
    }
    try {
        entry.setPropertyEntries(propNames);
    } catch (ItemExistsException e) {
        // should not get here
        log.error("Internal error", e);
    }
    // unless the child-info are omitted by the SPI impl -> make sure
    // the child entries the node entry are initialized or updated.
    Iterator<ChildInfo> childInfos = info.getChildInfos();
    if (childInfos != null) {
        entry.setNodeEntries(childInfos);
    }
    // now build or update the nodestate itself
    NodeState tmp = new NodeState(entry, info, this, definitionProvider);
    entry.setItemState(tmp);
    NodeState nState = entry.getNodeState();
    if (previousStatus == Status._UNDEFINED_) {
        // tmp state was used as resolution for the given entry i.e. the
        // entry was not available before. otherwise the 2 states were
        // merged. see HierarchyEntryImpl#setItemState
        notifyCreated(nState);
    } else {
        notifyUpdated(nState, previousStatus);
    }
    return nState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) ArrayList(java.util.ArrayList) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ItemExistsException(javax.jcr.ItemExistsException)

Example 10 with ChildInfo

use of org.apache.jackrabbit.spi.ChildInfo in project jackrabbit by apache.

the class BatchTest method testReorder.

public void testReorder() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Batch b = rs.createBatch(si, nid);
    b.addNode(nid, resolver.getQName("1"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("3"), NameConstants.NT_UNSTRUCTURED, null);
    b.addNode(nid, resolver.getQName("2"), NameConstants.NT_UNSTRUCTURED, null);
    rs.submit(b);
    b = rs.createBatch(si, nid);
    b.reorderNodes(nid, getNodeId(testPath + "/3"), null);
    rs.submit(b);
    Iterator<ChildInfo> it = rs.getChildInfos(si, nid);
    int i = 1;
    while (it.hasNext()) {
        ChildInfo ci = it.next();
        assertEquals(i, Integer.parseInt(ci.getName().getLocalName()));
        i++;
    }
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) ChildInfo(org.apache.jackrabbit.spi.ChildInfo)

Aggregations

ChildInfo (org.apache.jackrabbit.spi.ChildInfo)11 NodeId (org.apache.jackrabbit.spi.NodeId)5 ArrayList (java.util.ArrayList)4 RepositoryException (javax.jcr.RepositoryException)3 Batch (org.apache.jackrabbit.spi.Batch)3 IOException (java.io.IOException)2 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)2 PropertyId (org.apache.jackrabbit.spi.PropertyId)2 Serializable (java.io.Serializable)1 ItemExistsException (javax.jcr.ItemExistsException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 NodeIterator (javax.jcr.NodeIterator)1 HttpResponse (org.apache.http.HttpResponse)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)1 Name (org.apache.jackrabbit.spi.Name)1 Path (org.apache.jackrabbit.spi.Path)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1 DavException (org.apache.jackrabbit.webdav.DavException)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1