Search in sources :

Example 91 with PropertyState

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

the class DebugTars method filterNodeStates.

private void filterNodeStates(Set<UUID> uuids, List<String> paths, SegmentNodeState state, String path) {
    Set<String> localPaths = newTreeSet();
    for (PropertyState ps : state.getProperties()) {
        if (ps instanceof SegmentPropertyState) {
            SegmentPropertyState sps = (SegmentPropertyState) ps;
            RecordId recordId = sps.getRecordId();
            UUID id = recordId.getSegmentId().asUUID();
            if (uuids.contains(id)) {
                if (ps.getType().tag() == PropertyType.STRING) {
                    String val = "";
                    if (ps.count() > 0) {
                        // only shows the first value, do we need more?
                        val = displayString(ps.getValue(Type.STRING, 0));
                    }
                    localPaths.add(getLocalPath(path, ps, val, recordId));
                } else {
                    localPaths.add(getLocalPath(path, ps, recordId));
                }
            }
            if (ps.getType().tag() == PropertyType.BINARY) {
                // look for extra segment references
                for (int i = 0; i < ps.count(); i++) {
                    Blob b = ps.getValue(Type.BINARY, i);
                    for (SegmentId sbid : SegmentBlob.getBulkSegmentIds(b)) {
                        UUID bid = sbid.asUUID();
                        if (!bid.equals(id) && uuids.contains(bid)) {
                            localPaths.add(getLocalPath(path, ps, recordId));
                        }
                    }
                }
            }
        }
    }
    RecordId stateId = state.getRecordId();
    if (uuids.contains(stateId.getSegmentId().asUUID())) {
        localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
    }
    RecordId templateId = getTemplateId(state);
    if (uuids.contains(templateId.getSegmentId().asUUID())) {
        localPaths.add(path + "[Template@" + templateId + "]");
    }
    paths.addAll(localPaths);
    for (ChildNodeEntry ce : state.getChildNodeEntries()) {
        NodeState c = ce.getNodeState();
        if (c instanceof SegmentNodeState) {
            filterNodeStates(uuids, paths, (SegmentNodeState) c, path + ce.getName() + "/");
        }
    }
}
Also used : SegmentBlob(org.apache.jackrabbit.oak.segment.SegmentBlob) Blob(org.apache.jackrabbit.oak.api.Blob) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) SegmentId(org.apache.jackrabbit.oak.segment.SegmentId) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) RecordId(org.apache.jackrabbit.oak.segment.RecordId) UUID(java.util.UUID) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) SegmentPropertyState(org.apache.jackrabbit.oak.segment.SegmentPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 92 with PropertyState

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

the class OakSolrNodeStateConfiguration method getStringValuesFor.

private Iterable<String> getStringValuesFor(String propertyName) {
    Iterable<String> values = null;
    PropertyState property = definition.getProperty(propertyName);
    if (property != null && property.isArray()) {
        values = property.getValue(Type.STRINGS);
    }
    return values;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 93 with PropertyState

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

the class OakSolrNodeStateConfiguration method getIntValueFor.

private int getIntValueFor(String propertyName, int defaultValue) {
    long value = defaultValue;
    PropertyState property = definition.getProperty(propertyName);
    if (property != null) {
        value = property.getValue(Type.LONG);
    }
    return (int) value;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 94 with PropertyState

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

the class OakSolrNodeStateConfiguration method getStringValueFor.

private String getStringValueFor(String propertyName, String defaultValue) {
    String value = defaultValue;
    PropertyState property = definition.getProperty(propertyName);
    if (property != null) {
        value = property.getValue(Type.STRING);
    }
    return value;
}
Also used : PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 95 with PropertyState

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

the class SolrIndexEditor method docFromState.

private SolrInputDocument docFromState(NodeState state) {
    SolrInputDocument inputDocument = new SolrInputDocument();
    String path = getPath();
    inputDocument.addField(configuration.getPathField(), path);
    inputDocument.addField(configuration.getPathDepthField(), PathUtils.getDepth(path));
    if (configuration.collapseJcrContentNodes()) {
        int jcrContentIndex = path.lastIndexOf(JcrConstants.JCR_CONTENT);
        if (jcrContentIndex >= 0) {
            int index = jcrContentIndex + JcrConstants.JCR_CONTENT.length();
            String collapsedPath = path.substring(0, index);
            inputDocument.addField(configuration.getCollapsedPathField(), collapsedPath);
        }
    }
    for (PropertyState property : state.getProperties()) {
        if ((configuration.getUsedProperties().size() > 0 && configuration.getUsedProperties().contains(property.getName())) || !configuration.getIgnoredProperties().contains(property.getName())) {
            // try to get the field to use for this property from configuration
            String fieldName = configuration.getFieldNameFor(property.getType());
            Object fieldValue;
            if (fieldName != null) {
                fieldValue = property.getValue(property.getType());
            } else {
                fieldName = property.getName();
                if (Type.BINARY.tag() == property.getType().tag()) {
                    fieldValue = extractTextValues(property, state);
                } else if (property.isArray()) {
                    fieldValue = property.getValue(Type.STRINGS);
                } else {
                    fieldValue = property.getValue(Type.STRING);
                }
            }
            // add property field
            inputDocument.addField(fieldName, fieldValue);
            Object sortValue;
            if (fieldValue instanceof Iterable) {
                Iterable values = (Iterable) fieldValue;
                StringBuilder builder = new StringBuilder();
                String stringValue = null;
                for (Object value : values) {
                    builder.append(value);
                    if (builder.length() > 1024) {
                        stringValue = builder.substring(0, 1024);
                        break;
                    }
                }
                if (stringValue == null) {
                    stringValue = builder.toString();
                }
                sortValue = stringValue;
            } else {
                if (fieldValue.toString().length() > 1024) {
                    sortValue = fieldValue.toString().substring(0, 1024);
                } else {
                    sortValue = fieldValue;
                }
            }
            // add sort field
            inputDocument.addField(getSortingField(property.getType().tag(), property.getName()), sortValue);
        }
    }
    return inputDocument;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

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