use of life.genny.qwanda.Link in project rulesservice by genny-project.
the class QRules method getChildren.
/*
* Get children of the source code with the linkcode and linkValue
*/
public BaseEntity getChildren(final String sourceCode, final String linkCode, final String linkValue) {
try {
String beJson = QwandaUtils.apiGet(getQwandaServiceUrl() + "/qwanda/entityentitys/" + sourceCode + "/linkcodes/" + linkCode + "/children/" + linkValue, getToken());
Link[] linkArray = RulesUtils.fromJson(beJson, Link[].class);
if (linkArray.length > 0) {
ArrayList<Link> arrayList = new ArrayList<Link>(Arrays.asList(linkArray));
Link first = arrayList.get(0);
RulesUtils.println("The Child BaseEnity code is :: " + first.getTargetCode());
return RulesUtils.getBaseEntityByCode(getQwandaServiceUrl(), getDecodedTokenMap(), getToken(), first.getTargetCode(), false);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of life.genny.qwanda.Link in project rulesservice by genny-project.
the class QRules method triggerEmailForJobUpdate.
public void triggerEmailForJobUpdate(String jobCode) {
println("Job is already submitted, so the job is getting edited");
List<Link> links = getLinks(jobCode, "LNK_BEG");
List<String> offerList = new ArrayList<String>();
String ownerCode = null;
if (links != null) {
for (Link link : links) {
String linkValue = link.getLinkValue();
if (linkValue != null && linkValue.equals("OFFER")) {
offerList.add(link.getTargetCode());
}
if (linkValue != null && linkValue.equals("OWNER")) {
ownerCode = link.getTargetCode();
}
}
}
String[] recipientArr = new String[offerList.size()];
int i = 0;
for (String offer : offerList) {
BaseEntity offerBe = getBaseEntityByCode(offer);
String quoterCode = offerBe.getValue("PRI_QUOTER_CODE", null);
recipientArr[i] = quoterCode;
i++;
}
println("recipient array for edit job details email :" + Arrays.toString(recipientArr));
println("owner code ::" + ownerCode);
HashMap<String, String> contextMap = new HashMap<String, String>();
contextMap.put("JOB", jobCode);
contextMap.put("OWNER", ownerCode);
sendMessage("", recipientArr, contextMap, "MSG_CH40_JOB_EDITED", "EMAIL");
}
use of life.genny.qwanda.Link 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();
}
use of life.genny.qwanda.Link in project rulesservice by genny-project.
the class QRules method createLink.
public Link createLink(String groupCode, String targetCode, String linkCode, String linkValue, Double weight) {
log.info("CREATING LINK between " + groupCode + "and" + targetCode + "with LINK VALUE = " + linkValue);
Link link = new Link(groupCode, targetCode, linkCode, linkValue);
link.setWeight(weight);
try {
QwandaUtils.apiPostEntity(qwandaServiceUrl + "/qwanda/entityentitys", RulesUtils.toJson(link), getToken());
} catch (IOException e) {
e.printStackTrace();
}
return link;
}
use of life.genny.qwanda.Link 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");
}
}
Aggregations