Search in sources :

Example 1 with QDataAttributeMessage

use of life.genny.qwanda.message.QDataAttributeMessage in project rulesservice by genny-project.

the class QRules method sendAllAttributes.

/*
	 * Gets all the attributes and Publishes to the DATA channel
	 */
public void sendAllAttributes() {
    println("Sending all the attributes");
    try {
        QDataAttributeMessage msg = RulesUtils.loadAllAttributesIntoCache(getToken());
        publishData(msg);
        println("All the attributes sent");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : QDataAttributeMessage(life.genny.qwanda.message.QDataAttributeMessage) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadDataException(life.genny.qwanda.exception.BadDataException) ParseException(org.json.simple.parser.ParseException)

Example 2 with QDataAttributeMessage

use of life.genny.qwanda.message.QDataAttributeMessage in project rulesservice by genny-project.

the class RulesUtils method loadAllAttributesIntoCache.

public static QDataAttributeMessage loadAllAttributesIntoCache(final String token) {
    try {
        JsonObject json = VertxUtils.readCachedJson("attributes");
        if ("ok".equals(json.getString("status"))) {
            println("LOADING ATTRIBUTES FROM CACHE!");
            // VertxUtils.writeCachedJson("attributes", json.getString("value"));
            attributesMsg = JsonUtils.fromJson(json.getString("value"), QDataAttributeMessage.class);
            Attribute[] attributeArray = attributesMsg.getItems();
            for (Attribute attribute : attributeArray) {
                attributeMap.put(attribute.getCode(), attribute);
            }
            println("All the attributes have been loaded in " + attributeMap.size() + " attributes");
        } else {
            println("LOADING ATTRIBUTES FROM API");
            String jsonString = QwandaUtils.apiGet(qwandaServiceUrl + "/qwanda/attributes", token);
            VertxUtils.writeCachedJson("attributes", jsonString);
            attributesMsg = JsonUtils.fromJson(jsonString, QDataAttributeMessage.class);
            Attribute[] attributeArray = attributesMsg.getItems();
            for (Attribute attribute : attributeArray) {
                attributeMap.put(attribute.getCode(), attribute);
            }
            println("All the attributes have been loaded from api in" + attributeMap.size() + " attributes");
        }
        return attributesMsg;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Attribute(life.genny.qwanda.attribute.Attribute) JsonObject(io.vertx.core.json.JsonObject) QDataAttributeMessage(life.genny.qwanda.message.QDataAttributeMessage) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 QDataAttributeMessage (life.genny.qwanda.message.QDataAttributeMessage)2 JsonParseException (com.google.gson.JsonParseException)1 JsonObject (io.vertx.core.json.JsonObject)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Attribute (life.genny.qwanda.attribute.Attribute)1 BadDataException (life.genny.qwanda.exception.BadDataException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 ParseException (org.json.simple.parser.ParseException)1