Package com.couchbase.client.java.document.json

Examples of com.couchbase.client.java.document.json.JsonObject


                public Observable<AsyncQueryResult> call(final GenericQueryResponse response) {
                    final Observable<AsyncQueryRow> rows = response.rows().map(new Func1<ByteBuf, AsyncQueryRow>() {
                        @Override
                        public AsyncQueryRow call(ByteBuf byteBuf) {
                            try {
                                JsonObject value = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                                return new DefaultAsyncQueryRow(value);
                            } catch (Exception e) {
                                throw new TranscodingException("Could not decode View Info.", e);
                            }
                        }
                    });
                    final Observable<JsonObject> info = response.info().map(new Func1<ByteBuf, JsonObject>() {
                        @Override
                        public JsonObject call(ByteBuf byteBuf) {
                            try {
                                return JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                            } catch (Exception e) {
                                throw new TranscodingException("Could not decode View Info.", e);
                            }
                        }
                    });
                    if (response.status().isSuccess()) {
                        return Observable.just((AsyncQueryResult) new DefaultAsyncQueryResult(rows, info, null,
                            response.status().isSuccess()));
                    } else {
                        return response.info().map(new Func1<ByteBuf, AsyncQueryResult>() {
                            @Override
                            public AsyncQueryResult call(ByteBuf byteBuf) {
                                try {
                                    JsonObject error = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                                    return new DefaultAsyncQueryResult(rows, info, error, response.status().isSuccess());
                                } catch (Exception e) {
                                    throw new TranscodingException("Could not decode View Info.", e);
                                }
View Full Code Here


    public Observable<DesignDocument> getDesignDocuments(final boolean development) {
        return core.<GetDesignDocumentsResponse>send(new GetDesignDocumentsRequest(bucket, password))
            .flatMap(new Func1<GetDesignDocumentsResponse, Observable<DesignDocument>>() {
                @Override
                public Observable<DesignDocument> call(GetDesignDocumentsResponse response) {
                    JsonObject converted = null;
                    try {
                        converted = CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER.stringToJsonObject(response.content());
                    } catch (Exception e) {
                        throw new TranscodingException("Could not decode design document.", e);
                    }
                    JsonArray rows = converted.getArray("rows");
                    List<DesignDocument> docs = new ArrayList<DesignDocument>();
                    for (Object doc : rows) {
                        JsonObject docObj = ((JsonObject) doc).getObject("doc");
                        String id = docObj.getObject("meta").getString("id");
                        String[] idSplit = id.split("/");
                        String fullName = idSplit[1];
                        boolean isDev = fullName.startsWith("dev_");
                        if (isDev != development) {
                            continue;
                        }
                        String name = fullName.replace("dev_", "");
                        docs.add(DesignDocument.from(name, docObj.getObject("json")));
                    }
                    return Observable.from(docs);
                }
            });
    }
View Full Code Here

                }
            })
            .map(new Func1<GetDesignDocumentResponse, DesignDocument>() {
                @Override
                public DesignDocument call(GetDesignDocumentResponse response) {
                    JsonObject converted;
                    try {
                        converted = CouchbaseAsyncBucket.JSON_OBJECT_TRANSCODER.stringToJsonObject(
                            response.content().toString(CharsetUtil.UTF_8));
                    } catch (Exception e) {
                        throw new TranscodingException("Could not decode design document.", e);
View Full Code Here

                            }
                        }
                    }).map(new Func1<JsonObject, AsyncViewResult>() {
                        @Override
                        public AsyncViewResult call(JsonObject jsonInfo) {
                            JsonObject error = null;
                            JsonObject debug = null;
                            int totalRows = 0;
                            boolean success = response.status().isSuccess();
                            if (success) {
                                debug = jsonInfo.getObject("debug_info");
                                Integer trows = jsonInfo.getInt("total_rows");
                                if (trows != null) {
                                    totalRows = trows;
                                }
                            } else if (response.status() == ResponseStatus.NOT_EXISTS) {
                                throw new ViewDoesNotExistException("View " + query.getDesign() + "/"
                                    + query.getView() + " does not exist.");
                            } else {
                                error = jsonInfo;
                            }

                            Observable<AsyncViewRow> rows = response.rows().map(new Func1<ByteBuf, AsyncViewRow>() {
                                @Override
                                public AsyncViewRow call(final ByteBuf byteBuf) {
                                    JsonObject doc;
                                    try {
                                        doc = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                                    } catch (Exception e) {
                                        throw new TranscodingException("Could not decode View Info.", e);
                                    }
                                    String id = doc.getString("id");
                                    return new DefaultAsyncViewRow(CouchbaseAsyncBucket.this, id, doc.get("key"), doc.get("value"));
                                }
                            });
                            return new DefaultAsyncViewResult(rows, totalRows, success, error, debug);
                        }
                    });
View Full Code Here

        if (!TranscoderUtils.hasJsonFlags(flags)) {
            throw new TranscodingException("Flags (0x" + Integer.toHexString(flags) + ") indicate non-JSON document for "
                + "id " + id + ", could not decode.");
        }

        JsonObject converted = stringToJsonObject(content.toString(CharsetUtil.UTF_8));
        content.release();
        return newDocument(id, expiry, converted, cas);
    }
View Full Code Here

        return new DesignDocument(name, views);
    }

    public static DesignDocument from(final String name, final JsonObject raw) {
        final List<View> views = new ArrayList<View>();
        JsonObject rawViews = raw.getObject("views");
        if (rawViews != null) {
           for(Map.Entry<String, Object> entry : rawViews.toMap().entrySet()) {
               String viewName = entry.getKey();
               JsonObject viewContent = (JsonObject) entry.getValue();
               String map = viewContent.getString("map");
               String reduce = viewContent.getString("reduce");
               views.add(DefaultView.create(viewName, map, reduce));
            }
        }
        return new DesignDocument(name, views);
    }
