Improved code

This commit is contained in:
Luca Frosini 2024-04-16 16:35:38 +02:00
parent 489eed2787
commit 2aa2909e4e
1 changed files with 4 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.gxhttp.reference.GXConnection; import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
@ -443,12 +444,14 @@ public class ResourceRegistryPublisherImpl extends BaseRequestInfo implements Re
public String create(String json) public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
JsonNode jsonNode = JsonUtility.getJsonNode(json); ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json);
String type = TypeUtility.getTypeName(jsonNode); String type = TypeUtility.getTypeName(jsonNode);
UUID uuid = UUIDUtility.getUUID(jsonNode); UUID uuid = UUIDUtility.getUUID(jsonNode);
if(uuid==null) { if(uuid==null) {
uuid = UUIDManager.getInstance().generateValidUUID(); uuid = UUIDManager.getInstance().generateValidUUID();
((ObjectNode) jsonNode).put(ERElement.ID_PROPERTY, uuid.toString()); ((ObjectNode) jsonNode).put(ERElement.ID_PROPERTY, uuid.toString());
json = mapper.writeValueAsString(jsonNode);
} }
return create(type, json, uuid); return create(type, json, uuid);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {