List of usage examples for io.vertx.core.json JsonArray stream
public Stream<Object> stream()
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicDocumentImpl.java
License:Open Source License
void readDocuments(JsonArray docIds, List<String> categories, Handler<AsyncResult<JsonArray>> resultHandler) { MultiPartRequest marklogicRequest = restService.newMultipartRequest(); marklogicRequest.get(DOCUMENTS_URL).addParam(FORMAT, "json").addParams(CATEGORY, categories); docIds.stream().forEach(docId -> marklogicRequest.addParam(MarkLogicConstants.URI, (String) docId)); marklogicRequest.execute(response -> { SearchResponse searchResponse = new SearchResponse(response); searchResponse.endHandler(marklogicResponse -> { if (HttpResponseStatus.OK.code() == marklogicResponse.statusCode()) { JsonArray documents = new JsonArray(); for (Document document : ((SearchResponse) marklogicResponse).getDocuments()) { documents.add(document.toJson()); }// w w w . j ava2 s .c om resultHandler.handle(Future.succeededFuture(documents)); } if (HttpResponseStatus.NOT_FOUND.code() == marklogicResponse.statusCode()) { resultHandler.handle( Future.failedFuture(new ResourceNotFoundException(marklogicResponse.statusMessage()))); } resultHandler.handle(Future.succeededFuture()); }); searchResponse.process(); }); }
From source file:se.liquidbytes.jel.owfs.OwfsAdapter.java
License:Apache License
/** * Set value on device with specified hwId. * * @param hwId Id on device/*from ww w. j av a2 s . co m*/ * @param value value to set on device. * @throws DeviceMissingException throws exception if specified device does not exist. * @throws OwServerConnectionException throws exception if command fails for any reason. */ private void setDeviceValue(String hwId, String value) throws DeviceMissingException, OwServerConnectionException { if (hwId == null || !deviceLookup.containsKey(hwId)) { throw new DeviceMissingException("Trying to perform a action on a non existing device.", hwId); } if (hwId.contains(CHILDSEPARATOR)) { String parentId = hwId.split(CHILDSEPARATOR)[0]; String childSuffix = hwId.split(CHILDSEPARATOR)[1]; JsonObject parentDevice = deviceLookup.get(parentId); JsonObject typeInfo = parentDevice.getJsonObject("typeInfo"); if (typeInfo == null) { throw new OwServerConnectionException(String.format("typeInfo missing for device with type '%s'", parentDevice.getString("type"))); } JsonArray childDevices = typeInfo.getJsonArray("childDevices"); if (childDevices != null && childDevices.size() > 0) { String writePath = childDevices.stream().filter(t -> t instanceof JsonObject) .map(t -> (JsonObject) t).filter((d) -> d.getString("idSuffix").equals(childSuffix)) .map((cd) -> cd.getString("valueWritePath")).findFirst().get(); writePath = parentDevice.getString("path") + writePath; // Queue command. Record time so we could measure how long command has been queued before executed, if we want to. this.commandQueue.offer(new JsonObject().put("path", writePath).put("value", value).put("nanoTime", System.nanoTime())); } } else { JsonObject device = deviceLookup.get(hwId); JsonObject typeInfo = device.getJsonObject("typeInfo"); if (typeInfo == null) { throw new OwServerConnectionException( String.format("typeInfo missing for device with type '%s'", device.getString("type"))); } // Check if this type of device is writable. if (typeInfo.containsKey("valueWritePath")) { String writePath = device.getString("path") + typeInfo.getString("valueWritePath"); // Queue command. Record time so we could measure how long command has been queued before executed, if we want to. this.commandQueue.offer(new JsonObject().put("path", writePath).put("value", value).put("nanoTime", System.nanoTime())); } } }