You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Robert Munteanu (Jira)" <ji...@apache.org> on 2023/04/19 15:00:03 UTC

[jira] [Created] (SLING-11837) Align index definition generation logic with the one from Oak

Robert Munteanu created SLING-11837:
---------------------------------------

             Summary: Align index definition generation logic with the one from Oak
                 Key: SLING-11837
                 URL: https://issues.apache.org/jira/browse/SLING-11837
             Project: Sling
          Issue Type: Improvement
          Components: Content-Package to Feature Model Converter
            Reporter: Robert Munteanu
             Fix For: Content-Package to Feature Model Converter 1.3.2


The logic used to generate the "str:" prefix for string values comes from here: https://github.com/apache/sling-org-apache-sling-feature-cpconverter/blob/a98317ba836d9acedb334518a438f4bcc8ce721d/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java#L108

For prefixes, we should probably use the logic used in Oak. AFAIK this is implemented in oak-store-spi, package org.apache.jackrabbit.oak.json, serialize:

{noformat}
    public void serialize(PropertyState property, Type<?> type, int index) {
        if (type == BOOLEAN) {
            json.value(property.getValue(BOOLEAN, index));
        } else if (type == LONG) {
            json.value(property.getValue(LONG, index));
        } else if (type == DOUBLE) {
            Double value = property.getValue(DOUBLE, index);
            if (value.isNaN() || value.isInfinite()) {
                json.value(TypeCodes.encode(type.tag(), value.toString()));
            } else {
                json.encodedValue(value.toString());
            }
        } else if (type == BINARY) {
            Blob blob = property.getValue(BINARY, index);
            json.value(TypeCodes.encode(type.tag(), blobs.serialize(blob)));
        } else  {
            String value = property.getValue(STRING, index);
            if (type != STRING || TypeCodes.split(value) != -1) {
                value = TypeCodes.encode(type.tag(), value);
            }
            json.value(value);
        }
    }

    public static int split(String jsonString) {
        if (jsonString.startsWith(":blobId:")) {  // See OAK-428
            return 7;
        }
        else if (jsonString.length() >= 4 && jsonString.charAt(3) == ':') {
            return 3;
        }
        else {
            return -1;
        }
    }

{noformat}

So basically, the logic for String types is: if there is a ':' at position 4, then the "str:" prefix is needed. Otherwise, not.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)