Search in sources :

Example 21 with BaseEntity

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

the class QRules method publishCmd.

public void publishCmd(final List<BaseEntity> beList, final String parentCode, final String linkCode, String[] recipientCodes) {
    QDataBaseEntityMessage msg = new QDataBaseEntityMessage(beList.toArray(new BaseEntity[0]));
    msg.setParentCode(parentCode);
    msg.setLinkCode(linkCode);
    msg.setToken(getToken());
    if (recipientCodes != null) {
        msg.setRecipientCodeArray(recipientCodes);
    }
    publish("cmds", RulesUtils.toJsonObject(msg));
}
Also used : QDataBaseEntityMessage(life.genny.qwanda.message.QDataBaseEntityMessage) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Example 22 with BaseEntity

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

the class QRules method fireAttributeChanges.

public void fireAttributeChanges(QEventAttributeValueChangeMessage m) {
    Answer a = m.getAnswer();
    BaseEntity be = m.getBe();
    for (EntityAttribute ea : be.getBaseEntityAttributes()) {
        Answer pojo = new Answer(a.getSourceCode(), a.getTargetCode(), ea.getAttributeCode(), ea.getAsLoopString());
        pojo.setWeight(ea.getWeight());
        pojo.setInferred(ea.getInferred());
        pojo.setExpired(a.getExpired());
        pojo.setRefused(a.getRefused());
        // pojo.setAskId(answer.getAskId());
        QEventAttributeValueChangeMessage msg = new QEventAttributeValueChangeMessage(pojo, m.getOldValue(), m.getToken());
        msg.getData().setCode(ea.getAttributeCode());
        msg.getData().setId(-1L);
        msg.setBe(be);
        publish("events", JsonUtils.toJson(msg));
    }
}
Also used : Answer(life.genny.qwanda.Answer) EntityAttribute(life.genny.qwanda.attribute.EntityAttribute) QEventAttributeValueChangeMessage(life.genny.qwanda.message.QEventAttributeValueChangeMessage) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Example 23 with BaseEntity

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

the class QRules method getBaseEntityValueAsLocalDateTime.

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

Example 24 with BaseEntity

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

the class QRules method getBaseEntityValue.

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

Example 25 with BaseEntity

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

the class RulesUtils method getBaseEntitysByAttributeAndValue.

/**
 * @param qwandaServiceUrl
 * @param decodedToken
 * @param token
 * @return baseEntity user for the decodedToken passed
 */
public static List<BaseEntity> getBaseEntitysByAttributeAndValue(final String qwandaServiceUrl, Map<String, Object> decodedToken, final String token, final String attributeCode, final String value) {
    String beJson = getBaseEntityJsonByAttributeAndValue(qwandaServiceUrl, decodedToken, token, attributeCode, value, 1000);
    QDataBaseEntityMessage be = fromJson(beJson, QDataBaseEntityMessage.class);
    List<BaseEntity> items = null;
    try {
        items = new ArrayList<BaseEntity>(Arrays.asList(be.getItems()));
    } catch (Exception e) {
        println("Error: items is null");
    }
    return items;
}
Also used : QDataBaseEntityMessage(life.genny.qwanda.message.QDataBaseEntityMessage) BaseEntity(life.genny.qwanda.entity.BaseEntity) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

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