Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe

Commits:

5 changed files:

Changes:

  • client/datasource/actions/src/main/i18n/templates/reportHtmlExport_en_GB.ftl
    ... ... @@ -273,6 +273,23 @@
    273 273
                 }, 50);
    
    274 274
             }
    
    275 275
     
    
    276
    +        function deserializeJson(json) {
    
    277
    +            let height = json.height;
    
    278
    +            let width = json.width;
    
    279
    +            let data = json.rows;
    
    280
    +            let result = new Array(height);
    
    281
    +            for (let row = 0; row < height; row++) {
    
    282
    +                let cells = data[row].split('||');
    
    283
    +                let realRow = new Array(width);
    
    284
    +                result[row]=realRow;
    
    285
    +                for (let column = 0; column < width; column++) {
    
    286
    +                    let rowElement = cells[column];
    
    287
    +                    realRow[column] = rowElement ==='$'?null:rowElement;
    
    288
    +                }
    
    289
    +            }
    
    290
    +            return result;
    
    291
    +        }
    
    292
    +
    
    276 293
             <#list .data_model.columnRendererFunctions as key>
    
    277 294
     ${key}</#list>
    
    278 295
     
    
    ... ... @@ -348,6 +365,7 @@ ${key}</#list>
    348 365
     
    
    349 366
     <script type="application/javascript">
    
    350 367
         const json = ${.data_model.json};
    
    368
    +    json.data.data = deserializeJson(json.data);
    
    351 369
     
    
    352 370
         const gridContainerParent = document.getElementById("wrapperParent");
    
    353 371
         const searchOption = document.getElementById("search");
    

  • client/datasource/actions/src/main/i18n/templates/reportHtmlExport_es_ES.ftl
    ... ... @@ -273,6 +273,23 @@
    273 273
                 }, 50);
    
    274 274
             }
    
    275 275
     
    
    276
    +        function deserializeJson(json) {
    
    277
    +            let height = json.height;
    
    278
    +            let width = json.width;
    
    279
    +            let data = json.rows;
    
    280
    +            let result = new Array(height);
    
    281
    +            for (let row = 0; row < height; row++) {
    
    282
    +                let cells = data[row].split('||');
    
    283
    +                let realRow = new Array(width);
    
    284
    +                result[row]=realRow;
    
    285
    +                for (let column = 0; column < width; column++) {
    
    286
    +                    let rowElement = cells[column];
    
    287
    +                    realRow[column] = rowElement ==='$'?null:rowElement;
    
    288
    +                }
    
    289
    +            }
    
    290
    +            return result;
    
    291
    +        }
    
    292
    +
    
    276 293
             <#list .data_model.columnRendererFunctions as key>
    
    277 294
     ${key}</#list>
    
    278 295
     
    
    ... ... @@ -347,6 +364,7 @@ ${key}</#list>
    347 364
     
    
    348 365
     <script type="application/javascript">
    
    349 366
         const json = ${.data_model.json};
    
    367
    +    json.data.data = deserializeJson(json.data);
    
    350 368
     
    
    351 369
         const gridContainerParent = document.getElementById("wrapperParent");
    
    352 370
         const searchOption = document.getElementById("search");
    

  • client/datasource/actions/src/main/i18n/templates/reportHtmlExport_fr_FR.ftl
    ... ... @@ -274,6 +274,23 @@
    274 274
                 }, 50);
    
    275 275
             }
    
    276 276
     
    
    277
    +        function deserializeJson(json) {
    
    278
    +            let height = json.height;
    
    279
    +            let width = json.width;
    
    280
    +            let data = json.rows;
    
    281
    +            let result = new Array(height);
    
    282
    +            for (let row = 0; row < height; row++) {
    
    283
    +                let cells = data[row].split('||');
    
    284
    +                let realRow = new Array(width);
    
    285
    +                result[row]=realRow;
    
    286
    +                for (let column = 0; column < width; column++) {
    
    287
    +                    let rowElement = cells[column];
    
    288
    +                    realRow[column] = rowElement ==='$'?null:rowElement;
    
    289
    +                }
    
    290
    +            }
    
    291
    +            return result;
    
    292
    +        }
    
    293
    +
    
    277 294
             <#list .data_model.columnRendererFunctions as key>
    
    278 295
     ${key}</#list>
    
    279 296
     
    
    ... ... @@ -348,6 +365,7 @@ ${key}</#list>
    348 365
     
    
    349 366
     <script type="application/javascript">
    
    350 367
         const json = ${.data_model.json};
    
    368
    +    json.data.data = deserializeJson(json.data);
    
    351 369
     
    
    352 370
         const gridContainerParent = document.getElementById("wrapperParent");
    
    353 371
         const searchOption = document.getElementById("search");
    

  • toolkit/api-report/src/main/java/fr/ird/observe/report/json/ReportColumnRenderersParametersAdapter.java
    1
    +package fr.ird.observe.report.json;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: API :: Report
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.google.auto.service.AutoService;
    
    26
    +import com.google.gson.JsonArray;
    
    27
    +import com.google.gson.JsonDeserializationContext;
    
    28
    +import com.google.gson.JsonDeserializer;
    
    29
    +import com.google.gson.JsonElement;
    
    30
    +import com.google.gson.JsonObject;
    
    31
    +import com.google.gson.JsonParseException;
    
    32
    +import com.google.gson.JsonSerializationContext;
    
    33
    +import com.google.gson.JsonSerializer;
    
    34
    +import fr.ird.observe.report.ColumnRendererParameters;
    
    35
    +import fr.ird.observe.report.ReportColumnRenderersParameters;
    
    36
    +import io.ultreia.java4all.lang.Objects2;
    
    37
    +import io.ultreia.java4all.util.json.JsonAdapter;
    
    38
    +
    
    39
    +import java.lang.reflect.Type;
    
    40
    +import java.util.ArrayList;
    
    41
    +import java.util.List;
    
    42
    +
    
    43
    +/**
    
    44
    + * Created at 01/12/2023.
    
    45
    + *
    
    46
    + * @author Tony Chemit - dev@tchemit.fr
    
    47
    + * @since 9.3.0
    
    48
    + */
    
    49
    +@AutoService(JsonAdapter.class)
    
    50
    +public class ReportColumnRenderersParametersAdapter implements JsonDeserializer<ReportColumnRenderersParameters>, JsonSerializer<ReportColumnRenderersParameters>, JsonAdapter {
    
    51
    +
    
    52
    +    private static final String TYPE = "type";
    
    53
    +    private static final String VALUE = "value";
    
    54
    +
    
    55
    +    @Override
    
    56
    +    public Class<?> type() {
    
    57
    +        return ReportColumnRenderersParameters.class;
    
    58
    +    }
    
    59
    +
    
    60
    +    @Override
    
    61
    +    public ReportColumnRenderersParameters deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
    
    62
    +        JsonArray columnRendererParametersJson = json.getAsJsonArray();
    
    63
    +        List<ColumnRendererParameters> list = new ArrayList<>(columnRendererParametersJson.size());
    
    64
    +        for (JsonElement itemJson : columnRendererParametersJson) {
    
    65
    +            JsonObject asJsonObject = itemJson.getAsJsonObject();
    
    66
    +            String key = context.deserialize(asJsonObject.get(TYPE), String.class);
    
    67
    +            Class<ColumnRendererParameters> itemType = Objects2.forName(key);
    
    68
    +            list.add(context.deserialize(asJsonObject.get(VALUE), itemType));
    
    69
    +        }
    
    70
    +        return new ReportColumnRenderersParameters(list);
    
    71
    +    }
    
    72
    +
    
    73
    +    @Override
    
    74
    +    public JsonElement serialize(ReportColumnRenderersParameters src, Type typeOfSrc, JsonSerializationContext context) {
    
    75
    +        JsonArray result = new JsonArray();
    
    76
    +        for (ColumnRendererParameters columnRendererParameter : src.getColumnRendererParameters()) {
    
    77
    +            JsonObject item = new JsonObject();
    
    78
    +            item.addProperty(TYPE, columnRendererParameter.getClass().getName());
    
    79
    +            item.add(VALUE, context.serialize(columnRendererParameter));
    
    80
    +            result.add(item);
    
    81
    +        }
    
    82
    +        return result;
    
    83
    +    }
    
    84
    +}

  • toolkit/api/src/main/java/fr/ird/observe/spi/json/java4all/DataMatrixAdapter.java
    1
    +package fr.ird.observe.spi.json.java4all;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: API
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 IRD, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.google.auto.service.AutoService;
    
    26
    +import com.google.gson.JsonArray;
    
    27
    +import com.google.gson.JsonDeserializationContext;
    
    28
    +import com.google.gson.JsonDeserializer;
    
    29
    +import com.google.gson.JsonElement;
    
    30
    +import com.google.gson.JsonObject;
    
    31
    +import com.google.gson.JsonParseException;
    
    32
    +import com.google.gson.JsonPrimitive;
    
    33
    +import com.google.gson.JsonSerializationContext;
    
    34
    +import com.google.gson.JsonSerializer;
    
    35
    +import io.ultreia.java4all.util.json.JsonAdapter;
    
    36
    +import io.ultreia.java4all.util.matrix.DataMatrix;
    
    37
    +
    
    38
    +import java.lang.reflect.Type;
    
    39
    +import java.util.Arrays;
    
    40
    +import java.util.stream.Collectors;
    
    41
    +
    
    42
    +/**
    
    43
    + * Created at 01/12/2023.
    
    44
    + *
    
    45
    + * @author Tony Chemit - dev@tchemit.fr
    
    46
    + * @since 9.3.0
    
    47
    + */
    
    48
    +@AutoService(JsonAdapter.class)
    
    49
    +public class DataMatrixAdapter implements JsonDeserializer<DataMatrix>, JsonSerializer<DataMatrix>, JsonAdapter {
    
    50
    +
    
    51
    +    private static final String WIDTH = "width";
    
    52
    +    private static final String HEIGHT = "height";
    
    53
    +    private static final String X = "x";
    
    54
    +    private static final String Y = "y";
    
    55
    +    private static final String ROWS = "rows";
    
    56
    +
    
    57
    +    @Override
    
    58
    +    public Class<?> type() {
    
    59
    +        return DataMatrix.class;
    
    60
    +    }
    
    61
    +
    
    62
    +    @Override
    
    63
    +    public DataMatrix deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
    
    64
    +        JsonObject dataMatrixAsJsonObject = json.getAsJsonObject();
    
    65
    +
    
    66
    +        DataMatrix result = new DataMatrix();
    
    67
    +        result.setWidth(context.deserialize(dataMatrixAsJsonObject.get(WIDTH), int.class));
    
    68
    +        result.setHeight(context.deserialize(dataMatrixAsJsonObject.get(HEIGHT), int.class));
    
    69
    +        result.setX(context.deserialize(dataMatrixAsJsonObject.get(X), int.class));
    
    70
    +        result.setY(context.deserialize(dataMatrixAsJsonObject.get(Y), int.class));
    
    71
    +        JsonArray rows = dataMatrixAsJsonObject.getAsJsonArray(ROWS);
    
    72
    +        Object[][] data = new Object[result.getHeight()][result.getWidth()];
    
    73
    +        int index = 0;
    
    74
    +        for (JsonElement rowElement : rows) {
    
    75
    +            String[] deserialize = rowElement.getAsString().split("\\|\\|");
    
    76
    +            Object[] row = new Object[deserialize.length];
    
    77
    +            for (int i = 0; i < deserialize.length; i++) {
    
    78
    +                String s = deserialize[i];
    
    79
    +                row[i] = s.equals("$") ? null : s;
    
    80
    +            }
    
    81
    +            data[index++] = row;
    
    82
    +        }
    
    83
    +        result.setData(data);
    
    84
    +        return result;
    
    85
    +    }
    
    86
    +
    
    87
    +    @Override
    
    88
    +    public JsonElement serialize(DataMatrix src, Type typeOfSrc, JsonSerializationContext context) {
    
    89
    +        JsonObject result = new JsonObject();
    
    90
    +        result.addProperty(WIDTH, src.getWidth());
    
    91
    +        result.addProperty(HEIGHT, src.getHeight());
    
    92
    +        result.addProperty(X, src.getX());
    
    93
    +        result.addProperty(Y, src.getY());
    
    94
    +        JsonArray rows = new JsonArray(src.getHeight());
    
    95
    +        result.add(ROWS, rows);
    
    96
    +        for (Object[] row : src.getData()) {
    
    97
    +            rows.add(new JsonPrimitive(Arrays.stream(row).map(d -> d == null ? "$" : d.toString()).collect(Collectors.joining("||"))));
    
    98
    +        }
    
    99
    +
    
    100
    +        return result;
    
    101
    +    }
    
    102
    +}
    
    103
    +