use of me.retrodaredevil.couchdbjava.response.ViewResponse in project solarthing by wildmountainfarms.
the class CouchDbMillisDatabase method query.
@Override
public List<StoredPacketGroup> query(MillisQuery query) throws SolarThingDatabaseException {
final ViewResponse response;
try {
response = database.queryView(SolarThingCouchDb.createMillisNullView(CouchDbQueryUtil.createMillisNullParams(query)));
} catch (CouchDbException e) {
throw ExceptionUtil.createFromCouchDbException(e);
}
List<ViewResponse.DocumentEntry> rows = response.getRows();
List<StoredPacketGroup> r = new ArrayList<>(rows.size());
for (ViewResponse.DocumentEntry row : rows) {
// When using includeDocs=true, we want to use the doc, not its value (which is null with millisNull)
JsonData jsonData = row.getDoc();
StoredPacketGroup storedPacketGroup = jsonDataToStoredPacketGroup(jsonData).getPacket();
r.add(storedPacketGroup);
}
return r;
}
use of me.retrodaredevil.couchdbjava.response.ViewResponse in project solarthing by wildmountainfarms.
the class CouchDbAlterDatabase method queryAll.
@Override
@NotNull
public List<VersionedPacket<StoredAlterPacket>> queryAll(String sourceId) throws SolarThingDatabaseException {
final ViewResponse allDocs;
try {
allDocs = database.allDocs(new ViewQueryParamsBuilder().includeDocs(true).build());
} catch (CouchDbException e) {
throw ExceptionUtil.createFromCouchDbException(e);
}
List<ViewResponse.DocumentEntry> rows = allDocs.getRows();
List<VersionedPacket<StoredAlterPacket>> r = new ArrayList<>(rows.size());
for (ViewResponse.DocumentEntry row : rows) {
if (row.getId().startsWith("_")) {
// ignore design documents
continue;
}
// Since we're using _all_docs with include_docs=true, we have to use the doc, since the value is just the ID for _all_docs
JsonData jsonData = row.getDoc();
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 _all_docs!");
}
ObjectNode objectNode = (ObjectNode) jsonNode;
final StoredAlterPacket storedAlterPacket;
try {
storedAlterPacket = mapper.treeToValue(objectNode, StoredAlterPacket.class);
;
} catch (JsonProcessingException e) {
throw new SolarThingDatabaseException("Could not parse. JsonData: " + jsonData.getJson(), e);
}
// String documentId = objectNode.get("_id").asText();
String documentRevision = objectNode.get("_rev").asText();
VersionedPacket<StoredAlterPacket> versionedPacket = new VersionedPacket<>(storedAlterPacket, new RevisionUpdateToken(documentRevision));
r.add(versionedPacket);
}
return r;
}
Aggregations