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));
}
Aggregations