46 lines
1.3 KiB
Java
46 lines
1.3 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.informationsystem.utils;
|
|
|
|
import java.io.IOException;
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class Utility {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(Utility.class);
|
|
|
|
public static UUID getUUIDFromJsonNode(JsonNode jsonNode){
|
|
UUID uuid = UUID.fromString(jsonNode.get(IdentifiableElement.UUID_PROPERTY).asText());
|
|
logger.trace("UUID got from {} is : {} ", jsonNode.toString(), uuid);
|
|
return uuid;
|
|
}
|
|
|
|
public static UUID getUUIDFromJSONString(String json) throws JsonProcessingException, IOException {
|
|
logger.trace("Trying to get UUID of {} ", json);
|
|
JsonNode jsonNode = getJSONNode(json);
|
|
return getUUIDFromJsonNode(jsonNode);
|
|
}
|
|
|
|
public static JsonNode getJSONNode(String json) throws JsonProcessingException, IOException {
|
|
if(json==null || json.compareTo("")==0){
|
|
return null;
|
|
}
|
|
logger.trace("Trying to get Jsonnode from {}", json);
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
JsonNode jsonNode = mapper.readTree(json);
|
|
return jsonNode;
|
|
}
|
|
|
|
}
|