Search in sources :

Example 6 with Answer

use of life.genny.qwanda.Answer 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 7 with Answer

use of life.genny.qwanda.Answer in project rulesservice by genny-project.

the class QRules method processImageUpload.

public void processImageUpload(QDataAnswerMessage m, final String finalAttributeCode) {
    /* we save the first photo as the icon of the BaseEntity */
    Answer[] answers = m.getItems();
    if (answers.length > 0) {
        Answer answer = answers[0];
        String sourceCode = answer.getSourceCode();
        String targetCode = answer.getTargetCode();
        answer.setSourceCode(answer.getTargetCode());
        String value = answer.getValue();
        if (value != null) {
            JsonArray imagesJson = new JsonArray(value);
            if (imagesJson != null) {
                JsonObject firstImage = imagesJson.getJsonObject(0);
                if (firstImage != null) {
                    this.println(firstImage);
                    String jsonStringImage = firstImage.getString("uploadURL");
                    this.updateBaseEntityAttribute(sourceCode, targetCode, finalAttributeCode, jsonStringImage);
                }
            }
        }
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Answer(life.genny.qwanda.Answer) JsonObject(io.vertx.core.json.JsonObject)

Example 8 with Answer

use of life.genny.qwanda.Answer in project rulesservice by genny-project.

the class QRules method processLoadTypeAnswer.

public void processLoadTypeAnswer(QEventAttributeValueChangeMessage m) {
    /* Collect load code from answer */
    Answer answer = m.getAnswer();
    println("The created value  ::  " + answer.getCreatedDate());
    println("Answer from QEventAttributeValueChangeMessage  ::  " + answer.toString());
    String targetCode = answer.getTargetCode();
    String sourceCode = answer.getSourceCode();
    String loadCategoryCode = answer.getValue();
    String attributeCode = m.data.getCode();
    println("The target BE code is   ::  " + targetCode);
    println("The source BE code is   ::  " + sourceCode);
    println("The attribute code is   ::  " + attributeCode);
    println("The load type code is   ::  " + loadCategoryCode);
    // no attributes
    BaseEntity loadType = getBaseEntityByCode(loadCategoryCode, false);
    /* creating new Answer */
    Answer newAnswer = new Answer(answer.getSourceCode(), answer.getTargetCode(), "PRI_LOAD_TYPE", loadType.getName());
    newAnswer.setInferred(true);
    saveAnswer(newAnswer);
}
Also used : Answer(life.genny.qwanda.Answer) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Example 9 with Answer

use of life.genny.qwanda.Answer in project rulesservice by genny-project.

the class QRules method sendMobileVerificationPasscode.

/* Send Mobile Verification Code */
public void sendMobileVerificationPasscode(final String userCode) {
    String[] recipients = { userCode };
    String verificationCode = generateVerificationCode();
    // println("The verification code is ::"+verificationCode);
    Answer verificationCodeAns = new Answer(userCode, userCode, "PRI_VERIFICATION_CODE", verificationCode);
    saveAnswer(verificationCodeAns);
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put("USER", userCode);
    println("The String Array is ::" + Arrays.toString(recipients));
    /* Sending sms message to user */
    sendMessage("", recipients, contextMap, "GNY_USER_VERIFICATION", "SMS");
}
Also used : Answer(life.genny.qwanda.Answer) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 10 with Answer

use of life.genny.qwanda.Answer in project rulesservice by genny-project.

the class QRules method updateCachedBaseEntity.

public BaseEntity updateCachedBaseEntity(final List<Answer> answers) {
    Answer firstanswer = null;
    if (answers != null) {
        if (!answers.isEmpty()) {
            firstanswer = answers.get(0);
        }
    }
    BaseEntity cachedBe = null;
    if (firstanswer != null) {
        cachedBe = this.getBaseEntityByCodeWithAttributes(firstanswer.getTargetCode());
    } else {
        return null;
    }
    for (Answer answer : answers) {
        // Add an attribute if not already there
        try {
            answer.setAttribute(RulesUtils.attributeMap.get(answer.getAttributeCode()));
            if (answer.getAttribute() == null) {
                log.error("Null Attribute");
            } else
                cachedBe.addAnswer(answer);
        } catch (BadDataException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    VertxUtils.writeCachedJson(cachedBe.getCode(), JsonUtils.toJson(cachedBe));
    return cachedBe;
}
Also used : Answer(life.genny.qwanda.Answer) BadDataException(life.genny.qwanda.exception.BadDataException) BaseEntity(life.genny.qwanda.entity.BaseEntity)

Aggregations

Answer (life.genny.qwanda.Answer)16 BaseEntity (life.genny.qwanda.entity.BaseEntity)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 IOException (java.io.IOException)4 JsonObject (io.vertx.core.json.JsonObject)2 AttributeMoney (life.genny.qwanda.attribute.AttributeMoney)2 EntityAttribute (life.genny.qwanda.attribute.EntityAttribute)2 BadDataException (life.genny.qwanda.exception.BadDataException)2 QDataAnswerMessage (life.genny.qwanda.message.QDataAnswerMessage)2 Money (org.javamoney.moneta.Money)2 JsonArray (io.vertx.core.json.JsonArray)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 GPS (life.genny.qwanda.GPS)1 Link (life.genny.qwanda.Link)1 AttributeBoolean (life.genny.qwanda.attribute.AttributeBoolean)1