Search in sources :

Example 1 with EntityAttribute

use of life.genny.qwanda.attribute.EntityAttribute in project rulesservice by genny-project.

the class QRules method clearBaseEntityAttr.

public void clearBaseEntityAttr(String userCode) {
    BaseEntity be = getBaseEntityByCode(userCode);
    println("be   ::   " + be);
    Set<EntityAttribute> attributes = be.getBaseEntityAttributes();
    println("Size all   ::   " + attributes.size());
    Set<EntityAttribute> removeAttributes = new HashSet<EntityAttribute>();
    for (EntityAttribute attribute : attributes) {
        switch(attribute.getAttributeCode()) {
            case ("PRI_UUID"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_FIRSTNAME"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_LASTNAME"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_EMAIL"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_USERNAME"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_KEYCLOAK_UUID"):
                removeAttributes.add(attribute);
                break;
            case ("PRI_FB_BASIC"):
                removeAttributes.add(attribute);
                break;
        }
    }
    println("before removing   ::   " + attributes.toString());
    println("Size toRemove   ::   " + removeAttributes.size());
    println("Removing attrs   ::   " + removeAttributes.toString());
    attributes.removeAll(removeAttributes);
    println("after removing   ::   " + attributes.toString());
    println("Size afterRemoved   ::   " + attributes.size());
    be.setBaseEntityAttributes(attributes);
    QDataBaseEntityMessage beMsg = new QDataBaseEntityMessage(be);
    beMsg.setDelete(true);
    publishData(beMsg);
}
Also used : QDataBaseEntityMessage(life.genny.qwanda.message.QDataBaseEntityMessage) EntityAttribute(life.genny.qwanda.attribute.EntityAttribute) BaseEntity(life.genny.qwanda.entity.BaseEntity) HashSet(java.util.HashSet)

Example 2 with EntityAttribute

use of life.genny.qwanda.attribute.EntityAttribute in project rulesservice by genny-project.

the class QRules method makePayment.

public void makePayment(QDataAnswerMessage m) {
    /* Save Payment-related answers as user/BEG attributes */
    String userCode = getUser().getCode();
    BaseEntity userBe = getBaseEntityByCode(userCode);
    String begCode = PaymentUtils.processPaymentAnswers(getQwandaServiceUrl(), m, getToken());
    String assemblyAuthKey = PaymentUtils.getAssemblyAuthKey();
    String assemblyId = userBe.getValue("PRI_ASSEMBLY_USER_ID", null);
    if (begCode != null && assemblyId != null) {
        /* GET beg Base Entity */
        BaseEntity beg = getBaseEntityByCode(begCode);
        String offerCode = beg.getLoopValue("STT_HOT_OFFER", null);
        if (offerCode != null) {
            /* Make payment */
            showLoading("Processing payment...");
            Boolean isMakePaymentSucceeded = PaymentUtils.makePayment(getQwandaServiceUrl(), offerCode, begCode, assemblyAuthKey, getToken());
            println("isMakePaymentSucceeded ::" + isMakePaymentSucceeded);
            /* GET offer Base Entity */
            BaseEntity offer = getBaseEntityByCode(offerCode);
            String quoterCode = offer.getLoopValue("PRI_QUOTER_CODE", null);
            if (!isMakePaymentSucceeded) {
                /* TOAST :: FAIL */
                println("Sending error toast since make payment failed");
                HashMap<String, String> contextMap = new HashMap<String, String>();
                contextMap.put("DRIVER", quoterCode);
                contextMap.put("JOB", begCode);
                contextMap.put("QUOTER", quoterCode);
                String[] recipientArr = { userCode };
                /* Need to display error toast if make payment fails */
                sendMessage(null, recipientArr, contextMap, "MSG_CH40_MAKE_PAYMENT_FAILED", "TOAST");
                /* sending cmd BUCKETVIEW */
                drools.setFocus("SendLayoutsAndData");
            }
            if (isMakePaymentSucceeded) {
                /* GET attributes of OFFER BE */
                Money offerPrice = offer.getLoopValue("PRI_OFFER_PRICE", null);
                Money ownerPriceExcGST = offer.getLoopValue("PRI_OFFER_OWNER_PRICE_EXC_GST", null);
                Money ownerPriceIncGST = offer.getLoopValue("PRI_OFFER_OWNER_PRICE_INC_GST", null);
                Money driverPriceExcGST = offer.getLoopValue("PRI_OFFER_DRIVER_PRICE_EXC_GST", null);
                Money driverPriceIncGST = offer.getLoopValue("PRI_OFFER_DRIVER_PRICE_INC_GST", null);
                Money feePriceExcGST = offer.getLoopValue("PRI_OFFER_FEE_EXC_GST", null);
                Money feePriceIncGST = offer.getLoopValue("PRI_OFFER_FEE_INC_GST", null);
                /* Update BEG's prices with offer's prices */
                /*
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_PRICE",
					 * QwandaUtils.getMoneyString(offerPrice)); updateBaseEntityAttribute(begCode,
					 * begCode, "PRI_OWNER_PRICE_EXC_GST",
					 * QwandaUtils.getMoneyString(ownerPriceExcGST));
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_OWNER_PRICE_INC_GST",
					 * QwandaUtils.getMoneyString(ownerPriceIncGST));
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_DRIVER_PRICE_EXC_GST",
					 * QwandaUtils.getMoneyString(driverPriceExcGST));
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_DRIVER_PRICE_INC_GST",
					 * QwandaUtils.getMoneyString(driverPriceIncGST));
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_FEE_EXC_GST",
					 * QwandaUtils.getMoneyString(feePriceExcGST));
					 * updateBaseEntityAttribute(begCode, begCode, "PRI_FEE_INC_GST",
					 * QwandaUtils.getMoneyString(feePriceIncGST));
					 */
                List<Answer> answers = new ArrayList<Answer>();
                answers.add(new Answer(begCode, begCode, "PRI_PRICE", QwandaUtils.getMoneyString(offerPrice)));
                answers.add(new Answer(begCode, begCode, "PRI_OWNER_PRICE_EXC_GST", QwandaUtils.getMoneyString(ownerPriceExcGST)));
                answers.add(new Answer(begCode, begCode, "PRI_OWNER_PRICE_INC_GST", QwandaUtils.getMoneyString(ownerPriceIncGST)));
                answers.add(new Answer(begCode, begCode, "PRI_DRIVER_PRICE_EXC_GST", QwandaUtils.getMoneyString(driverPriceExcGST)));
                answers.add(new Answer(begCode, begCode, "PRI_DRIVER_PRICE_INC_GST", QwandaUtils.getMoneyString(driverPriceIncGST)));
                answers.add(new Answer(begCode, begCode, "PRI_FEE_EXC_GST", QwandaUtils.getMoneyString(feePriceExcGST)));
                answers.add(new Answer(begCode, begCode, "PRI_FEE_INC_GST", QwandaUtils.getMoneyString(feePriceIncGST)));
                // fetch the job to ensure the cache has caught up
                BaseEntity begBe = null;
                try {
                    begBe = QwandaUtils.getBaseEntityByCode(begCode, getToken());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                /* Update BEG to have DRIVER_CODE as an attribute */
                answers.add(new Answer(begCode, begCode, "STT_IN_TRANSIT", quoterCode));
                saveAnswers(answers);
                /* TOAST :: SUCCESS */
                println("Sending success toast since make payment succeeded");
                HashMap<String, String> contextMap = new HashMap<String, String>();
                contextMap.put("DRIVER", quoterCode);
                contextMap.put("JOB", begCode);
                contextMap.put("QUOTER", quoterCode);
                contextMap.put("OFFER", offer.getCode());
                String[] recipientArr = { userCode };
                /* TOAST :: PAYMENT SUCCESS */
                sendMessage("", recipientArr, contextMap, "MSG_CH40_MAKE_PAYMENT_SUCCESS", "TOAST");
                // sendMessage("", recipientArr, contextMap, "MSG_CH40_CONFIRM_QUOTE_OWNER",
                // "TOAST");
                sendMessage("", recipientArr, contextMap, "MSG_CH40_CONFIRM_QUOTE_OWNER", "EMAIL");
                /* QUOTER config */
                HashMap<String, String> contextMapForDriver = new HashMap<String, String>();
                contextMapForDriver.put("JOB", begCode);
                contextMapForDriver.put("OWNER", userCode);
                contextMapForDriver.put("OFFER", offer.getCode());
                String[] recipientArrForDriver = { quoterCode };
                /* Sending messages to DRIVER - Email and sms enabled */
                sendMessage("", recipientArrForDriver, contextMapForDriver, "MSG_CH40_CONFIRM_QUOTE_DRIVER", "TOAST");
                sendMessage("", recipientArrForDriver, contextMapForDriver, "MSG_CH40_CONFIRM_QUOTE_DRIVER", "SMS");
                sendMessage("", recipientArrForDriver, contextMapForDriver, "MSG_CH40_CONFIRM_QUOTE_DRIVER", "EMAIL");
                /* Update link between BEG and OFFER to weight= 0 */
                // updateLink(begCode, offerCode, "LNK_BEG", "OFFER", 1.0);
                /* Allocate QUOTER as Driver */
                updateLink(begCode, quoterCode, "LNK_BEG", "DRIVER", 1.0);
                /* Update link between BEG and Accepted OFFER to weight= 100 */
                updateLink(begCode, offerCode, "LNK_BEG", "OFFER", 100.0);
                /* Set PRI_NEXT_ACTION to Disabled for all other Offers */
                // get all offers
                List<BaseEntity> offers = getAllChildrens(begCode, "LNK_BEG", "OFFER");
                println("All the Offers for the load " + begCode + " are: " + offers.toString());
                for (BaseEntity be : offers) {
                    if (!(be.getCode().equals(offerCode))) {
                        println("The BE is : " + be.getCode());
                        /* Update PRI_NEXT_ACTION to Disabled */
                        updateBaseEntityAttribute(getUser().getCode(), be.getCode(), "PRI_NEXT_ACTION", "DISABLED");
                    }
                }
                /* SEND (OFFER, QUOTER, BEG) BaseEntitys to recipients */
                String[] offerRecipients = VertxUtils.getSubscribers(realm(), offer.getCode());
                println("OFFER subscribers   ::   " + Arrays.toString(offerRecipients));
                publishBaseEntityByCode(userCode, begCode, "LNK_BEG", offerRecipients);
                /* OWNER */
                publishBaseEntityByCode(quoterCode, begCode, "LNK_BEG", offerRecipients);
                publishBaseEntityByCode(offerCode, begCode, "LNK_BEG", offerRecipients);
                publishBaseEntityByCode("GRP_NEW_ITEMS", begCode, "LNK_CORE", offerRecipients);
                /* Set progression of LOAD delivery to 0 */
                Answer updateProgressAnswer = new Answer(begCode, begCode, "PRI_PROGRESS", Double.toString(0.0));
                saveAnswer(updateProgressAnswer);
                /* We ask FE to monitor GPS */
                geofenceJob(begCode, getUser().getCode(), 10.0);
                /* GET all the driver subsribers */
                String[] begRecipients = VertxUtils.getSubscribers(realm(), "GRP_NEW_ITEMS");
                println("ALL BEG subscribers   ::   " + Arrays.toString(begRecipients));
                println("quoter code ::" + quoterCode);
                Set<String> unsubscribeSet = new HashSet<>();
                for (String begRecipient : begRecipients) {
                    if (!begRecipient.equals(quoterCode)) {
                        unsubscribeSet.add(begRecipient);
                    }
                }
                println("unsubscribe set ::" + unsubscribeSet);
                String[] unsubscribeArr = new String[unsubscribeSet.size()];
                int i = 0;
                for (String code : unsubscribeSet) {
                    unsubscribeArr[i++] = code;
                }
                println("unsubscribe arr ::" + Arrays.toString(unsubscribeArr));
                /* Move BEG to GRP_APPROVED */
                fastClearBaseEntity(begCode, unsubscribeArr);
                BaseEntity begbe = getBaseEntityByCode(begCode);
                println("be   ::   " + begbe);
                Set<EntityAttribute> attributes = begbe.getBaseEntityAttributes();
                begbe.setBaseEntityAttributes(attributes);
                QDataBaseEntityMessage beMsg = new QDataBaseEntityMessage(begbe);
                beMsg.setDelete(true);
                publishData(beMsg, unsubscribeArr);
                VertxUtils.unsubscribe(realm(), "GRP_NEW_ITEMS", unsubscribeSet);
                moveBaseEntity(begCode, "GRP_NEW_ITEMS", "GRP_APPROVED", "LNK_CORE");
                // publishBaseEntityByCode(begCode, "GRP_NEW_ITEMS", "LNK_CORE",
                // newbegRecipients);
                // publishBaseEntityByCode(begCode, "GRP_APPROVED", "LNK_CORE",
                // newbegRecipients);
                /* Update PRI_NEXT_ACTION = OWNER */
                Answer begNextAction = new Answer(userCode, offerCode, "PRI_NEXT_ACTION", "NONE");
                saveAnswer(begNextAction);
                /* Update the Job status */
                updateBaseEntityAttribute(getUser().getCode(), begCode, "STA_" + quoterCode, Status.NEEDS_ACTION.value());
                updateBaseEntityAttribute(getUser().getCode(), begCode, "STA_" + getUser().getCode(), Status.NEEDS_NO_ACTION.value());
                /* sending cmd BUCKETVIEW */
                drools.setFocus("SendLayoutsAndData");
            /*	List<BaseEntity> listBe = new ArrayList<>();
					listBe.add(getUser());
					listBe.add(getBaseEntityByCode(quoterCode));
					listBe.add(getBaseEntityByCode(offerCode));
					listBe.add(getBaseEntityByCode(begCode));

					publishCmd(listBe, "GRP_ROOT", "LNK_CORE");
					sendSublayout("BUCKET_DASHBOARD", "dashboard_channel40.json", "GRP_DASHBOARD");
					setLastLayout( "BUCKET_DASHBOARD", "GRP_DASHBOARD" );  */
            }
            setState("PAYMENT_DONE");
        }
    }
}
Also used : QDataBaseEntityMessage(life.genny.qwanda.message.QDataBaseEntityMessage) EntityAttribute(life.genny.qwanda.attribute.EntityAttribute) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BaseEntity(life.genny.qwanda.entity.BaseEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AttributeMoney(life.genny.qwanda.attribute.AttributeMoney) Money(org.javamoney.moneta.Money) Answer(life.genny.qwanda.Answer) AttributeBoolean(life.genny.qwanda.attribute.AttributeBoolean) HashSet(java.util.HashSet)

Example 3 with EntityAttribute

use of life.genny.qwanda.attribute.EntityAttribute 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 4 with EntityAttribute

use of life.genny.qwanda.attribute.EntityAttribute 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 5 with EntityAttribute

use of life.genny.qwanda.attribute.EntityAttribute 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)

Aggregations

EntityAttribute (life.genny.qwanda.attribute.EntityAttribute)9 BaseEntity (life.genny.qwanda.entity.BaseEntity)8 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Answer (life.genny.qwanda.Answer)2 QDataBaseEntityMessage (life.genny.qwanda.message.QDataBaseEntityMessage)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Attribute (life.genny.qwanda.attribute.Attribute)1 AttributeBoolean (life.genny.qwanda.attribute.AttributeBoolean)1 AttributeMoney (life.genny.qwanda.attribute.AttributeMoney)1 AttributeText (life.genny.qwanda.attribute.AttributeText)1 QEventAttributeValueChangeMessage (life.genny.qwanda.message.QEventAttributeValueChangeMessage)1 Money (org.javamoney.moneta.Money)1