Search in sources :

Example 36 with BaseEntity

use of life.genny.qwanda.entity.BaseEntity 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)

Example 37 with BaseEntity

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

the class QRules method sendAllDrivers.

// Search and send all the Drivers
public void sendAllDrivers(String searchBeCode) throws ClientProtocolException, IOException {
    println("Get All Drivers - The search BE is  :: " + searchBeCode);
    // createBaseEntityByCode2(searchBeCode,
    BaseEntity searchBE = new BaseEntity(searchBeCode, "Get All Drivers");
    // "Get All Users");
    JsonArray columnsArray = new JsonArray();
    JsonObject columns = new JsonObject();
    // if( getBaseEntityByCode(searchBeCode) == null ) {
    // searchBE = createBaseEntityByCode2(searchBeCode, "Get All Users");
    AttributeText attributeTextImage = new AttributeText("COL_PRI_IMAGE_URL", "Image");
    JsonObject image = new JsonObject();
    image.put("code", "PRI_IMAGE_URL");
    columnsArray.add(image);
    AttributeText attributeTextUserName = new AttributeText("COL_PRI_USERNAME", "User Name");
    JsonObject userName = new JsonObject();
    userName.put("code", "PRI_USERNAME");
    columnsArray.add(userName);
    AttributeText attributeTextFirstName = new AttributeText("COL_PRI_FIRSTNAME", "First Name");
    JsonObject firstName = new JsonObject();
    firstName.put("code", "PRI_FIRSTNAME");
    columnsArray.add(firstName);
    AttributeText attributeTextLastName = new AttributeText("COL_PRI_LASTNAME", "Last Name");
    JsonObject lastName = new JsonObject();
    lastName.put("code", "PRI_LASTNAME");
    columnsArray.add(lastName);
    AttributeText attributeTextMobile = new AttributeText("COL_PRI_MOBILE", "Mobile Number");
    JsonObject mobile = new JsonObject();
    mobile.put("code", "PRI_MOBILE");
    columnsArray.add(mobile);
    AttributeText attributeTextEmail = new AttributeText("COL_PRI_EMAIL", "Email");
    JsonObject email = new JsonObject();
    email.put("code", "PRI_EMAIL");
    columnsArray.add(email);
    println("The columnsArray is ::" + columnsArray);
    // Sort Attribute
    AttributeText attributeTextSortFirstName = new AttributeText("SRT_PRI_FIRSTNAME", "Sort By FirstName");
    AttributeBoolean attributeIsDriver = new AttributeBoolean("PRI_DRIVER", "=");
    // Pagination Attribute
    AttributeInteger attributePageStart = new AttributeInteger("SCH_PAGE_START", "PageStart");
    AttributeInteger attributePageSize = new AttributeInteger("SCH_PAGE_SIZE", "PageSize");
    try {
        searchBE.addAttribute(attributeTextImage, 10.0);
        searchBE.addAttribute(attributeTextUserName, 9.0);
        searchBE.addAttribute(attributeTextFirstName, 8.0);
        searchBE.addAttribute(attributeTextLastName, 7.0);
        searchBE.addAttribute(attributeTextMobile, 6.0);
        searchBE.addAttribute(attributeTextEmail, 5.0);
        searchBE.addAttribute(attributeTextSortFirstName, 4.0, "ASC");
        searchBE.addAttribute(attributeIsDriver, 3.0, "TRUE");
        searchBE.addAttribute(attributePageStart, 3.0, "0");
        searchBE.addAttribute(attributePageSize, 2.0, "20");
    } catch (BadDataException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // }else {
    // searchBE = getBaseEntityByCodeWithAttributes(searchBeCode);
    // }
    // println("The search BE is  :: " + JsonUtils.toJson(searchBE));
    String jsonSearchBE = JsonUtils.toJson(searchBE);
    String result = QwandaUtils.apiPostEntity(qwandaServiceUrl + "/qwanda/baseentitys/search", jsonSearchBE, getToken());
    System.out.println("The result   ::  " + result);
    publishData(new JsonObject(result));
    sendTableViewWithHeaders("SBE_GET_ALL_DRIVERS", columnsArray);
// sendCmdView("TABLE_VIEW", "SBE_GET_ALL_USERS" );
// publishCmd(result, grpCode, "LNK_CORE");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) BadDataException(life.genny.qwanda.exception.BadDataException) AttributeText(life.genny.qwanda.attribute.AttributeText) BaseEntity(life.genny.qwanda.entity.BaseEntity) AttributeBoolean(life.genny.qwanda.attribute.AttributeBoolean) JsonObject(io.vertx.core.json.JsonObject) AttributeInteger(life.genny.qwanda.attribute.AttributeInteger)

Example 38 with BaseEntity

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

the class QRules method sendAllUsers.

/* Search the text value in all jobs */
public void sendAllUsers(String searchBeCode) throws ClientProtocolException, IOException {
    println("Get All Users - The search BE is  :: " + searchBeCode);
    // createBaseEntityByCode2(searchBeCode,
    BaseEntity searchBE = new BaseEntity(searchBeCode, "Get All Users");
    // "Get All Users");
    JsonArray columnsArray = new JsonArray();
    JsonObject columns = new JsonObject();
    // if( getBaseEntityByCode(searchBeCode) == null ) {
    // searchBE = createBaseEntityByCode2(searchBeCode, "Get All Users");
    AttributeText attributeTextImage = new AttributeText("COL_PRI_IMAGE_URL", "Image");
    JsonObject image = new JsonObject();
    image.put("code", "PRI_IMAGE_URL");
    columnsArray.add(image);
    AttributeText attributeTextUserName = new AttributeText("COL_PRI_USERNAME", "User Name");
    JsonObject userName = new JsonObject();
    userName.put("code", "PRI_USERNAME");
    columnsArray.add(userName);
    AttributeText attributeTextFirstName = new AttributeText("COL_PRI_FIRSTNAME", "First Name");
    JsonObject firstName = new JsonObject();
    firstName.put("code", "PRI_FIRSTNAME");
    columnsArray.add(firstName);
    AttributeText attributeTextLastName = new AttributeText("COL_PRI_LASTNAME", "Last Name");
    JsonObject lastName = new JsonObject();
    lastName.put("code", "PRI_LASTNAME");
    columnsArray.add(lastName);
    AttributeText attributeTextMobile = new AttributeText("COL_PRI_MOBILE", "Mobile Number");
    JsonObject mobile = new JsonObject();
    mobile.put("code", "PRI_MOBILE");
    columnsArray.add(mobile);
    AttributeText attributeTextEmail = new AttributeText("COL_PRI_EMAIL", "Email");
    JsonObject email = new JsonObject();
    email.put("code", "PRI_EMAIL");
    columnsArray.add(email);
    println("The columnsArray is ::" + columnsArray);
    // Sort Attribute
    AttributeText attributeTextSortFirstName = new AttributeText("SRT_PRI_FIRSTNAME", "Sort By FirstName");
    // Pagination Attribute
    AttributeInteger attributePageStart = new AttributeInteger("SCH_PAGE_START", "PageStart");
    AttributeInteger attributePageSize = new AttributeInteger("SCH_PAGE_SIZE", "PageSize");
    try {
        searchBE.addAttribute(attributeTextImage, 10.0);
        searchBE.addAttribute(attributeTextUserName, 9.0);
        searchBE.addAttribute(attributeTextFirstName, 8.0);
        searchBE.addAttribute(attributeTextLastName, 7.0);
        searchBE.addAttribute(attributeTextMobile, 6.0);
        searchBE.addAttribute(attributeTextEmail, 5.0);
        searchBE.addAttribute(attributeTextSortFirstName, 4.0, "ASC");
        searchBE.addAttribute(attributePageStart, 3.0, "0");
        searchBE.addAttribute(attributePageSize, 2.0, "20");
    } catch (BadDataException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // }else {
    // searchBE = getBaseEntityByCodeWithAttributes(searchBeCode);
    // }
    println("The search BE is  :: " + searchBE);
    String jsonSearchBE = JsonUtils.toJson(searchBE);
    String result = QwandaUtils.apiPostEntity(qwandaServiceUrl + "/qwanda/baseentitys/search", jsonSearchBE, getToken());
    System.out.println("The result   ::  " + result);
    publishData(new JsonObject(result));
    sendTableViewWithHeaders("SBE_GET_ALL_USERS", columnsArray);
// sendCmdView("TABLE_VIEW", "SBE_GET_ALL_USERS" );
// publishCmd(result, grpCode, "LNK_CORE");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) BadDataException(life.genny.qwanda.exception.BadDataException) AttributeText(life.genny.qwanda.attribute.AttributeText) BaseEntity(life.genny.qwanda.entity.BaseEntity) JsonObject(io.vertx.core.json.JsonObject) AttributeInteger(life.genny.qwanda.attribute.AttributeInteger)

Example 39 with BaseEntity

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

the class QRules method sendAllLoads.

/* Get All the jobs */
public void sendAllLoads(String searchBeCode) throws ClientProtocolException, IOException {
    // println("Get all Loads - The search BE is :: "+searchBeCode );
    BaseEntity searchBE = new BaseEntity(searchBeCode, "Get All Loads");
    // BaseEntity searchBE;
    JsonArray columnsArray = new JsonArray();
    JsonObject columns = new JsonObject();
    // Creating attributes
    AttributeText attributeBECode = new AttributeText("PRI_CODE", "LIKE");
    JsonObject beCode = new JsonObject();
    beCode.put("code", "PRI_CODE");
    AttributeText attributeTextName = new AttributeText("COL_PRI_NAME", "Load Name");
    JsonObject name = new JsonObject();
    name.put("code", "PRI_NAME");
    columnsArray.add(name);
    AttributeText attributeTextJobId = new AttributeText("COL_PRI_JOB_ID", "Job ID");
    JsonObject description = new JsonObject();
    description.put("code", "PRI_JOB_ID");
    columnsArray.add(description);
    AttributeText attributeTextPickupAddress = new AttributeText("COL_PRI_PICKUP_ADDRESS_FULL", "Pickup Address");
    JsonObject pickUpAddress = new JsonObject();
    pickUpAddress.put("code", "PRI_PICKUP_ADDRESS_FULL");
    columnsArray.add(pickUpAddress);
    AttributeMoney attributeDescription = new AttributeMoney("COL_PRI_DESCRIPTION", "Description");
    JsonObject ownerPrice = new JsonObject();
    ownerPrice.put("code", "PRI_DESCRIPTION");
    columnsArray.add(ownerPrice);
    // Sort Attribute
    AttributeText attributeTextSortName = new AttributeText("SRT_PRI_NAME", "Sort By Name");
    // Pagination Attribute
    AttributeInteger attributePageStart = new AttributeInteger("SCH_PAGE_START", "PageStart");
    AttributeInteger attributePageSize = new AttributeInteger("SCH_PAGE_SIZE", "PageSize");
    try {
        searchBE.addAttribute(attributeBECode, 10.0, "BEG_%%");
        searchBE.addAttribute(attributeTextName, 9.0);
        searchBE.addAttribute(attributeTextJobId, 8.0);
        searchBE.addAttribute(attributeTextPickupAddress, 7.0);
        // searchBE.addAttribute(attributeTextDropOffAddress, 6.0);
        searchBE.addAttribute(attributeDescription, 5.0);
        // searchBE.addAttribute(attributeDriverPrice, 4.0);
        searchBE.addAttribute(attributeTextSortName, 3.0, "ASC");
        searchBE.addAttribute(attributePageStart, 2.0, "0");
        searchBE.addAttribute(attributePageSize, 1.0, "500");
    } catch (BadDataException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // println("The search BE is :: "+JsonUtils.toJson(searchBE));
    String jsonSearchBE = JsonUtils.toJson(searchBE);
    String loadsList = QwandaUtils.apiPostEntity(qwandaServiceUrl + "/qwanda/baseentitys/search", jsonSearchBE, getToken());
    // System.out.println("The result :: "+loadsList);
    publishData(new JsonObject(loadsList));
    sendTableViewWithHeaders("SBE_GET_ALL_LOADS", columnsArray);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) BadDataException(life.genny.qwanda.exception.BadDataException) AttributeText(life.genny.qwanda.attribute.AttributeText) BaseEntity(life.genny.qwanda.entity.BaseEntity) JsonObject(io.vertx.core.json.JsonObject) AttributeMoney(life.genny.qwanda.attribute.AttributeMoney) AttributeInteger(life.genny.qwanda.attribute.AttributeInteger)

Example 40 with BaseEntity

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

the class QRules method getBaseEntityByAttributeAndValue.

public BaseEntity getBaseEntityByAttributeAndValue(final String attributeCode, final String value) {
    BaseEntity be = null;
    be = RulesUtils.getBaseEntityByAttributeAndValue(qwandaServiceUrl, getDecodedTokenMap(), getToken(), attributeCode, value);
    addAttributes(be);
    return be;
}
Also used : BaseEntity(life.genny.qwanda.entity.BaseEntity)

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