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));
}
}
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);
}
}
}
}
}
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);
}
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");
}
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;
}
Aggregations