Search in sources :

Example 1 with PacketParseException

use of me.retrodaredevil.solarthing.packets.collection.parsing.PacketParseException in project solarthing by wildmountainfarms.

the class CouchDbMillisDatabase method jsonDataToStoredPacketGroup.

private VersionedPacket<StoredPacketGroup> jsonDataToStoredPacketGroup(JsonData jsonData) throws SolarThingDatabaseException {
    final JsonNode jsonNode;
    try {
        jsonNode = CouchDbJacksonUtil.getNodeFrom(jsonData);
    } catch (JsonProcessingException e) {
        throw new SolarThingDatabaseException("We couldn't parse some of the data into JSON. This should never happen", e);
    }
    if (!jsonNode.isObject()) {
        throw new SolarThingDatabaseException("Something must be wrong with the packet millis view because we got this jsonNode: " + jsonNode);
    }
    ObjectNode objectNode = (ObjectNode) jsonNode;
    final PacketGroup packetGroup;
    try {
        packetGroup = parser.parse(objectNode);
    } catch (PacketParseException e) {
        throw new SolarThingDatabaseException(e);
    }
    String documentId = objectNode.get("_id").asText();
    String documentRevision = objectNode.get("_rev").asText();
    StoredPacketGroup storedPacketGroup = PacketGroups.createStoredPacketGroup(packetGroup, new CouchDbStoredIdentifier(packetGroup.getDateMillis(), documentId, documentRevision));
    return new VersionedPacket<>(storedPacketGroup, new RevisionUpdateToken(documentRevision));
}
Also used : PacketGroup(me.retrodaredevil.solarthing.packets.collection.PacketGroup) StoredPacketGroup(me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) PacketParseException(me.retrodaredevil.solarthing.packets.collection.parsing.PacketParseException) JsonNode(com.fasterxml.jackson.databind.JsonNode) StoredPacketGroup(me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 VersionedPacket (me.retrodaredevil.solarthing.database.VersionedPacket)1 SolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)1 PacketGroup (me.retrodaredevil.solarthing.packets.collection.PacketGroup)1 StoredPacketGroup (me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup)1 PacketParseException (me.retrodaredevil.solarthing.packets.collection.parsing.PacketParseException)1