Skip to content
Snippets Groups Projects
Commit c92a1f50 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

Fix unit conversion for records with primitive arrays.

parent 1026ce24
Branches trusted-single_pipeline
No related tags found
1 merge request!1002Fix unit conversion for records with primitive arrays.
......@@ -38,7 +38,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- OSDU Versions-->
<os-core-common.version>3.3.1</os-core-common.version>
<os-core-common.version>3.4.1</os-core-common.version>
<!-- Spring Versions-->
<spring-boot.version>3.3.7</spring-boot.version>
......
/*
* Copyright 2020-2025 Google LLC
* Copyright 2020-2025 EPAM Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.storage.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class FileReadUtil {
private static Gson gson = new Gson();
public static JsonObject readRecordFromFile(String filename) {
InputStream file = FileReadUtil.class.getClassLoader().getResourceAsStream(filename);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file));
return gson.fromJson(bufferedReader, JsonObject.class);
}
}
......@@ -72,6 +72,17 @@ public class RecordUtil {
return records.toString();
}
public static String createJsonRecordForUnitConversionWithPrimitiveArray(String id, String kind, String legalTag, String unitOfMeasureId, String fileName){
JsonObject defaultRecord = getDefaultRecord(id, kind, legalTag);
JsonObject recordObject = FileReadUtil.readRecordFromFile(fileName);
recordObject.get("meta").getAsJsonArray().get(0).getAsJsonObject().addProperty(UNIT_OF_MEASURE_ID, unitOfMeasureId);
defaultRecord.add("data", recordObject.get("data"));
defaultRecord.add("meta", recordObject.get("meta"));
JsonArray records = new JsonArray();
records.add(defaultRecord);
return records.toString();
}
public static String createJsonRecordWithEntV2OnlyAcl(String id, String kind, String legalTag, String data) {
JsonObject dataJson = new JsonObject();
dataJson.addProperty("custom", data);
......
{
"meta": [
{
"kind": "Unit",
"name": "ft",
"persistableReference": "{\"abcd\":{\"a\":0.0,\"b\":0.001,\"c\":1.0,\"d\":0.0},\"symbol\":\"ft\",\"baseMeasurement\":{\"ancestry\":\"L\",\"type\":\"UM\"},\"type\":\"UAD\"}",
"propertyNames": [
"GrainSizes[]"
]
}
],
"data": {
"GrainSizes": [
1,
2,
3
]
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment