Search in sources :

Example 81 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeState method fromString.

public static DocumentNodeState fromString(DocumentNodeStore store, String s) {
    JsopTokenizer json = new JsopTokenizer(s);
    String path = null;
    RevisionVector rootRev = null;
    RevisionVector lastRev = null;
    boolean hasChildren = false;
    HashMap<String, String> map = new HashMap<String, String>();
    while (true) {
        String k = json.readString();
        json.read(':');
        if ("path".equals(k)) {
            path = json.readString();
        } else if ("rev".equals(k)) {
            rootRev = RevisionVector.fromString(json.readString());
        } else if ("lastRev".equals(k)) {
            lastRev = RevisionVector.fromString(json.readString());
        } else if ("hasChildren".equals(k)) {
            hasChildren = json.read() == JsopReader.TRUE;
        } else if ("prop".equals(k)) {
            json.read('{');
            while (true) {
                if (json.matches('}')) {
                    break;
                }
                k = json.readString();
                json.read(':');
                String v = json.readString();
                map.put(k, v);
                json.matches(',');
            }
        }
        if (json.matches(JsopReader.END)) {
            break;
        }
        json.read(',');
    }
    List<PropertyState> props = Lists.newArrayListWithCapacity(map.size());
    for (Entry<String, String> e : map.entrySet()) {
        String value = e.getValue();
        if (value != null) {
            props.add(store.createPropertyState(e.getKey(), value));
        }
    }
    return new DocumentNodeState(store, path, rootRev, props, hasChildren, lastRev);
}
Also used : HashMap(java.util.HashMap) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 82 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class DocumentNodeStore method getBinarySize.

/**
     * Returns the binary size of a property value represented as a JSON or
     * {@code -1} if the property is not of type binary.
     *
     * @param json the property value.
     * @return the size of the referenced binary value(s); otherwise {@code -1}.
     */
private long getBinarySize(@Nullable String json) {
    if (json == null) {
        return -1;
    }
    PropertyState p = new DocumentPropertyState(DocumentNodeStore.this, "p", json);
    if (p.getType().tag() != PropertyType.BINARY) {
        return -1;
    }
    long size = 0;
    if (p.isArray()) {
        for (int i = 0; i < p.count(); i++) {
            size += p.size(i);
        }
    } else {
        size = p.size();
    }
    return size;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 83 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class MergingNodeStateDiff method resolveConflict.

//------------------------------------------------------------< private >---
private void resolveConflict(ConflictType conflictType, NodeState conflictInfo) {
    PropertyConflictHandler propertyConflictHandler = propertyConflictHandlers.get(conflictType);
    if (propertyConflictHandler != null) {
        for (PropertyState ours : conflictInfo.getProperties()) {
            PropertyState theirs = parent.getProperty(ours.getName());
            Resolution resolution = propertyConflictHandler.resolve(ours, theirs);
            applyResolution(resolution, conflictType, ours);
        }
    } else {
        NodeConflictHandler nodeConflictHandler = nodeConflictHandlers.get(conflictType);
        if (nodeConflictHandler != null) {
            for (ChildNodeEntry oursCNE : conflictInfo.getChildNodeEntries()) {
                String name = oursCNE.getName();
                NodeState ours = oursCNE.getNodeState();
                NodeState theirs = parent.getChildNode(name);
                Resolution resolution = nodeConflictHandler.resolve(name, ours, theirs);
                applyResolution(resolution, conflictType, name, ours);
                if (LOG.isDebugEnabled()) {
                    String diff = JsopDiff.diffToJsop(ours, theirs);
                    LOG.debug("{} resolved conflict of type {} with resolution {} on node {}, conflict trace {}", nodeConflictHandler, conflictType, resolution, name, diff);
                }
            }
        } else {
            LOG.warn("Ignoring unknown conflict '" + conflictType + '\'');
        }
    }
    NodeBuilder conflictMarker = getConflictMarker(conflictType);
    if (conflictMarker != null) {
        assert conflictMarker.getChildNodeCount(1) == 0;
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Resolution(org.apache.jackrabbit.oak.spi.commit.PartialConflictHandler.Resolution)

Example 84 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class MergingNodeStateDiff method removeChild.

private static void removeChild(NodeBuilder target, String name) {
    target.getChildNode(name).remove();
    PropertyState childOrder = target.getProperty(TreeConstants.OAK_CHILD_ORDER);
    if (childOrder != null) {
        PropertyBuilder<String> builder = PropertyBuilder.copy(NAME, childOrder);
        builder.removeValue(name);
        target.setProperty(builder.getPropertyState());
    }
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 85 with PropertyState

use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testModifyCache.

@Test
public void testModifyCache() throws Exception {
    List<PropertyState> props = new ArrayList();
    props.add(PropertyStates.createProperty(CacheConstants.REP_EXPIRATION, 25));
    props.add(PropertyStates.createProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES, EveryonePrincipal.NAME));
    props.add(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME));
    props.add(PropertyStates.createProperty("residualProp", "anyvalue"));
    Tree cache = getCache(getTestUser());
    for (PropertyState prop : props) {
        try {
            cache.setProperty(prop);
            root.commit(CacheValidatorProvider.asCommitAttributes());
            fail("Modifying rep:cache node below a user or group must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9