Search in sources :

Example 1 with AddressConstants

use of io.georocket.constants.AddressConstants in project georocket by georocket.

the class MockIndexer method mockIndexerQuery.

/**
 * Start consuming {@link AddressConstants#INDEXER_QUERY} messages.
 * See the class comments to see the logic of the replied items.
 *
 * Returns "valid" hits that correspond to the items that are returned from the {@link MockStore}.
 *
 * @param vertx vertx instance
 */
public static void mockIndexerQuery(Vertx vertx) {
    indexerQuerySubscription = vertx.eventBus().<JsonObject>consumer(AddressConstants.INDEXER_QUERY).toObservable().subscribe(msg -> {
        JsonArray hits = new JsonArray();
        String givenScrollId = msg.body().getString("scrollId");
        Long numberReturnHits;
        String returnScrollId;
        if (givenScrollId == null) {
            numberReturnHits = HITS_PER_PAGE;
            returnScrollId = FIRST_RETURNED_SCROLL_ID;
        } else if (givenScrollId.equals(FIRST_RETURNED_SCROLL_ID)) {
            numberReturnHits = TOTAL_HITS - HITS_PER_PAGE;
            returnScrollId = INVALID_SCROLLID;
        } else {
            numberReturnHits = 0L;
            returnScrollId = INVALID_SCROLLID;
        }
        for (int i = 0; i < numberReturnHits; i++) {
            hits.add(new JsonObject().put("mimeType", "application/geo+json").put("id", "some_id").put("start", 0).put("end", MockStore.RETURNED_CHUNK.length()).put("parents", new JsonArray()));
        }
        if (INVALID_SCROLLID.equals(givenScrollId)) {
            msg.fail(404, "invalid scroll id");
        } else {
            msg.reply(new JsonObject().put("totalHits", TOTAL_HITS).put("scrollId", returnScrollId).put("hits", hits));
        }
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) AddressConstants(io.georocket.constants.AddressConstants) Subscription(rx.Subscription) Vertx(io.vertx.rxjava.core.Vertx) JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

AddressConstants (io.georocket.constants.AddressConstants)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Vertx (io.vertx.rxjava.core.Vertx)1 Subscription (rx.Subscription)1