VDM call to a function import returns null without throwing an exception - sap-cloud-sdk

I am using VDM to query a function import. It returns null, which is not expected. It does not go to exception flow, so not able to figure out whether the call was a success or not.
PurchaseRequisitionHeaderBOView resultPojo = null;
try {
resultPojo = sspprService.purchaserequisition_WdActivation(purchaseRequisition, draftUUID, isActiveEntity)
.execute(new ErpConfigContext(s4destination));
if (resultPojo == null)
logger.error("VDM call returned null!");
} catch (ODataException e) {
logger.error(EXCEPTION_ACTIVATING_CART, e);
throw new org.apache.olingo.odata2.api.exception.ODataException(EXCEPTION_ACTIVATING_CART, e);
}
Expected:If call was a success a non-null POJO. If call failed it should hit the catch block.
Response of the function import
{
"d" : {
"__metadata" : {
"id" : "https://uyt700-er9003.wdf.sap.corp/sap/opu/odata/sap/MMPUR_REQ_GPR_MAINTAIN_SRV/I_Purchaserequisition_Wd(PurchaseRequisition='12444947',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)",
"uri" : "https://uyt700-er9003.wdf.sap.corp/sap/opu/odata/sap/MMPUR_REQ_GPR_MAINTAIN_SRV/I_Purchaserequisition_Wd(PurchaseRequisition='12444947',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)",
"type" : "MMPUR_REQ_GPR_MAINTAIN_SRV.I_Purchaserequisition_WdType",
"etag" : "W/\"20190920072451.9970020m\""
},
"Activation_ac" : false,
"Edit_ac" : true,
"Preparation_ac" : false,
"Validation_ac" : false,
"PurReqnDescription_fc" : 3,
"PurReqnSSPRequestor_fc" : 3,
"PurchaseRequisition" : "12444947",
"PurReqnSSPRequestor" : "00001076",
"PurReqnSSPAuthor" : "CSAC",
"PurchaseRequisitionType" : "NB",
"CreationDate" : "\/Date(1568937600000)\/",
"LastChangeDateTime" : "20190920072451.9970020",
"IsOnBehalfCart" : "",
"BusinessUser" : "CSAC",
"PurReqnIsCreatedInExpertMode" : false,
"PurReqnDescription" : "",
"EmployeeFullName" : "Don Draper",
"PurReqnOrigin" : "S",
"IsSrchEnabled" : false,
"PurReqnLifeCycleStatus" : "",
"PurReqnLifeCycleStatusName" : "",
"NumberOfItems" : 0,
"TotalNetAmount" : "0.00",
"Currency" : "",
"IsExtPurgScenario" : false,
"PurReqnIsCopyDraft" : false,
"HasDraftEntity" : false,
"DraftUUID" : "00000000-0000-0000-0000-000000000000",
"DraftEntityCreationDateTime" : null,
"DraftEntityLastChangeDateTime" : null,
"HasActiveEntity" : false,
"IsActiveEntity" : true,
"DraftAdministrativeData" : {
"__deferred" : {
"uri" : "https://uyt700-er9003.wdf.sap.corp/sap/opu/odata/sap/MMPUR_REQ_GPR_MAINTAIN_SRV/I_Purchaserequisition_Wd(PurchaseRequisition='12444947',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)/DraftAdministrativeData"
}
},
"SiblingEntity" : {
"__deferred" : {
"uri" : "https://uyt700-er9003.wdf.sap.corp/sap/opu/odata/sap/MMPUR_REQ_GPR_MAINTAIN_SRV/I_Purchaserequisition_Wd(PurchaseRequisition='12444947',DraftUUID=guid'00000000-0000-0000-0000-000000000000',IsActiveEntity=true)/SiblingEntity"
}
}
}
}

Please update your dependency of SAP Cloud SDK to 3.6.0 as it fixes the issue of parsing OData function import responses. A customization is no longer required. Please let me know, if it works for you.

Related

How to retrieve the result of Pregel ArangoDB?

I am a newbie and using ArangoDB 3.2.5. I would like to retrieve the result of pregel in ArangoDB. Here is a simple example in arangosh.
var pregel = require("#arangodb/pregel");
var params = {source: "Country/Tunesia"};
var execution = pregel.start("sssp", "CountryGraph", params);
In the document, it dumps the result of pregel in a field in the collection. Is there an alternative way like the following code to retrieve the result? I look for it in the document but didn't find it. By the way, you can load the dataset example used by the above code by loading this. Thanks.
var result = pregel.getResult(execution);
The result can not be returned directly. You have two options however:
Let ArangoDB write the Pregel result into the documents
Don't store the result, but only hold it temporarily in memory
To avoid persisting the result, there is an option store which you have to set to false. You can access the volatile result with AQL through the function PREGEL_RESULT(<handle>).
The flow is like this:
Start Pregel execution
Check status and wait until it changes to "done" or "canceled"
Perform an AQL query to access the result if Pregel succeeded
var pregel = require("#arangodb/pregel");
var params = {source: "Country/Algeria", store: false};
var handle = pregel.start("sssp", "CountryGraph", params);
while (!["done", "canceled"].includes(pregel.status(handle).state)) {
print("waiting for result");
require("internal").wait(0.5); // TODO: make this more clever
}
var status = pregel.status(handle);
print(status);
if (status.state == "done") {
var query = db._query("FOR doc IN PREGEL_RESULT(#handle) RETURN doc", {handle: handle});
print(query.toArray());
}
The output looks like this:
shell>arangosh --javascript.execute pregel.js
waiting for result
{
"state" : "done",
"gss" : 2,
"totalRuntime" : 0.00583648681640625,
"aggregators" : {
},
"sendCount" : 1,
"receivedCount" : 1,
"vertexCount" : 10,
"edgeCount" : 8,
"code" : 200
}
[
{
"_key" : "Germany",
"result" : 9223372036854776000
},
{
"_key" : "Switzerland",
"result" : 9223372036854776000
},
{
"_key" : "Brasil",
"result" : 9223372036854776000
},
{
"_key" : "Marocco",
"result" : 9223372036854776000
},
{
"_key" : "Argentina",
"result" : 9223372036854776000
},
{
"_key" : "Austria",
"result" : 9223372036854776000
},
{
"_key" : "Algeria",
"result" : 0
},
{
"_key" : "Uruguay",
"result" : 9223372036854776000
},
{
"_key" : "Tunesia",
"result" : 1
},
{
"_key" : "Australia",
"result" : 9223372036854776000
}
]

Logging with winston-mongodb, express-winston and winston

