use of life.genny.qwanda.attribute.Attribute in project rulesservice by genny-project.
the class QRules method addAttributes.
public void addAttributes(BaseEntity be) {
for (EntityAttribute ea : be.getBaseEntityAttributes()) {
if (ea != null) {
Attribute attribute = RulesUtils.attributeMap.get(ea.getAttributeCode());
if (attribute != null) {
ea.setAttribute(attribute);
} else {
RulesUtils.loadAllAttributesIntoCache(getToken());
attribute = RulesUtils.attributeMap.get(ea.getAttributeCode());
if (attribute != null) {
ea.setAttribute(attribute);
} else {
log.error("Cannot get Attribute - " + ea.getAttributeCode());
Attribute dummy = new AttributeText(ea.getAttributeCode(), ea.getAttributeCode());
ea.setAttribute(dummy);
}
}
}
}
}
use of life.genny.qwanda.attribute.Attribute 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;
}
Aggregations