View Full Code Here

        return "DesignDocument{" + "name='" + name + '\'' + ", views=" + views + '}';
    }


    public JsonObject toJsonObject() {
        JsonObject converted = JsonObject.empty();
        JsonObject views = JsonObject.empty();

        for (View view : this.views) {
            JsonObject content = JsonObject.empty();
            content.put("map", view.map());
            if (view.hasReduce()) {
                content.put("reduce", view.reduce());
            }
            views.put(view.name(), content);
        }

        converted.put("views", views);
View Full Code Here

                public Observable<BucketSettings> call(BucketsConfigResponse response) {
                    try {
                        JsonArray decoded = CouchbaseAsyncBucket.JSON_ARRAY_TRANSCODER.stringToJsonArray(response.config());
                        List<BucketSettings> settings = new ArrayList<BucketSettings>();
                        for (Object item : decoded) {
                            JsonObject bucket = (JsonObject) item;
                            settings.add(DefaultBucketSettings.builder()
                                .name(bucket.getString("name"))
                                .enableFlush(bucket.getObject("controllers").getString("flush") != null)
                                .type(bucket.getString("bucketType").equals("membase")
                                    ? BucketType.COUCHBASE : BucketType.MEMCACHED)
                                .replicas(bucket.getInt("replicaNumber"))
                                .quota(bucket.getObject("quota").getInt("ram"))
                                .indexReplicas(bucket.getBoolean("replicaIndex"))
                                .port(bucket.getInt("proxyPort"))
                                .password(bucket.getString("saslPassword"))
                                .build());
                        }
                        return Observable.from(settings);
                    } catch (Exception e) {
                        throw new TranscodingException("Could not decode cluster info.", e);
View Full Code Here

        return new DesignDocument(name, views);
    }

    public static DesignDocument from(final String name, final JsonObject raw) {
        final List<View> views = new ArrayList<View>();
        JsonObject rawViews = raw.getObject("views");
        if (rawViews != null) {
           for(Map.Entry<String, Object> entry : rawViews.toMap().entrySet()) {
               String viewName = entry.getKey();
               JsonObject viewContent = (JsonObject) entry.getValue();
               String map = viewContent.getString("map");
               String reduce = viewContent.getString("reduce");
               views.add(DefaultView.create(viewName, map, reduce));
            }
        }
        return new DesignDocument(name, views);
    }
View Full Code Here

        return "DesignDocument{" + "name='" + name + '\'' + ", views=" + views + '}';
    }


    public JsonObject toJsonObject() {
        JsonObject converted = JsonObject.empty();
        JsonObject views = JsonObject.empty();

        for (View view : this.views) {
            JsonObject content = JsonObject.empty();
            content.put("map", view.map());
            if (view.hasReduce()) {
                content.put("reduce", view.reduce());
            }
            views.put(view.name(), content);
        }

        converted.put("views", views);
View Full Code Here

TOP

Related Classes of com.couchbase.client.java.document.json.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.