how to get jbpm output variable? - drools

I created the bpmn project and deployed it to the kieserver,how can I use the rest api of kieserver to call and obtain output variables ?
I have defined process variable in bpmn, but after calling and executing bpmn, I cannot get the process variable in the returned results.
The following are the request message and response message I called
Please help to see if there is a problem with the calling method or parameters
Url: http://127.0.0.1:8080/kie-server/services/rest/server/containers/instances/YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT
Request:
{
"commands":[
{
"set-global" : {
"identifier" : "output",
"object" : {
"com.ygdpostloan.OutputVariable" : {
"finalDecisionFlag" : "xxx",
"targetBehaviorStatus" : null
}
},
"out-identifier" : "output"
}
},
{
"start-process" : {
"processId" : "YgdPostLoanFinalResultProcess",
"data" : null,
"agendaFilter" : null,
"parameter" : [
{
"value" : {
"com.ygdpostloan.InputVariable":{
"sysCode" : "jyd",
"flagBQS" : null,
"flagRH" : null,
"flagXDXWJT" : null,
"resultBQS" : null,
"resultRH" : null,
"resultXDXWJT" : 3
}
},
"key" : "input"
}
],
"out-identifier" : "input"
}
}
]
}
Response:
{
"type" : "SUCCESS",
"msg" : "Container YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT successfully called.",
"result" : {
"execution-results" : {
"results" : [ {
"value" : {"com.ygdpostloan.OutputVariable":{
"finalDecisionFlag" : "xxx",
"targetBehaviorStatus" : null
}},
"key" : "output"
}, {
"value" : 13,
"key" : "input"
} ],
"facts" : [ ]
}
}
}
I receive result data through global variable , but I'm not sure whether this method is reasonable. I want to try to receive results through process variable
Variables alse cannot be obtained through the kie server client api
public static void main(String[] args) {
KieServices kieServices = KieServices.Factory.get();
CredentialsProvider credentialsProvider = new EnteredCredentialsProvider("kieserver", "kieserver");
KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration("http://127.0.0.18080/kie-server/services/rest/server", credentialsProvider);
// Set the Marshaling Format to JSON. Other options are JAXB and XSTREAM
kieServicesConfig.setMarshallingFormat(MarshallingFormat.JSON);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
QueryServicesClient queryServicesClient = kieServicesClient.getServicesClient(QueryServicesClient.class);
List<ProcessDefinition> processes = queryServicesClient.findProcesses(0, 10);
System.out.println(processes);
// Retrieve the RuleServices Client.
ProcessServicesClient processServicesClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
ProcessDefinition processDefinition = processServicesClient.getProcessDefinition("YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT", "YgdPostLoanFinalResultProcess");
System.out.println(processDefinition);
Map<String, Object> inputMap = new HashMap<>();
Map<String, Object> intParamMap = new HashMap<>();
intParamMap.put("resultXDXWJT", 3);
intParamMap.put("sysCode", "111");
Map<String, Object> processParamMap = new HashMap<>();
InputVariable inputVariable = new InputVariable();
inputVariable.setResultXDXWJT(3);
inputVariable.setSysCode("111");
inputMap.put("com.ygdpostloan.InputVariable", inputVariable);
processParamMap.put("input", inputMap);
Long instanceId = processServicesClient.startProcess("YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT", "YgdPostLoanFinalResultProcess", processParamMap);
System.out.println(instanceId);
ProcessInstance processInstance1 = processServicesClient.getProcessInstance("YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT", instanceId, true);
System.out.println(processInstance1);
//Map<String, Object> processInstanceVariables = processServicesClient.getProcessInstanceVariables("YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT", instanceId);
//System.out.println(processInstanceVariables);
List<NodeInstance> completedNodeInstances = queryServicesClient.findCompletedNodeInstances(instanceId, 0, 10);
System.out.println(completedNodeInstances);
//Map<String, Object> processInstanceVariables = processServicesClient.getProcessInstanceVariables("YgdPostLoanFinalResultDemo_1.0.0-SNAPSHOT", instanceId);
ProcessInstance processInstance = queryServicesClient.findProcessInstanceById(instanceId);
System.out.println(processInstance);
Map<String, Object> variables = processInstance.getVariables();
System.out.println(variables); // return null
}

Related

ElasticsearchRestTemplate can't save multiple documents to different index

