All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cognite.client.servicesV1.parser.ThreeDRevisionLogsParser Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.cognite.client.servicesV1.parser;

import com.cognite.client.dto.ThreeDModelRevision;
import com.cognite.client.dto.ThreeDRevisionLog;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

public class ThreeDRevisionLogsParser {

    static final ObjectMapper objectMapper = new ObjectMapper();

    public static List parseThreeDRevisionLogs(String json) throws JsonProcessingException {
        List list = new ArrayList<>();
        JsonNode root = objectMapper.readTree(json);
        ThreeDRevisionLog.Builder tmBuilder = ThreeDRevisionLog.newBuilder();

        if (root.path("items").isArray()) {
            for (JsonNode node : root.path("items")) {
                extractNodes(tmBuilder, node);
                list.add(tmBuilder.build());
                tmBuilder.clear();
            }
        }else if (root.isObject()) {
            extractNodes(tmBuilder, root);
            list.add(tmBuilder.build());
        }
        return list;
    }

    private static void extractNodes(ThreeDRevisionLog.Builder tmBuilder, JsonNode node) {
        if (node.path("timestamp").isIntegralNumber()) {
            tmBuilder.setTimestamp(node.get("timestamp").longValue());
        }
        if (node.path("severity").isIntegralNumber()) {
            tmBuilder.setSeverity(node.get("severity").intValue());
        }
        if (node.path("type").isTextual()) {
            tmBuilder.setType(node.get("type").textValue());
        }
        if (node.path("info").isTextual()) {
            tmBuilder.setType(node.get("info").textValue());
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy