I'm struggling to remove key 'customerNumber' from sub-arrays allAddresses and allPersons. my requirement is that in the below payload key customerNumber should only appear in the parent array CustomerMaster. all other appearances of customerNumber should be deleted.
with the below code I get error groovy.lang.MissingPropertyException: No such property: allAddresses for class: java.util.LinkedHashMap$Entry. To my surprise the code works when the key CustomerMaster is an array. I dont understand why it fails if the customer is not an array
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput;
import groovy.json.*
def Message removeCustomerNumber(Message message) {
def body = message.getBody(String)
//def body = message.getBody(String.class);
body=body.toString();
def json = new JsonSlurper().parseText(body)
json.CustomerMaster.each{
// if (it.allAddresses.metaClass.respondsTo('each')){
// if(it.metaClass.hasProperty(it, 'allAddresses')){
it.allAddresses.each{
it.remove('customerNumber')
}
// }
// }
}
def out= JsonOutput.toJson(json);
//out = JsonOutput.prettyPrint()
message.setBody(out);
return message;
}
in other words when the CustomerMaster is an collection, I have no issue. I tried checking with hasProperty() and respondsTo() with out success
payload:
{
"CustomerMaster": {
"activitySector": "01",
"cognosCode": "ES001",
"companyName1": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"companyName2": "ALIAXIS IBERIA S.A.U.",
"creditControlArea": "ES01",
"currency": "EUR",
"customerNumber": "0000100001",
"allPersons": [
{
"birthday": "00000000",
"cognosCode": "ES001",
"contactId": "0000000308",
"customerNumber": "0000100001",
"jobTitle": "ENCARGADO COBROS",
"language": "ES",
"lastName": "EDUARDO JIMENEZ"
},
{
"birthday": "20210419",
"cognosCode": "ES001",
"contactId": "0000000475",
"customerNumber": "0000100001",
"email1": "FACTURASPDF.SNPT#ABAST.ES",
"jobTitle": "ENVÍO FACTURACIÓN",
"language": "ES",
"lastName": "FACTURACION"
},
{
"birthday": "00000000",
"cognosCode": "ES001",
"contactId": "0000000036",
"customerNumber": "0000100001",
"jobTitle": "REPRESENTANTE LEGAL",
"language": "ES",
"lastName": "D. JULIO ESTEBAN SALGADO"
}
],
"allAddresses": [
{
"StateOrProvince": "MERES-SIERO",
"city": "MERES-SIERO",
"countryCode": "ES",
"customerNumber": "0000100001",
"fax": "985793802",
"id": "0000372156",
"name": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"number": "1",
"phoneBusiness": "985-792224",
"postalCode": "33199",
"region": "33",
"street": "POL.IND.PRONI. CALLE D",
"type": "WE"
},
{
"StateOrProvince": "MERES-SIERO",
"city": "MERES-SIERO",
"countryCode": "ES",
"customerNumber": "0000100001",
"fax": "985793802",
"id": "0000372156",
"name": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"number": "1",
"phoneBusiness": "985-792224",
"postalCode": "33199",
"region": "33",
"street": "POL.IND.PRONI. CALLE D",
"type": "AG"
},
{
"StateOrProvince": "MERES-SIERO",
"city": "MERES-SIERO",
"countryCode": "ES",
"customerNumber": "0000100001",
"fax": "985793802",
"id": "0000372156",
"name": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"number": "1",
"phoneBusiness": "985-792224",
"postalCode": "33199",
"region": "33",
"street": "POL.IND.PRONI. CALLE D",
"type": "RE"
},
{
"StateOrProvince": "MERES-SIERO",
"city": "MERES-SIERO",
"countryCode": "ES",
"customerNumber": "0000100001",
"fax": "985793802",
"id": "0000372156",
"name": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"number": "1",
"phoneBusiness": "985-792224",
"postalCode": "33199",
"region": "33",
"street": "POL.IND.PRONI. CALLE D",
"type": "RG"
},
{
"StateOrProvince": "MERES-SIERO",
"city": "MERES-SIERO",
"countryCode": "ES",
"customerNumber": "0000100001",
"fax": "985793802",
"id": "0000372156",
"name": "SANIPLAST SOL. SOSTEN. DEL AGUA SL",
"number": "1",
"phoneBusiness": "985-792224",
"postalCode": "33199",
"region": "33",
"street": "POL.IND.PRONI. CALLE D",
"type": "ZV"
}
],
"email1": "JUANJOSE.GONZALEZ#SANIPLAST.ES",
"entityCode": "ES01",
"fax": "985793802",
"phone1": "985-792224",
"phone2": "985791154ISABEL",
"termsofPayment": "Z037"
}
}
def json = new JsonSlurper().parseText(body)
if(json.CustomerMaster instanceof List){
json.CustomerMaster.each{
it.allPersons?.each{it.remove("customerNumber")}
it.allAddresses?.each{it.remove("customerNumber")}
}
}else{
json.CustomerMaster?.allPersons?.each{it.remove("customerNumber")}
json.CustomerMaster?.allAddresses?.each{it.remove("customerNumber")}
}
with ternary operator
( json.CustomerMaster instanceof List ? json.CustomerMaster : [json.CustomerMaster] ).each{
it?.allPersons?.each{it.remove("customerNumber")}
it?.allAddresses?.each{it.remove("customerNumber")}
}
I've searched the internet and StackOverflow, but I cannot find the answer or even the question.
I have two collections, artisan and users. I want my query to return all reports and indicate if the specified user has that report as a favorite in their array.
I'm finding hard to remove the other result for the next data that is set in the first result.
i would love to receive some help on how to get the correct value from the aggregate statement.
if you look so closely, you will see that "_id": "5f21f998fe054d2cf0b7f787" is showing 3 times, but the correct one is the one with "user_id": "5f21f998fe054d2cf0b7f787" of artisan. That is the same for others also
Here below is the code and the result i was getting
Thanks
User.aggregate([
{
$lookup: {
from: Artisan.collection.name,
localField: "user._id",
foreignField: "artisan.user_id",
as: "artisan"
}
},
{$unwind: '$artisan'}
])
.then((result) => {
res.json(result);
}, (err) => next(err))
.catch((err) => next(err));```
\\Here is the result
[
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f21f998fe054d2cf0b7f787",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Ayobami",
"lastname": "Eniola",
"email": "ekundayoolumide#gmail.com",
"password": "$2b$10$BlfwHzVgZ4kWYfG6Ia4x.Oj6cdVG24Cwl3R9FZQ9lK/1LoUg.WbAi",
"user_type": "artisan",
"createdAt": "2020-07-29T22:35:04.601Z",
"updatedAt": "2020-07-29T22:35:04.601Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f21fa632fc70100d0339193",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide1#gmail.com",
"password": "john1234",
"user_type": "artisan",
"createdAt": "2020-07-29T22:38:27.957Z",
"updatedAt": "2020-07-29T22:42:22.454Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f21f998fe054d2cf0b7f788",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f21f998fe054d2cf0b7f787",
"createdAt": "2020-07-29T22:35:04.645Z",
"updatedAt": "2020-07-29T22:35:04.645Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f21fa632fc70100d0339194",
"date_of_birth": null,
"duration": "4 years",
"payment_status": "",
"payment_type": "",
"user_id": "5f21fa632fc70100d0339193",
"createdAt": "2020-07-29T22:38:27.998Z",
"updatedAt": "2020-07-29T22:42:22.601Z",
"__v": 0
}
},
{
"_id": "5f227b0433105d3a3864547d",
"email_verified": null,
"sex": "male",
"phone_no": 2348117741341,
"address": "10 Oweh Street",
"area": "",
"city": "Lagos",
"state": "Lagos",
"country": "",
"job_type": "great work",
"status": "",
"login_key": "",
"login_valid_till": null,
"firstname": "Johnson",
"othername": "Akinmade",
"lastname": "Eniola",
"email": "ekundayoolumide2#gmail.com",
"password": "$2b$10$jg/nKNpg/RkDA.KFG/flFuy8fwfamLdgCD7MNk16rprDiwoWTKcse",
"user_type": "artisan",
"createdAt": "2020-07-30T07:47:16.234Z",
"updatedAt": "2020-07-30T07:47:16.234Z",
"__v": 0,
"artisan": {
"_id": "5f227b0433105d3a3864547e",
"date_of_birth": null,
"duration": "",
"payment_status": "",
"payment_type": "",
"user_id": "5f227b0433105d3a3864547d",
"createdAt": "2020-07-30T07:47:16.269Z",
"updatedAt": "2020-07-30T07:47:16.269Z",
"__v": 0
}
}
]
Right now you have:
$lookup: {
from: Artisan.collection.name,
localField: "user._id",
foreignField: "artisan.user_id",
as: "artisan"
}
After looking at your results, the documents from the User collection don't have a field named user._id, they just have an _id field. Similarly with your Artisan collection there isn't a field named artist.user_id, there's just a user_id field. Change the localField and foreignField values to only have the name of the fields as they appear in the respective documents.
It should look something like this:
$lookup: {
from: Artisan.collection.name,
localField: "_id",
foreignField: "user_id",
as: "artisan"
}
We are using Microsoft bot framework V3 and typescript and while designing Adaptive cards design below issues are facing
1.Card rendering is failing at UI side When we use "width": "80px" or width:1 for alignment.
Red color is not properly displaying("color": "Attention") whichi is coming as brick red
{
'contentType': 'application/vnd.microsoft.card.adaptive',
'content': {
'$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
'type': 'AdaptiveCard',
'version': '1.0',
'body': [
{
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"color": "Dark",
"text": "Company",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"color": "Dark",
"text": "PO Number",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"color": "Dark",
"text": "Status",
"isSubtle": true,
"wrap": true
}
],
"width": "80px"
},
{
"type": "Column",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"weight": "Bolder",
"text": "ABC.COM",
"wrap": true
},
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"weight": "Bolder",
"text": "200123456",
"wrap": true
},
{
"type": "TextBlock",
"horizontalAlignment": "Left",
"spacing": "Small",
"size": "Small",
"weight": "Bolder",
"text": "canceled",
"wrap": true,
"color": "Attention"
}
],
"width": "stretch"
}
]
}
]
}
};
I have a huge dataset that increases by hundreds/thousands items for sale every few minutes. I will be parsing this data as it comes in and I'm looking for suggestions on how to efficiently match new incoming items with users who want the item.
Examples of how other have done this would mean the world to me. Even just clarification on what to search for online would be helpful. I'm having difficulty asking the right questions to search engines so I can learn how to solve this (usually I'm very good at this sort of thing).
Thank you fellow geniuses!
p.s. Hoping so solve this problem with nodejs
Inventory Dataset Example:
{
"anchor": 982179125,
"next_page": 1,
"next_tier": 0,
"num_matches": 47037,
"postings": [
{
"category": "SBIK",
"category_group": "SSSS",
"external_id": "4488716340",
"heading": "60cm Aluminum/Carbon Road Bike, Ultegra/105 equipped, 20-Spd",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.801041",
"locality": "USA-SFO-MRS",
"long": "-122.434151",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 800.0
},
{
"category": "SBOT",
"category_group": "SSSS",
"external_id": "4488164318",
"heading": "Burley Bee Boat Trailer",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.7999",
"locality": "USA-SFO-MRS",
"long": "-122.4342",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 150.0
},
{
"category": "SAUT",
"category_group": "SSSS",
"external_id": "4459983854",
"heading": "Car frame extra light castom made",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.7999",
"locality": "USA-SFO-MRS",
"long": "-122.4342",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 300.0
},
"success": true,
"time_fetch": 9.4971656799316406,
"time_search": 42.315006256103516,
"time_taken": 183.84885787963867
}
My users are looking for:
{name:"tom",wants:"new car"}
{name:"john",wants:"Road Bike",price:[low:100,high:1000]}
{name:"becky",wants:"dolls"}
{name:"sam",wants:"Drobo",price:[low:0,high:500]}]
...
...
...