Skip to content

Instantly share code, notes, and snippets.

@uchia-itachi
Created December 18, 2019 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchia-itachi/6c11b68a3a79c305c55733a770c7ac10 to your computer and use it in GitHub Desktop.
Save uchia-itachi/6c11b68a3a79c305c55733a770c7ac10 to your computer and use it in GitHub Desktop.
import com.myspace.*;
import org.kie.api.KieServices;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.internal.command.CommandFactory;
import org.kie.server.api.marshalling.MarshallingFormat;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
import org.kie.server.client.RuleServicesClient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class MAIN1 {
public static final String URL = "http://localhost:8080/kie-server/services/rest/server";
public static final String USER = "kieserver";
public static final String PASSWORD = "kieserver1!";
private static final MarshallingFormat FORMAT = MarshallingFormat.JSON;
private static String containerID = "Taxes";
private static String className = "com.myspace.TaxList";
public static TaxPayer person = new TaxPayer();
public static TaxList t = new TaxList();
public static void create(){
System.out.println("enter salary, age, hra , ta and sa in order");
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
String[] lines = line.trim().split("\\s+");
int[] arr = new int[5];
for(int i=0;i<5;i++)
arr[i] = Integer.parseInt(lines[i]);
person.setHra(arr[2]);
person.setSalary(arr[0]);
person.setSa(arr[4]);
person.setAge(arr[1]);
person.setTa(arr[3]);
}
public static void main(String[] args) throws InterruptedException {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(URL,USER,PASSWORD);
config.setMarshallingFormat(FORMAT);
RuleServicesClient client = KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
List<Command<?>> cmds = new ArrayList<Command<?>>();
KieCommands commands = KieServices.Factory.get().getCommands();
while(true){
create();
List<TaxPayer> payer = new ArrayList<>();
payer.add(person);
t.list.add((ArrayList) payer);
cmds.add(commands.newInsert(person,className));
cmds.add(commands.newFireAllRules());
BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds);
ServiceResponse<ExecutionResults> respone = client.executeCommandsWithResults(containerID, myCommands);
if(respone.getType() == ServiceResponse.ResponseType.SUCCESS){
System.out.println("sucessfully connected");
TaxList updatedPerson = (TaxList) respone.getResult().getValue(className);
System.out.println(updatedPerson.list);
}
else{
System.out.println("error in executing rules");
System.out.println(respone.getMsg());
}
TimeUnit.SECONDS.sleep(2);
}
}
}
package com.myspace;
import java.util.ArrayList;
import java.util.List;
public class TaxList {
public List<TaxReciever> receiverList = new ArrayList<>();
public List<TaxPayer> payerList = new ArrayList<>();
public List<ArrayList> list = new ArrayList<>();
public TaxList(List<TaxReciever> receiverList, List<TaxPayer> payerList, List<ArrayList> list) {
this.receiverList = receiverList;
this.payerList = payerList;
this.list = list;
}
public TaxList() {
}
public List<TaxReciever> getReceiverList() {
return receiverList;
}
public void setReceiverList(List<TaxReciever> receiverList) {
this.receiverList = receiverList;
}
public List<TaxPayer> getPayerList() {
return payerList;
}
public void setPayerList(List<TaxPayer> payerList) {
this.payerList = payerList;
}
public List<ArrayList> getList() {
return list;
}
public void setList(List<ArrayList> list) {
this.list = list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment