Drools - KIEServer inserted Object in then not showing in Reponse - drools

I have simple DRL rule
package drl;
//generated from Decision Table
import com.Location;
import com.LocationApproval;
// rule values at C12, header at C7
rule "Basic_12"
salience 65535
when
location: Location(city == "A")
then
insert(new LocationApproval(true,"20"));
end
// rule values at C13, header at C7
rule "Basic_13"
salience 65534
when
location: Location(city == "B")
then
insert(new LocationApproval(true,"10"));
end
Here is the code to execute rules KIE Server Execution
Location location = new Location();
location.setCity("A");
LocationApproval locationApproval = new LocationApproval();
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
List<Command> commandList = new ArrayList<Command>();
Command<?> insert = commandsFactory.newInsert(location, "LocationApproval");
Command<?> fireAllRules = commandsFactory.newFireAllRules();
Command<?> batchCommand = commandsFactory.newBatchExecution(Arrays.asList(insert, fireAllRules));
ServiceResponse<ExecutionResults> results = ruleServicesClient.executeCommandsWithResults("containerOD",
commandsFactory.newBatchExecution(Arrays.asList(insert, fireAllRules), "session"));
This does not return LocationApproval object
Output Response ::
{
"type" : "SUCCESS",
"msg" : "Container container successfully called.",
"result" : {
"execution-results" : {
"results" : [ {
"value" : [{"com.Location":{
"city" : "A"
}}],
"key" : "LocationApproval"
} ],
"facts" : [ ]
}
}
}
Kindly Help

Related

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

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

Meteor Methods insert not working (mongodb)

I am trying to write a table with various numbers of rows and columns to a database. For this, I have a Criterion collection that saves the table headers and an Option collection that saves the table data.
The structure is like this:
for Criterion:
{
{ "_id" : "hId1", "name" : "Option Name", "tableId" : "tId1" },
{ "_id" : "hId2", "name" : "Rent", "score" : 9, "tableId" : "tId1" },
{ "_id" : "hId3", "name" : "Surface", "score" : 5, "tableId" : "tId1" },
{ "_id" : "hId4", "name" : "Price", "score" : 5, "tableId" : "tId1" },
{ "_id" : "hId5", "name" : "CPU", "score" : 5, "tableId" : "tId4" }
etc.
}
for Option:
{
{ "_id" : "id1", "score" : 5,
"hId1" : { "value" : "Apt 1" },
"hId2" : { "value" : "800 sqft", "score" : 1 },
"hId3" : { "value" : "$800", "score" : 3 },
etc.
"tableId" : "tId1"
}
{ "_id" : "id2", "score" : 5,
"hId1" : { "value" : "Apt 2" },
"hId2" : { "value" : "780 sqft", "score" : 10 },
"hId3" : { "value" : "$700", "score" : 3 },
etc.
"tableId" : "tId1"
}
etc.
}
The first row for Criterion will always have "Option Name". For the data above, the table with "tableId" = "tId1" would end up looking like this (tableId and headerId are the keys):
| Option Name | Surface | Price |
| =========== | ======== | ===== |
| Apt 1 | 800 sqft | $800 |
| Apt 2 | 780 sqft | $700 |
My code looks like this (imports/api/comparison.js):
/**
* Options are for the rows
*/
export var Option = new Mongo.Collection('option');
/**
* Criteria are the columns
*/
export var Criterion = new Mongo.Collection('criterion');
Meteor.methods({
'comparison.insertRow' (query, headerId, tableId, isFirst) {
check(query, Object);
check(headerId, String);
check(tableId, String);
check(isFirst, Boolean);
if(isFirst){
var data = {};
data._id = headerId;
data.tableId = tableId;
data.name = "Option Name";
Criterion.insert(data);
}
query._id = tableId;
Option.insert(query);
},
});
Where isFirst is a boolean expressing whether this is the first row in a table or not.
My query is constructed like this (imports/ui/Menu/DataInsert.jsx):
var query = {};
query.score = // value
// get the header separately
query[headerId] = {
value: //valueH from form
};
// Find the text field via the React ref
for (var i = 1, len = cols.length; i < len; i++) {
query[cols[i]._id] = {
value: //valueV from form,
score: //valueS from form
};
}
My files are available on the server because I am doing this in server/main.js: import '../imports/api/comparison.js';
The query gets inserted no problem into Option no problem.
Why isn't data getting inserted into Criterion (when isFirst = true)?
I did a console.log(data) and a console.log(query) and it looks like this:
whereas the data in the db looks like this:
#jordanwillis was correct above, this was happening because I was setting the _id manually on the query. I did need to set the id, but I needed to set the tableId.
So, for the record, this is what I did:
'comparison.insertRow' (query, headerId, tableId, isFirst) {
check(query, Object);
check(headerId, String);
check(tableId, String);
check(isFirst, Boolean);
if(isFirst){
var data = {};
data._id = headerId;
data.tableId = tableId;
data.name = "Option Name";
Criterion.insert(data);
}
query.tableId = tableId;
Option.insert(query);
},
And my foreign keys are tableId and headerId (which is part of query).