I have a test domain class
public class TestDocument {
private final String id;
private final String strField;
private final Integer intField;
public TestDocument(final String id, final String strField, final Integer intField) {
this.id = id;
this.strField = strField;
this.intField = intField;
}
}
now I invoke ElasticsearchRestTemplate.save method with 3 documents and want to save into 3 different indices.
#Service
public class TestEsService {
#Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;
#PostConstruct
public void testSave() {
final TestDocument d1 = new TestDocument("id_1", "str1", 1);
final TestDocument d2 = new TestDocument("id_2", "str2", 2);
final TestDocument d3 = new TestDocument("id_3", "str3", 3);
this.save(List.of(d1, d2, d3));
}
public void save(final List<TestDocument> documents) {
final IndexCoordinates indexCoordinates = IndexCoordinates.of("index_1", "index_2", "index_3");
this.elasticsearchRestTemplate.save(documents, indexCoordinates);
}
}
After executed above code. I check my local elasticsearch.
curl -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?pretty' -s
I got only one index in my ES.
yellow open index_1 17ppJ9vJRUGIVHYBKKxXog 1 1 3 0 5.5kb 5.5kb
and check the data of this index_1 index:
curl 'http://localhost:9200/index_1/_search?pretty'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "index_1",
"_type" : "_doc",
"_id" : "id_1",
"_score" : 1.0,
"_source" : {
"_class" : "com.test.entity.TestDocument",
"id" : "id_1",
"strField" : "str1",
"intField" : 1
}
},
{
"_index" : "index_1",
"_type" : "_doc",
"_id" : "id_2",
"_score" : 1.0,
"_source" : {
"_class" : "com.test.entity.TestDocument",
"id" : "id_2",
"strField" : "str2",
"intField" : 2
}
},
{
"_index" : "index_1",
"_type" : "_doc",
"_id" : "id_3",
"_score" : 1.0,
"_source" : {
"_class" : "com.test.entity.TestDocument",
"id" : "id_3",
"strField" : "str3",
"intField" : 3
}
}
]
}
}
after dive into the code:
I found a clue within RequestFactory.bulkRequest:
queries.forEach(query -> {
if (query instanceof IndexQuery) {
bulkRequest.add(indexRequest((IndexQuery) query, index));
} else if (query instanceof UpdateQuery) {
bulkRequest.add(updateRequest((UpdateQuery) query, index));
}
});
actually IndexRequest() gets index name via index.getIndexName(); method:
public IndexRequest indexRequest(IndexQuery query, IndexCoordinates index) {
String indexName = index.getIndexName();
IndexRequest indexRequest;
where IndexCoordinates.getIndexName() return the first index name only.
public String getIndexName() {
return indexNames[0];
}
Is it a bug? Should I report to spring-data-elasticsearch Github issue?
Multiple names in IndexCoordinates are used when accessing an Elasticsearch API that uses multiple index names, for example when searching data in multiple indices, but not for writing access.
If you want to save the 3 entities to 3 indices, you need 3 calls with different IndexCoordinates - each of these having one index name.

Getting the ArrayOfObjects value in MongoDb with java driver

I need to compare the requestParam system and Email Systems system ,if both are equal ,result value should be feteched based that system
{
"_id" : ObjectId("5f0890e870e631865877e"),
"user" : "testuser",
"Email" : "testuser#sample.com",
"Batch Systems" : [
"STAR",
"STORY",
"ITEMS",
],
"Email Systems" : [
{
"Bob" : {
"System" : "Bob",
**"result"** : true
}
},
{
"Wild" : {
"System" : "Wild",
"result" : true
}
},
{
"CRaft" : {
"System" : "Craft",
"result" : false
}
}
]
}
public Object getDetails(#RequestParam(value = "system") String userId,
MongoDatabase database = this.mongoClient.getDatabase(this.database);
MongoCollection<Document> users = database.getCollection(users);
String searchString = new String(sourceSystem);
Document matchDoc = new Document("$Email Systems.Bob.System",searchString);
Document projectDoc = new Document("$Email Systems","EmailSystem");
AggregateIterable<Document> aggregateIterable = users.aggregate(Arrays.asList( new Document("$match", matchDoc)));
Iterator iterator = aggregateIterable.iterator();
ArrayList<Document> documents = new ArrayList();
while (iterator.hasNext()) {
boolean doc = documents.add((Document) iterator.next());
About Code is giving results [Document{{Bob=Document{{System=Bob, result=true}}}}, Document{{Wild=Document{{System=Wild, result=true}}}}]
I am not able to get the Bob result value and it should be compared with the request param system .Can anyone help me the way to get the Bob result value based on above output

dslContract generated from spring restdocs not working with queryParameters

When i create dslcontracts in my restdoc test with query parameters, it creates the groovy contract file as well as stub file. But when i deploy the contract using #EnableStubRunnerServer, i can never get the query parameters to match.
I realized that the stub file is generated with request looking like:
"request" : {
"url" : "/search",
"method" : "GET",
"queryParameters" : {
"query" : {
"equalTo" : "friday"
}
}
}
However if i change the stub file to :
"request" : {
"urlPathPattern" : "/search",
"method" : "GET",
"queryParameters" : {
"query" : {
"equalTo" : "friday"
}
}
}
it seems to work. Is there a way to make this work?
Here is how i'm writing the test:
#Test
public void searchWithQuery() throws Exception {
Map<String, Object> param = new HashMap<>();
param.put("query", "equalTo(\"friday\")");
mockMvc.perform(get(SEARCH_PATH + "?query=friday"))
.andExpect(status().isOk())
.andDo(document("search-query",
dslContract(param)
));
}

ag-grid actualComparator error

i'm building an ag-Grid in Vue.js . I'm trying to set colDefs and dataRow dinamically, and all is ok but i've "actualComparator is not a function" error when i set a date filter.
coldefs are dinamics and i receive from json
colDefs:[
{
"field" : "field1",
"filter" : "text",
"headerName" : "Name",
"width" : 100},
{
"field" : "filed2",
"filter" : "text",
"headerName" : "Surname",
"width" : 80},
{
"field" : "date1",
"filter" : "agDateColumnFilter",
"filterParams" : {
"clearButton" : true,
"comparator" : "dateFilterComparator"
},
"headerName" : "Birth",
"width" : 150
}]
dateFieldComparator is a function inside the methods
dateFilterComparator(filterLocalDateAtMidnight, cellValue){
console.log("I'm here");
var dateAsString = cellValue;
if (dateAsString == null) return -1;
var dateParts = dateAsString.split("/");
var cellDate = new Date(Number(dateParts[2]), Number(dateParts[1]) - 1, Number(dateParts[0]));
if (filterLocalDateAtMidnight == cellDate) {
return 0;
}
else if (cellDate < filterLocalDateAtMidnight) {
return -1;
} else {
return 1;
}
}
The request for the json (dataRow + colDefs) is send on the beforeMount eventhook, ag-grid is showed correctly but when i try to set a filter on the date i receive the error above.
The Clear Filter button is showed but the comparator seems not initialized with my function dataParamComparator.
I've try to call the gridOptions.api.setColumnDefs() on the onReady but without success.
Regards
Davide

Project BsonDocument without querying a collection

How can I project one BsonDocument to new instance without querying a collection?
inputs: document: BsonDocument, fields: new string[] { "_id", "meta.name", "type" }
output: BsonDocument with only the above elements populated
Itch scratched
input
{
"_id" : ObjectId("58b454f40960a1788ef48ebc"),
"schema" : {
"id" : "asset",
"version" : {
"major" : 1,
"minor" : 0
}
},
"type" : "asset",
"meta" : {
"name" : "Most Amazing Product",
"type" : null,
"legacy" : {
"url" : "https://s3.amazonaws.com/bucket_name/guid"
}
},
"content" : {
"is_s3" : true,
"s3_bucket" : "bucket_name",
"s3_key" : "guid.doc",
"url" : "https://s3.amazonaws.com/guid.doc"
},
"modified-date" : ISODate("2017-08-09T15:25:57.972Z"),
"modified-by" : "api"
}
code
nuget: MongoDB.Driver 2.4.4
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.IO;
BsonDocument original = BsonDocument.Parse(#"{ ""_id"" : ObjectId(""58b454f40960a1788ef48ebc""), ""schema"" : { ""id"" : ""asset"", ""version"" : { ""major"" : 1, ""minor"" : 0 } }, ""type"" : ""asset"", ""meta"" : { ""name"" : ""Most Amazing Product"", ""type"" : null, ""legacy"" : { ""url"" : ""https://s3.amazonaws.com/bucket_name/guid"" } }, ""content"" : { ""is_s3"" : true, ""s3_bucket"" : ""bucket_name"", ""s3_key"" : ""guid.doc"", ""url"" : ""https://s3.amazonaws.com/guid.doc"" }, ""modified-date"" : ISODate(""2017-08-09T15:25:57.972Z""), ""modified-by"" : ""api"" }");
string[] fields = new[] { "_id", "meta.name", "type" };
BsonDocument projection = new BsonDocument();
foreach (var fieldName in fields)
{
BsonDocument source = original;
BsonDocument target = projection;
string[] parts = fieldName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
string currentName = parts[i];
if (i == parts.Length - 1)
{
if(source.Contains(currentName))
target[currentName] = source[currentName];
}
else
{
// Does the source have a current property at this level
if (source.Contains(currentName))
{
// first time this has been visited on target
if (target.Contains(currentName) == false)
{
target.Add(currentName, new BsonDocument());
}
source = source[currentName] as BsonDocument;
target = target[currentName] as BsonDocument;
}
else
{
// no need to go any further if the source doesn't have the property specified
break;
}
}
}
}
result
{
"_id" : ObjectId("58b454f40960a1788ef48ebc"),
"meta" : {
"name" : "Most Amazing Product"
},
"type" : "asset"
}