Search in sources :

Example 6 with IndexerException

use of com.bluenimble.platform.indexer.IndexerException in project serverless by bluenimble.

the class ElasticSearchIndexer method describe.

@Override
public JsonObject describe(String entity) throws IndexerException {
    if (Lang.isNullOrEmpty(entity)) {
        throw new IndexerException("Entity cannot be null nor empty.");
    }
    tracer.log(Tracer.Level.Info, "Describe entity [{0}]", entity);
    JsonObject result = new JsonObject();
    Error error = new Error();
    remote.get((JsonObject) new JsonObject().set(Remote.Spec.Endpoint, url + Internal.Elk.Mapping + Lang.SLASH + entity).set(Remote.Spec.Headers, new JsonObject().set(HttpHeaders.AUTHORIZATION, authToken).set(HttpHeaders.CONTENT_TYPE, ContentTypes.Json)).set(Remote.Spec.Serializer, Serializer.Name.json), new Remote.Callback() {

        @Override
        public void onSuccess(int code, Object data) {
            if (data != null) {
                result.putAll((JsonObject) data);
            }
        }

        @Override
        public void onError(int code, Object message) {
            error.set(code, message);
        }
    });
    if (error.happened()) {
        throw new IndexerException("Error occured while calling Indexer: Code=" + error.code + ", Message: " + error.message);
    }
    return result;
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) Remote(com.bluenimble.platform.remote.Remote) IndexerException(com.bluenimble.platform.indexer.IndexerException) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 7 with IndexerException

use of com.bluenimble.platform.indexer.IndexerException in project serverless by bluenimble.

the class ElasticSearchIndexer method delete.

@Override
public JsonObject delete(String entity, String id) throws IndexerException {
    if (Lang.isNullOrEmpty(id)) {
        throw new IndexerException("Document Id cannot be null nor empty.");
    }
    JsonObject result = new JsonObject();
    Error error = new Error();
    tracer.log(Tracer.Level.Info, "Delete document [{0}]", id);
    remote.delete((JsonObject) new JsonObject().set(Remote.Spec.Endpoint, url + entity + Lang.SLASH + id).set(Remote.Spec.Headers, new JsonObject().set(HttpHeaders.AUTHORIZATION, authToken)).set(Remote.Spec.Serializer, Serializer.Name.json), new Remote.Callback() {

        @Override
        public void onSuccess(int code, Object data) {
            if (data != null) {
                result.putAll((JsonObject) data);
            }
        }

        @Override
        public void onError(int code, Object message) {
            error.set(code, message);
        }
    });
    if (error.happened()) {
        throw new IndexerException("Error occured while calling Indexer: Code=" + error.code + ", Message: " + error.message);
    }
    return result;
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) Remote(com.bluenimble.platform.remote.Remote) IndexerException(com.bluenimble.platform.indexer.IndexerException) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 8 with IndexerException

use of com.bluenimble.platform.indexer.IndexerException in project serverless by bluenimble.

the class ElasticSearchIndexer method clear.

@Override
public JsonObject clear(String entity) throws IndexerException {
    if (Lang.isNullOrEmpty(entity)) {
        throw new IndexerException("Entity cannot be null nor empty.");
    }
    tracer.log(Tracer.Level.Info, "Deleting all documents in entity [{0}]", entity);
    JsonObject result = new JsonObject();
    Error error = new Error();
    remote.post((JsonObject) new JsonObject().set(Remote.Spec.Endpoint, url + entity + Lang.SLASH + Internal.Elk.DeleteQ).set(Remote.Spec.Headers, new JsonObject().set(HttpHeaders.AUTHORIZATION, authToken).set(HttpHeaders.CONTENT_TYPE, ContentTypes.Json)).set(Remote.Spec.Data, new JsonObject().set(Internal.Elk.Query, new JsonObject().set(Internal.Elk.MatchAll, new JsonObject()))).set(Remote.Spec.Serializer, Serializer.Name.json), new Remote.Callback() {

        @Override
        public void onSuccess(int code, Object data) {
            if (data != null) {
                result.putAll((JsonObject) data);
            }
        }

        @Override
        public void onError(int code, Object message) {
            error.set(code, message);
        }
    });
    return null;
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) Remote(com.bluenimble.platform.remote.Remote) IndexerException(com.bluenimble.platform.indexer.IndexerException) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 9 with IndexerException

use of com.bluenimble.platform.indexer.IndexerException in project serverless by bluenimble.

the class ElasticSearchIndexer method create.

/*
	
	@Override
	public JsonObject init () throws IndexerException {
		JsonObject result 	= new JsonObject ();
		Error error 		= new Error ();
		
		JsonObject oEntity 	= (JsonObject)new JsonObject ()
			.set (Remote.Spec.Endpoint, url)
			.set (Remote.Spec.Headers, 
				new JsonObject ()
					.set (HttpHeaders.AUTHORIZATION, authToken)
					.set (HttpHeaders.CONTENT_TYPE, ContentTypes.Json)
			).set (Remote.Spec.Serializer, Serializer.Name.json);
		
		remote.put (
			oEntity, 
			new Remote.Callback () {
				@Override
				public void onSuccess (int code, Object data) {
					if (data != null) {
						result.putAll ((JsonObject)data);
					}
				}
				@Override
				public void onError (int code, Object message) {
					error.set (code, message);
				}
			}
		);
		
		if (error.happened ()) {
			throw new IndexerException ("Error occured while calling Indexer: Code=" + error.code + ", Message: " + error.message);
		}
		
		return result;
	}
	
	*/
@Override
public JsonObject create(String entity, JsonObject definition) throws IndexerException {
    if (Lang.isNullOrEmpty(entity)) {
        throw new IndexerException("Entity cannot be null nor empty.");
    }
    tracer.log(Tracer.Level.Info, "Creating entity [{0}] with definition {1}", entity, definition);
    JsonObject result = new JsonObject();
    Error error = new Error();
    JsonObject oEntity = (JsonObject) new JsonObject().set(Remote.Spec.Endpoint, url + entity + Lang.SLASH + Internal.Elk.Mapping).set(Remote.Spec.Headers, new JsonObject().set(HttpHeaders.AUTHORIZATION, authToken).set(HttpHeaders.CONTENT_TYPE, ContentTypes.Json)).set(Remote.Spec.Serializer, Serializer.Name.json);
    if (!Json.isNullOrEmpty(definition)) {
        oEntity.set(Remote.Spec.Data, definition);
    }
    remote.put(oEntity, new Remote.Callback() {

        @Override
        public void onSuccess(int code, Object data) {
            if (data != null) {
                result.putAll((JsonObject) data);
            }
        }

        @Override
        public void onError(int code, Object message) {
            error.set(code, message);
        }
    });
    if (error.happened()) {
        throw new IndexerException("Error occured while calling Indexer: Code=" + error.code + ", Message: " + error.message);
    }
    return result;
}
Also used : JsonObject(com.bluenimble.platform.json.JsonObject) Remote(com.bluenimble.platform.remote.Remote) IndexerException(com.bluenimble.platform.indexer.IndexerException) JsonObject(com.bluenimble.platform.json.JsonObject)

Aggregations

IndexerException (com.bluenimble.platform.indexer.IndexerException)9 JsonObject (com.bluenimble.platform.json.JsonObject)9 Remote (com.bluenimble.platform.remote.Remote)8 Indexer (com.bluenimble.platform.indexer.Indexer)1 Date (java.util.Date)1