Mongodb - E QUERY SyntaxError: Unexpected identifier

Here is an example of my MongoDb structure :
{
"id" : 1,
"children" : [
{
"id" : 2,
"status" : " fsdfsdf "
},
{
"id" : 3,
"status" : " ffdfg "
},
{
"id" : 4,
"status" : " fsdfsdfsdfdsf "
}
]
}
I wanted to trim records in mongodb, so i did :
db.getCollection('myCollectionName').find().forEach(function (doc){
for (subDoc of doc.children) {
if(typeof subDoc.status === 'string') {
subDoc.theText = subDoc.theText.trim();
}
}
db.getCollection('myCollectionName').save(doc);
})
But i got this error :
E QUERY SyntaxError: Unexpected identifier
You use wrong identifier — the array item doesn't have theText identifier.
var docs = db.getCollection('myCollectionName').find()
docs.forEach(function (doc) {
for (subDoc of doc.children) {
if(typeof subDoc.status === 'string') {
subDoc.status = subDoc.status.trim();
}
}
db.getCollection('myCollectionName').save(doc);
})
Step by Step instructions
Open local mongo shell with db stackoverflow
⋊> ~ mongo stackoverflow
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017/stackoverflow
MongoDB server version: 3.4.0
Insert one (your) document
> db.getCollection('myCollectionName').insertOne({
... "id" : 1,
... "children" : [
... {
... "id" : 2,
... "status" : " fsdfsdf "
... },
... {
... "id" : 3,
... "status" : " ffdfg "
... },
... {
... "id" : 4,
... "status" : " fsdfsdfsdfdsf "
... }
... ]
... })
{
"acknowledged" : true,
"insertedId" : ObjectId("588b4984522a4f31ff6bc738")
}
Find inserted document
> db.getCollection('myCollectionName').findOne()
{
"_id" : ObjectId("588b4984522a4f31ff6bc738"),
"id" : 1,
"children" : [
{
"id" : 2,
"status" : " fsdfsdf "
},
{
"id" : 3,
"status" : " ffdfg "
},
{
"id" : 4,
"status" : " fsdfsdfsdfdsf "
}
]
}
I use findOne because I know in db only one document. In normal situation you need use find and pretty to find all document in collection
> db.getCollection('myCollectionName').find().pretty()
Find documents in collection and save cursor in variable
> var docs = db.getCollection('myCollectionName').find()
Run function for trim only field status in array children in documents
> docs.forEach(function (doc) {
... for (subDoc of doc.children) {
... if(typeof subDoc.status === 'string') {
... subDoc.status = subDoc.status.trim();
... }
... }
...
... db.getCollection('myCollectionName').save(doc);
... })
Improvement for production: find only documents with field children and check fields into document exists.
Check the result (find the document)
> db.getCollection('myCollectionName').findOne()
{
"_id" : ObjectId("588b4984522a4f31ff6bc738"),
"id" : 1,
"children" : [
{
"id" : 2,
"status" : "fsdfsdf"
},
{
"id" : 3,
"status" : "ffdfg"
},
{
"id" : 4,
"status" : "fsdfsdfsdfdsf"
}
]
}

How to get last array element while Projection mongodb

I have following document structure (This is dummy document for understanding purpose)
{
"id" : "p1245",
"Info" : [
{
"cloth_name" : "ABC",
"cloth_type" : "C"
},
{
"cloth_name" : "PQR",
"cloth_type" : "J"
},
{
"cloth_name" : "SAM",
"cloth_type" : "T"
}
]
},
{
"id" : "p124576",
"Info" : [
{
"cloth_name" : "HTC",
"cloth_type" : "C"
}
]
}
From these document I want to project the "cloth_type", so I tried following java code
DBObject fields = new BasicDBObject("id", 1);
fields.put("ClothType","$Info.cloth_type");
DBObject project = new BasicDBObject("$project", fields);
List<DBObject> pipeline = Arrays.asList(project);
AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100).outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build();
Cursor cursor = collection.aggregate(pipeline, aggregationOptions);
while (cursor.hasNext())
{
System.out.println(cursor.next());
}
(I don't want to use "$unwind" here)
and get following output:
{ "id" : "p1245" , "ClothType" : [ "C" , "J" , "T"]}
{ "id" : "p124576" , "ClothType" : [ "C"]}
If there are multiple "cloth_type" for single id, then I want only the last cloth_type from this array.
I want something like, e.g. if there is array of "ClothType" [ "C", "J", "T"] then I want to project only [ "T"] i.e last element of array.
Is there any ways to achive this without using "$unwind".