How to read an aggregated entity from Odata Service SAP ui5 - odata

In OData Model V2, I'm struggling by reading the odata of my mocked server:
I want to get access to the child entity which is associated with a Parent entity.
From Open_Station I can navigate to_Order_Header:
[{
"results": [
{
"__metadata": {
"id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"type": "cds_zui_check_dialog.Open_StationType"
},
"Station": "CHE1",
"Task": "5246",
"to_Order_Header": {
"__deferred": {
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
}
}
}
]
}
]
And from to_Order_Header, I can navigate to Order_Item or Stock:
[{
"__metadata" : {
"id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
}
},
"to_Stock" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
}
}
]
In my controller, I have a metho ReadOdata read data like this:
ReadOdata: function()
{
var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
return new Promise(function(resolve, reject)
{
oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
success : function (data) {
resolve(data);
},
error: function (oError) {
reject(oError);
}
});
});
},
I always get a failure like this:
Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
sap.ui.model.odata.ODataMessageParser
I think the way I want to read the associated entity is wrong. Please help me.

I found a solution. It was a failure in the annotation of the Path:
Instead of writing:
oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {
I was writing:
oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {
In the MetaData, the NavigationProperty was called to_Open_Station.

Related

Require form-urlencoded request body with swagger-core

Using Dropwizard with swagger-core and swagger-jaxrs2 2.2.6, how can you mark the requestBody of a x-www-form-urlencoded request as required?
#POST
#Path("/do-something")
#Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
#Operation(summary = "Does something")
public void doSomething(#NotNull #FormParam("what") String what) {
// ...
}
This generates the following:
"/do-something" : {
"post" : {
"summary" : "Does something",
"operationId" : "doSomething",
"requestBody" : {
/* missing here: "required": true */
"content" : {
"application/x-www-form-urlencoded" : {
"schema" : {
"required" : [ "what" ],
"type" : "object",
"properties" : {
"what" : {
"type" : "string"
}
}
}
}
}
},
"responses" : { /* ... */ }
}
},
Parameter what is required, however the requestBody as a whole is not marked as required. Generated TypeScript clients therefore allow to omit it.
I could annotate the operation with something like #RequestBody(required = true), but this disables the auto detection of the parameters.
Do you have any idea how to solve this without rewriting half the documentation manually?

CDK Stepfunction Fargate step that takes all json key

I wanted to create ECS task that takes all json as its environment input. But my cdk code won't deploy because of following error message, the error message is so vague and it is difficult for me to figure out why my code is wrong.
Failed to call Step Functions for request: 'com.amazonaws.services.stepfunctions.model.CreateStateMachineRequest'. (Service: null; Status Code: 500; Error Code: null; Request ID: null)
new StateMachine (/local/home/miae/Explanation/src/ForecastingDeepLearningExplanationInfrastructure/node_modules/#aws-cdk/aws-stepfunctions/lib/state-machine.ts:101:26)
My cdk code
...
const ecsFargateTask = new sfn.Task(this, 'myEcs', {
inputPath: "$",
resultPath: "$.ecs",
task: new class implements sfn.IStepFunctionsTask {
bind(): sfn.StepFunctionsTaskConfig {
return {
resourceArn: "arn:aws:states:::ecs:runTask.sync",
parameters: {
"LaunchType": "FARGATE",
"Cluster": props.cluster.clusterArn,
"TaskDefinition": taskDefinition.taskDefinitionArn,
"Overrides": {
"ContainerOverrides": [{
"Name": "myContainer",
"Environment.$": "$.envs"
}]
}
}
};
}
}
});
}
const chain = sfn.Chain.start(ecsFargateTask);
new sfn.StateMachine(this, `StateMachineCopy${props.stage}`, {
definition: chain,
timeout: cdk.Duration.seconds(3000)
});
This is the Step function I want, and I could manually create this without problem.
{
"StartAt": "ExplanationEcs",
"States": {
"ExplanationEcs": {
"End": true,
"InputPath": "$",
"Parameters": {
"LaunchType": "FARGATE",
"Cluster": "arn:aws:ecs:us-west-2:123456789:cluster/myCluster482E02CC-1VWQ5XRG4II88",
"TaskDefinition": "arn:aws:ecs:us-west-2:123456789:task-definition/myTaskDefinitionE3E6548C:3",
"Overrides": {
"ContainerOverrides": [
{
"Name": "myContainer",
"Environment.$": "$.envs"
}
]
}
},
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"ResultPath": "$.ecs"
}
},
"TimeoutSeconds": 3000
}

modeshape binarycontent search

I am trying modeshape 4, want binary content search, I am able to search nodes other than node containing binary content. Need help with search binary content. Are there any examples?
Code to create node
static void addFile(byte[] filebytes, String filename) throws Exception{
Session session=openSession();
Node root = session.getRootNode();
if(!root.hasNode("files")){
Node n = root.addNode("files");
}
Node files=root.getNode("files");
Node newFileNode=files.addNode(String.valueOf(helper.rnd.nextInt()));
newFileNode.setProperty("fileName", filename);
newFileNode.setProperty("owner", "test");
newFileNode.setProperty("binaryContent", session.getValueFactory().createBinary(new ByteArrayInputStream(filebytes)));
session.save();
closeSession(session);
}
Search code
static void search()throws Exception{
javax.jcr.query.QueryManager queryManager = openSession().getWorkspace().getQueryManager();
javax.jcr.query.Query query = queryManager.createQuery("select * from [nt:base] as s where contains(s.binaryContent,'Finan') ",Query.JCR_SQL2);
javax.jcr.query.QueryResult result = query.execute();
javax.jcr.NodeIterator nodeIter = result.getNodes();
while ( nodeIter.hasNext() ) {
javax.jcr.Node node = nodeIter.nextNode();
System.out.println(node.getProperty("fileName")+" "+node.getProperty("owner"));
}
}
modeshape configuration
{
"name" : "Persisted-Repository",
"workspaces" : {
"predefined" : ["otherWorkspace"],
"default" : "default",
"allowCreation" : true
},
"security" : {
"anonymous" : {
"roles" : ["readonly","readwrite","admin"],
"useOnFailedLogin" : false
}
},
"storage" : {
"cacheConfiguration" : "infinispan-configuration-async-eviction.xml",
"cacheName" : "persisted_repository",
"binaryStorage" : {
"type" : "database",
"driverClass" : "oracle.jdbc.driver.OracleDriver",
"url" : "jdbc:oracle:thin:#xxx.xx.xx.xx:1521:sid",
"username" : "user",
"password" : "password"
}
},
"indexProviders": {
"lucene": {
"classname": "lucene",
"directory": "target/indexes"
}
},
"indexes": {
"textFromFiles": {
"kind": "text",
"provider": "lucene",
"nodeType": "nt:resource",
"columns": "jcr:data(BINARY)"
}
},
"textExtraction": {
"extractors" : {
"tikaExtractor":{
"name" : "Tika content-based extractor",
"classname" : "tika"
}
}
}
}
node structure
+---> -1731357696 /files/-1731357696
owner test
filename attachment-a.docx
binaryContent binary (14.39KB, SHA1=3941f73eab403accc1779af293afadd0c03e0c15)

filtered query using NativeSearchQueryBuilder in spring-data elasticsearch

I am new to elasticsearch. I have a filtered query which gives me correct results using console:
GET _search
{
"query": {
"filtered": {
"query": {
"bool" : {
"should" : [
{
"match" : { "name" : "necklace" }
},
{
"match" : { "skuCode" : "necklace" }
}
]
}
},
"filter": {
"bool" : {
"must" : [
{
"term" : { "enabled" : true }
},
{
"term" : { "type" : "SIMPLE" }
},
{
"term" : { "tenantCode" : "Triveni" }
}
]
}
}
}
}
}
I am unable to get the corresponding spring-data version going. Here is what I tried:
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(boolQuery().should(matchQuery("skuCode", keyword)).should(matchQuery("name", keyword))).withFilter(
boolFilter().must(termFilter("enabled", true), termFilter("type", "SIMPLE"), termFilter("tenantCode", "Triveni"))).build();
This query gives me no results.
Can somebody please help me with this?
NativeSearchQueryBuilder.withFilter is converted to so called post_filter. See Post Filter for more details. So the query you have done on the console differs from the one that is generated by spring-data elasticsearch. To mimic the query from the console you have to use the FilteredQuery instead.
Change your query building to this:
QueryBuilder boolQueryBuilder = boolQuery().should(matchQuery("skuCode", keyword)).should(matchQuery("name", keyword));
FilterBuilder filterBuilder = boolFilter().must(termFilter("enabled", true), termFilter("type", "SIMPLE"), termFilter("tenantCode", "Triveni"));
NativeSearchQueryBuilder().withQuery(QueryBuilders.filteredQuery(boolQueryBuilder, filterBuilder).build();
Although as long as you do not use aggregations, this should not affect the (hits) results.

Elasticsearch params presence

How do I construct the query JSON so that while filtering it checks for the presence of external params.
{"query": {
"filtered": {
"query": {
"match_all": {}
}}},
"filter": {
"and": {
"filters": [
{
"term": {
"locality_name": params[:locality_name] if params[:locality_name].present?
}
}
]
}
}}:
The if clause in the JSON is invalid syntax for query DSL.
I think you can combine existFilter and termFilter with and filter like this.
This will retrieve documents for which locality_name field exist and locality_name field value is equal to your specified value.
"filter" : {
"and" : [
{
"exists" : { "field" : "locality_name" }
},
{
"term" : { "locality_name" : "your_locality_name" }
}
]
}
http://www.elasticsearch.org/guide/reference/query-dsl/exists-filter/
http://www.elasticsearch.org/guide/reference/query-dsl/and-filter/

Resources