Search in sources :

Example 26 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity in project rulesservice by genny-project.

the class VertxUtils method readFromDDT.

public static BaseEntity readFromDDT(final String code, final String token) {
    BaseEntity be = null;
    JsonObject json = readCachedJson(code);
    if ("ok".equals(json.getString("status"))) {
        be = JsonUtils.fromJson(json.getString("value"), BaseEntity.class);
    } else {
        // fetch normally
        System.out.println("Cache MISS for " + code);
        try {
            // getBaseEntityByCodeWithAttributes
            be = QwandaUtils.getBaseEntityByCode(code, token);
        } catch (Exception e) {
            // Okay, this is bad. Usually the code is not in the database but in keycloak
            // So lets leave it to the rules to sort out... (new user)
            log.error("BE " + code + " is NOT IN CACHE OR DB " + e.getLocalizedMessage());
            return null;
        }
        if ((cachedEnabled) || (System.getenv("GENNY_DEV") != null)) {
            writeCachedJson(code, JsonUtils.toJson(be));
        }
    }
    return be;
}
Also used : BaseEntity(life.genny.qwanda.entity.BaseEntity) JsonObject(io.vertx.core.json.JsonObject)

Example 27 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity in project rulesservice by genny-project.

the class VertxUtils method readFromDDT.

public static BaseEntity readFromDDT(final String code, final boolean withAttributes, final String token) {
    BaseEntity be = null;
    JsonObject json = readCachedJson(code);
    if ("ok".equals(json.getString("status"))) {
        be = JsonUtils.fromJson(json.getString("value"), BaseEntity.class);
    } else {
        // fetch normally
        System.out.println("Cache MISS for " + code);
        try {
            if (withAttributes) {
                be = QwandaUtils.getBaseEntityByCodeWithAttributes(code, token);
            } else {
                be = QwandaUtils.getBaseEntityByCode(code, token);
            }
        } catch (Exception e) {
            // Okay, this is bad. Usually the code is not in the database but in keycloak
            // So lets leave it to the rules to sort out... (new user)
            log.error("BE " + code + " is NOT IN CACHE OR DB " + e.getLocalizedMessage());
            return null;
        }
        if ((cachedEnabled) || (System.getenv("GENNY_DEV") != null)) {
            writeCachedJson(code, JsonUtils.toJson(be));
        }
    }
    return be;
}
Also used : BaseEntity(life.genny.qwanda.entity.BaseEntity) JsonObject(io.vertx.core.json.JsonObject)

Example 28 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity in project rulesservice by genny-project.

the class VertxUtils method subscribe.

public static void subscribe(final String realm, final List<BaseEntity> watchList, final String userCode) {
    final String SUB = "SUB";
    // Subscribe to a code
    for (BaseEntity be : watchList) {
        Set<String> subscriberSet = getSetString(realm, SUB, be.getCode());
        subscriberSet.add(userCode);
        putSetString(realm, SUB, be.getCode(), subscriberSet);
    }
}
Also used : BaseEntity(life.genny.qwanda.entity.BaseEntity)

Example 29 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity in project rulesservice by genny-project.

the class QRules method getBaseEntityValueAsLocalDate.

public LocalDate getBaseEntityValueAsLocalDate(final String baseEntityCode, final String attributeCode) {
    BaseEntity be = getBaseEntityByCode(baseEntityCode);
    Optional<EntityAttribute> ea = be.findEntityAttribute(attributeCode);
    if (ea.isPresent()) {
        return ea.get().getValueDate();
    } else {
        return null;
    }
}
Also used : EntityAttribute(life.genny.qwanda.attribute.EntityAttribute) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Example 30 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity in project rulesservice by genny-project.

the class QRules method publishBaseEntityByCode.

public void publishBaseEntityByCode(final String be, final String parentCode, final String linkCode, final String[] recipientCodes) {
    BaseEntity item = getBaseEntityByCode(be);
    BaseEntity[] itemArray = new BaseEntity[1];
    itemArray[0] = item;
    QDataBaseEntityMessage msg = new QDataBaseEntityMessage(itemArray, parentCode, linkCode);
    msg.setRecipientCodeArray(recipientCodes);
    publishData(msg, recipientCodes);
}
Also used : QDataBaseEntityMessage(life.genny.qwanda.message.QDataBaseEntityMessage) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Aggregations

BaseEntity (life.genny.qwanda.entity.BaseEntity)54 QDataBaseEntityMessage (life.genny.qwanda.message.QDataBaseEntityMessage)13 ArrayList (java.util.ArrayList)11 JsonObject (io.vertx.core.json.JsonObject)9 Answer (life.genny.qwanda.Answer)8 EntityAttribute (life.genny.qwanda.attribute.EntityAttribute)8 BadDataException (life.genny.qwanda.exception.BadDataException)7 IOException (java.io.IOException)6 AttributeInteger (life.genny.qwanda.attribute.AttributeInteger)6 JsonArray (io.vertx.core.json.JsonArray)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 AttributeBoolean (life.genny.qwanda.attribute.AttributeBoolean)5 Link (life.genny.qwanda.Link)4 AttributeMoney (life.genny.qwanda.attribute.AttributeMoney)4 AttributeText (life.genny.qwanda.attribute.AttributeText)4 Money (org.javamoney.moneta.Money)3 HashSet (java.util.HashSet)2 List (java.util.List)2 JSONObject (org.json.simple.JSONObject)2