diff --git a/src/org/kar/archidata/api/DataResource.java b/src/org/kar/archidata/api/DataResource.java index 5318e2f..586bffb 100644 --- a/src/org/kar/archidata/api/DataResource.java +++ b/src/org/kar/archidata/api/DataResource.java @@ -56,7 +56,7 @@ import jakarta.ws.rs.core.StreamingOutput; @Path("/data") @Produces(MediaType.APPLICATION_JSON) public class DataResource { - private static final Logger LOGGER = LoggerFactory.getLogger(MediaType.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DataResource.class); private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks /** Upload some datas */ diff --git a/src/org/kar/archidata/dataAccess/addOn/AddOnDataJson.java b/src/org/kar/archidata/dataAccess/addOn/AddOnDataJson.java index 713b0f2..25fca37 100644 --- a/src/org/kar/archidata/dataAccess/addOn/AddOnDataJson.java +++ b/src/org/kar/archidata/dataAccess/addOn/AddOnDataJson.java @@ -1,6 +1,7 @@ package org.kar.archidata.dataAccess.addOn; import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Types; @@ -17,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.validation.constraints.NotNull; @@ -85,6 +87,40 @@ public class AddOnDataJson implements DataAccessAddOn { count.inc(); if (!rs.wasNull()) { final ObjectMapper objectMapper = new ObjectMapper(); + if (field.getType() == List.class) { + ParameterizedType listType = (ParameterizedType) field.getGenericType(); + Class listClass = (Class) listType.getActualTypeArguments()[0]; + if (listClass == Long.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + if (listClass == Float.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + if (listClass == Double.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + if (listClass == Integer.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + if (listClass == Short.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + if (listClass == String.class) { + final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference>() {});// field.getType()); + field.set(data, dataParsed); + return; + } + } final Object dataParsed = objectMapper.readValue(jsonData, field.getType()); field.set(data, dataParsed); } diff --git a/src/org/kar/archidata/dataAccess/addOn/AddOnSQLTableExternalForeinKeyAsList.java b/src/org/kar/archidata/dataAccess/addOn/AddOnSQLTableExternalForeinKeyAsList.java index 603fed9..a50a9dc 100644 --- a/src/org/kar/archidata/dataAccess/addOn/AddOnSQLTableExternalForeinKeyAsList.java +++ b/src/org/kar/archidata/dataAccess/addOn/AddOnSQLTableExternalForeinKeyAsList.java @@ -73,7 +73,7 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn { @Override public boolean canInsert(final Field field) { - return false; + return true; } @Override diff --git a/src/org/kar/archidata/tools/DataTools.java b/src/org/kar/archidata/tools/DataTools.java index feb8faf..e5525eb 100644 --- a/src/org/kar/archidata/tools/DataTools.java +++ b/src/org/kar/archidata/tools/DataTools.java @@ -19,6 +19,7 @@ import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; import org.kar.archidata.dataAccess.options.Condition; +import org.kar.archidata.dataAccess.options.ReadAllColumn; import org.kar.archidata.model.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +77,7 @@ public class DataTools { public static Data getWithSha512(final String sha512) { try { - return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512))); + return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)), new ReadAllColumn()); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace();