Search in sources :

Example 1 with QEventLinkChangeMessage

use of life.genny.qwanda.message.QEventLinkChangeMessage in project rulesservice by genny-project.

the class RuleTest method bucket_view_drag_drop_test.

// @Test
public void bucket_view_drag_drop_test() {
    System.out.println("Hello");
    final Map<String, String> keyValue = new HashMap<String, String>();
    // final Keycloak kc = KeycloakBuilder.builder()
    // .serverUrl("http://10.1.120.89:8180/auth")
    // .realm("genny")
    // .username("user1")
    // .password("password1")
    // .clientId("curl")
    // .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
    // .build();
    // String token = kc.tokenManager().getAccessToken().getToken();
    // String token1 = kc.tokenManager().getAccessTokenString();
    // System.out.println("The token is: "+token);
    // System.out.println("The token is: "+token1);
    Link link = new Link("GRP_QUOTES", "GRP_COMPLETED", "BEG_0000002", "LNK_CORE", null);
    QEventLinkChangeMessage evtMsg = new QEventLinkChangeMessage(link, null, "TEST");
    keyValue.put("token", "DUMB TOKEN");
    kSession.insert(keyValue);
    kSession.insert(evtMsg);
    kSession.fireAllRules();
}
Also used : QEventLinkChangeMessage(life.genny.qwanda.message.QEventLinkChangeMessage) HashMap(java.util.HashMap) Link(life.genny.qwanda.Link)

Example 2 with QEventLinkChangeMessage

use of life.genny.qwanda.message.QEventLinkChangeMessage in project rulesservice by genny-project.

the class QRules method saveJob.

public void saveJob(BaseEntity job) {
    String jobCode = job.getCode();
    /*
		 * We create a new attribute "PRI_TOTAL_DISTANCE" for this BEG. TODO: should be
		 * triggered in another rule
		 */
    Double pickupLatitude = job.getValue("PRI_PICKUP_ADDRESS_LATITUDE", 0.0);
    Double pickupLongitude = job.getValue("PRI_PICKUP_ADDRESS_LONGITUDE", 0.0);
    Double deliveryLatitude = job.getValue("PRI_DROPOFF_ADDRESS_LATITUDE", 0.0);
    Double deliveryLongitude = job.getValue("PRI_DROPOFF_ADDRESS_LONGITUDE", 0.0);
    /* Add author to the load */
    List<Answer> answers = new ArrayList<Answer>();
    answers.add(new Answer(getUser().getCode(), jobCode, "PRI_POSITION_LATITUDE", pickupLatitude + ""));
    answers.add(new Answer(getUser().getCode(), jobCode, "PRI_POSITION_LONGITUDE", pickupLongitude + ""));
    Double totalDistance = GPSUtils.getDistance(pickupLatitude, pickupLongitude, deliveryLatitude, deliveryLongitude);
    if (totalDistance > 0) {
        Answer totalDistanceAnswer = new Answer(jobCode, jobCode, "PRI_TOTAL_DISTANCE_M", totalDistance + "");
        answers.add(totalDistanceAnswer);
    }
    /* Adding Offer Count to 0 */
    Answer offerCountAns = new Answer(getUser().getCode(), jobCode, "PRI_OFFER_COUNT", "0");
    /* Publish Answer */
    answers.add(offerCountAns);
    /* set Status of the job */
    answers.add(new Answer(getUser().getCode(), jobCode, "STA_STATUS", Status.NEEDS_NO_ACTION.value()));
    // Setting color to green for new jobs for both driver and owner
    /*
		 * answers.add(new Answer(getUser().getCode(), jobCode, "STA_" +
		 * getUser().getCode(), Status.NEEDS_NO_ACTION.value()));
		 */
    BaseEntity updatedJob = this.getBaseEntityByCode(job.getCode());
    Long jobId = updatedJob.getId();
    answers.add(new Answer(getUser().getCode(), jobCode, "PRI_JOB_ID", jobId + ""));
    saveAnswers(answers);
    /* Determine the recipient code */
    String[] recipientCodes = VertxUtils.getSubscribers(realm(), "GRP_NEW_ITEMS");
    println("Recipients for Job/Load " + Arrays.toString(recipientCodes));
    /*
		 * Send newly created job with its attributes to all drivers so that it exists
		 * before link change
		 */
    BaseEntity newJobDetails = getBaseEntityByCode(jobCode);
    println("The newly submitted Job details     ::     " + newJobDetails.toString());
    publishData(newJobDetails, recipientCodes);
    /* publishing to Owner */
    publishBE(newJobDetails);
    /* Moving the BEG */
    Link link = new Link("GRP_DRAFTS", jobCode, "LNK_CORE");
    try {
        String output = QwandaUtils.apiPostEntity(getQwandaServiceUrl() + "/qwanda/baseentitys/move/GRP_NEW_ITEMS", JsonUtils.toJson(link), getToken());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    /* Get the sourceCode(Company code) for this User */
    BaseEntity company = getParent(getUser().getCode(), "LNK_STAFF");
    /* link newly created Job to GRP_LOADS */
    BaseEntity load = getChildren(jobCode, "LNK_BEG", "LOAD");
    String loadCode = load.getCode();
    Link newLoadLinkToLoadList = QwandaUtils.createLink("GRP_LOADS", loadCode, "LNK_LOAD", company.getCode(), (double) 1, getToken());
    println("The load has been added to the GRP_LOADS ");
    /* SEND LOAD BE */
    /* Try sending different types of links to the frontend to get it to display */
    publishBaseEntityByCode(loadCode, jobCode, "LNK_BEG", recipientCodes);
    /* publishing to Owner */
    publishBE(getBaseEntityByCode(loadCode));
    QEventLinkChangeMessage msgLnkBegLoad = new QEventLinkChangeMessage(new Link(jobCode, load.getCode(), "LNK_BEG"), null, getToken());
    publishData(msgLnkBegLoad, recipientCodes);
    publishBaseEntityByCode(jobCode, "GRP_NEW_ITEMS", "LNK_CORE", recipientCodes);
    /* publishing to Owner */
    publishBE(getBaseEntityByCode(jobCode));
    if (!newJobDetails.getValue("PRI_JOB_IS_SUBMITTED", false)) {
        /* Sending Messages */
        println("new job");
        HashMap<String, String> contextMap = new HashMap<String, String>();
        contextMap.put("JOB", jobCode);
        contextMap.put("OWNER", getUser().getCode());
        println("The String Array is ::" + Arrays.toString(recipientCodes));
        /* Sending toast message to owner frontend */
        sendMessage("", recipientCodes, contextMap, "MSG_CH40_NEW_JOB_POSTED", "TOAST");
        /* Sending message to BEG OWNER */
        sendMessage("", recipientCodes, contextMap, "MSG_CH40_NEW_JOB_POSTED", "EMAIL");
    }
}
Also used : QEventLinkChangeMessage(life.genny.qwanda.message.QEventLinkChangeMessage) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BaseEntity(life.genny.qwanda.entity.BaseEntity) IOException(java.io.IOException) Answer(life.genny.qwanda.Answer) Link(life.genny.qwanda.Link)

Aggregations

HashMap (java.util.HashMap)2 Link (life.genny.qwanda.Link)2 QEventLinkChangeMessage (life.genny.qwanda.message.QEventLinkChangeMessage)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Answer (life.genny.qwanda.Answer)1 BaseEntity (life.genny.qwanda.entity.BaseEntity)1