I'm using winston, expressWinston, winston-mongoDB to manage the logs in my NodeJs application.
While using winston-mongodb transport with express-winston; i can store the logs to my mongoDB collection in the following format. (meta:true)
{
"_id" : ObjectId("5a124f9781d911337ebeb98d"),
"timestamp" : ISODate("2017-11-20T03:44:23.336Z"),
"level" : "info",
"message" : "GET /stylesheets/bootstrap.css 304 2ms",
"meta" : {
"res" : {
"statusCode" : 304
},
"req" : {
"url" : "/stylesheets/bootstrap.css",
"headers" : {
"host" : "localhost:3000",
"connection" : "keep-alive",
},
"method" : "GET",
"httpVersion" : "1.1",
"originalUrl" : "/stylesheets/bootstrap.css",
"query" : {}
},
"responseTime" : 2
}
I can get the request/response info in the meta.
Is it possible that these details be a part of the collection directly ? , something like this:
{
"_id" : ObjectId("5a12537d81b6b634cb7d4696"),
"timestamp" : ISODate("2017-11-20T04:01:01.229Z"),
"level" : "info",
"message" : "GET /stylesheets/bootstrap.css 304 11ms",
"status": 200,
"requestUrl": '/',
"requestMethod": 'GET',
"remoteIp": '::1'
"meta" : {}
}
you can override the default log function implementation to save whatever you want exactly
let logger = new winston.Logger(options);
logger.log = function () {
var args = arguments;
// here you can transform your meta obj
winston.Logger.prototype.log.apply(this, args);
};
Hope it will help you the idea

how to find data in array key name nodejs from mongodb

how to find data from mongodb in nodejs i have below query but its return null, i want to find data in child_categories array Key name child_categoryname please help me i am very thanful to you
i am using nodejs i want to find 'truck repair' and in response i want to get child_categoryhrs in response related to truck repair
example = 4
JobCategories.findOne({ child_categories : { child_categoryname : 'truck repair'} })
.exec().then(result => { console.log(result); })
.catch(handleError(res));
//mongodb
{
"_id" : ObjectId("58cea64cfd70bb1aa472ef2c"),
"category_name" : "Repairing",
"date_updated" : ISODate("2017-03-20T12:04:16.323Z"),
"child_categories" : [
{
"child_categoryname" : "truck repair",
"child_categoryhrs" : 4,
"_id" : ObjectId("58cea64cfd70bb1aa472ef2d")
},
{
"child_categoryname" : "car repair",
"child_categoryhrs" : 8,
"_id" : ObjectId("58cfc5405895461b286238fa")
}
],
"__v" : 0
}

Fetch sub-document Mongodb only match with criteria

I have data in mongodb like this:
{
"_id" : ObjectId("55a12bf6ea1956ef37fe4247"),
"tempat_lahir" : "Paris",
"tanggal_lahir" : ISODate("1985-07-10T17:00:00.000Z"),
"gender" : true,
"family" : [
{
"nama" : "Robert Deniro",
"tempat_lahir" : "Bandung",
"tanggal_lahir" : ISODate("2015-07-09T17:00:00.000Z"),
"pekerjaan" : "IRT",
"hubungan" : "XXX",
"tanggungan" : false,
"_id" : ObjectId("55a180f398c9925299cb6e90"),
"meta" : {
"created_at" : ISODate("2015-07-11T20:59:25.242Z"),
"created_ip" : "127.0.0.1",
"modified_at" : ISODate("2015-07-12T15:54:39.682Z"),
"modified_ip" : "127.0.0.1"
}
},
{
"nama" : "Josh Groban",
"tempat_lahir" : "Jakarta",
"tanggal_lahir" : ISODate("2015-06-30T17:00:00.000Z"),
"pekerjaan" : "Balita",
"hubungan" : "Lain-Lain",
"tanggungan" : true,
"_id" : ObjectId("55a29293c65b144716ca65b2"),
"meta" : {
"created_at" : ISODate("2015-07-12T16:15:15.675Z"),
"created_ip" : "127.0.0.1"
}
}
]
}
when i try to find data in sub-document, with this code:
person.findOne({ _id: req.params.person, {'family.nama': new RegExp('robert', 'gi') }}, function(err, data){
// render code here
});
It show all data in Family Data,
Can we fetch or display a data only match with criteria/keyword, for example only "Robert Deniro" row
Thank You
In 'regular' MongoDB, you can use the $ operator for that. I'm not sure if it works with Mongoose, but it's worth a try:
person.findOne({
_id : req.params.person,
'family.nama' : new RegExp('robert', 'gi')
}, {
// Only include the subdocument(s) that matched the query.
'family.$' : 1
}, function(err, data){
// render code here
});
If you need any of the properties from the parent document (tempat_lahir, tanggal_lahir or gender; _id will always be included), you need to add them to the projection object explicitly.
One caveat: the $ operator will only return the first matching document from the array. If you need it to return multiple documents, you can't use this method and (AFAIK) have to postprocess the results after they are returned from the database.
It solved with this code:
var options = {
family: {
$elemMatch: { nama: req.query.keyword }
},
};
person.findOne({ _id: req.params.person, 'family.nama': keyword }, options, function(err, data){
//render code here
});
Thanks to #hassansin & #robertklep

elastic search index template creation

I am very new to elastic-search, in my node program i am using elastic-search. In that i am trying to create an "Index Template" but i am receiving error:
The query:
client.indices.putTemplate({
"name":"mfi1",
"template" : "te*"
}).then(function(res){
console.log(res);
}, function(error){
console.log(error);
});
But i am receiving error:
{
"error": "ElasticsearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.BytesArray#1]",
"status": 400
}
Help me to solve this.Thanks in advance.
Ya i found a solution:
I reconstructed my query as following:
{
name : "mfi3",
body:{
"template" : "te*",
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false }
}
}
}
};
Its working fine.

Resources