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/21 12:43:00 UTC

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

     [ https://issues.apache.org/jira/browse/SLING-11837?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Munteanu updated SLING-11837:
------------------------------------
    Description: 
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 https://github.com/apache/jackrabbit-oak/blob/838780a7aaf9775ad0bf7b6be65c1a1619e65eb7/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java#L269-L291:

{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. Note that we can't reuse the code since it uses the NodeState/PropertyState API.

  was:
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.


> 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
>            Assignee: Robert Munteanu
>            Priority: Major
>             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 https://github.com/apache/jackrabbit-oak/blob/838780a7aaf9775ad0bf7b6be65c1a1619e65eb7/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/json/JsonSerializer.java#L269-L291:
> {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. Note that we can't reuse the code since it uses the NodeState/PropertyState API.



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