How to provide OData service via the SAP Cloud SDK for an entity with a DateTime in its key? - sap-cloud-sdk

We are currently struggling with providing an OData service for an entity, which has as part of its key a property of type DateTime. This key property is not part of the key map in the OData request given by the SAP Cloud Provisioning SDK. This seems to be due to a bug in the parsing of the request in the method com.sap.cloud.sdk.service.prov.v2.data.provider.CXSDataProvider.getKeys(List):
if (type.toString().equals("Edm.Date")) {
Date value = type.valueOfString(keyPredicate.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Date.class);
keys.put(property.getName(), value);
}
Since there is no Edm.Date type in the OData standard, my guess is that instead the following would have been correct:
if (type.toString().startsWith("Edm.Date")) {
[s. above]
}
Is this correct or are we doing something wrong here? In addition there is a TODO marker on the method itself pointing out that only a subset of EDM types is currently supported as a key. Are there any plans to fix this TODO?

As muchumanoj commented, the issue should be resolved in version 1.29.5 of <groupId>com.sap.cloud.servicesdk.prov</groupId><artifactId>odatav2-prov</artifactId>. Thanks for reporting it.

Related

OpenAPI Generator issue with Destination service API specification

I want to get all destinations on subaccount and instance level. In SAP API business Hub, I found the API information and "SAP Cloud SDK" tab to generate code by OpenAPI generator.
https://api.sap.com/api/SAP_CP_CF_Connectivity_Destination/overview
I downloaded the API specification and added dependencies into Cloud SDK for Java project. The code is generated successfully with some errors (unknown models)in generated api classes.
For example in DestinationsOnSubaccountLevelApi.class, model OneOfDestinationNameOnly is imported and used in method but it is not generated in model package.
I looked into API specification and found that there were two types of response entity. That is the reason why the code could not be generated properly. I can modify the API specification to make it work but it should not be the long term solution. Is there any other way to fix this issue?
Unfortunately the SAP Cloud SDK Generator for Open API services is not yet able to understand oneOf relationship that is modeled in the specification.
As an alternative, would you consider using the DestinationAccessor API for resolving single destinations?
You can also directly instantiate an ScpCfDestinationLoader, which allows for querying all destinations:
ScpCfDestinationLoader loader = new ScpCfDestinationLoader();
DestinationOptions options = DestinationOptions
.builder()
.augmentBuilder(ScpCfDestinationOptionsAugmenter.augmenter().retrievalStrategy(ScpCfDestinationRetrievalStrategy.ALWAYS_SUBSCRIBER))
.build();
Try<Iterable<ScpCfDestination>> destinations = loader.tryGetAllDestinations(options);
Similar to the default behavior of DestinationAccessor API, in the code above only the subscriber account will be considered. Other options are:
ScpCfDestinationRetrievalStrategy.ALWAYS_SUBSCRIBER
ScpCfDestinationRetrievalStrategy.ALWAYS_PROVIDER
ScpCfDestinationRetrievalStrategy.SUBSCRIBER_THEN_PROVIDER

V4 Generator - OData V2 Non-Simple Function Import Parameters

I am using version odata-v4-generator-cli 3.40.0 to generate a client from the SAP B1 Service Layer definition.
However, there are many errors like the following:
Function import DraftsService_SaveDraftToDocument has non-simple type for parameter Document, but OData V2 does not support non-simple types as function import parameters.
And the function is not present in the generated client code. The error seems to indicate it is a limitation with V2, but this is a V4 definition with the V4 version of the generator.
The log message you are seeing is indeed very misleading - in fact it is plain wrong.
We have a fix for the incorrect message in our pipeline.
In general, however, generating function imports (V2) and (un-)bound actions (V4) with non-primitive parameters is not yet supported in our OData generators.
This is why these methods are not included in the generated code.
We are receiving many requests asking for this feature and have it rather high up in our backlog.
Unfortunately, I cannot give any details for a release schedule - I will update this answer when we have more concrete information.
EDIT (06/14/2021)
With release 3.46.0 of the SAP Cloud SDK for Java, we have shipped a first version of bound functions and actions.

Logic Apps and CosmosDB

So I'm trying to do something I expected to be simple - using Logic App to insert a json object into Cosmos DB.
I've created a CosmosDB (based on Core SQL API) and created a container called Archive with the partition key /username (which is in my json object).
Now to Logic App.
First, I YOLO'ed the simple approach.
Which gave me error: "The input content is invalid because the required properties - 'id; ' - are missing"
But my json object doesnt have an id field. Maybe use the IsUpsert parameter? I dont feel like manipulating my input document to add a field called 'id'.
Which gave me error: "One of the specified inputs is invalid" Okay - feels even worse.
I now tried to use the other logic app connector (Not V2, but the original).
which gave me error: "The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection."
I saw that this connector(unlike the V2 one) has a Partition Key Value parameter from UI, which I added to pass the value of my username
which gave me error "The input content is invalid because the required properties - 'id; ' - are missing".
At this point I thought, let me just give the bloody machine what it wants, and so I added "id" to my json object.
and yes that actually worked.
So questions are
With Logic Apps connectors, are you only able to insert json objects into Cosmos DB without that magic field "id" in the message payload?
If the partitioning key is required. Why is it not available from the V2 connector parameter UI?
Thanks.
The v1 version of this thing doesn't have partition key because it's so old, Cosmos didn't have partitioned containers. You will want to use the v2 preview. I think that will go GA at some point here soon because it's been in preview for a while now.
And yes, With Cosmos DB you can't insert anything without it's id so you will need to generate from whatever calls your endpoint and pass it in the body of your http request.

ServiceStack and Stripe

I'm using the ServiceStack Stripe package, but it seems the serializer for the GetStripeCustomer method doesn't parse the Subscription Status correctly.
In the JSON I can see that the Status is "past_due", but when ServiceStack converts it to StripeCollection the Status value is "Unknown".
I'm using ServiceStack.Stripe v4.0.24
Has anyone encountered this?
There was an issue automatically converting Stripe's Lower_Case_Enums into ServiceStack's .NET enums PascalCase naming convention which should be resolved with this commit.
This change is available from v4.0.37+ that's now available on MyGet.

MoreLikeThis in Azure Search

I'm currently evaluating the new Azure Search feature in Windows Azure. I'm wondering if there's a way to do a MoreLikeThis query similar to lucene/elasticsearch?—pass in a document text and get a list of documents that are similar to the passed in document. I know Azure Search uses elasticsearch in the background (Source).
I haven't found this anywhere in the API, but maybe I'm missing something hidden in the parameters. I think this is a very useful feature and it would be shame if it's not included.
Yes it comes in the new version of azure search : 2015-02-28-Preview
see here : http://azure.microsoft.com/en-us/documentation/articles/search-api-2015-02-28-preview/
moreLikeThis=[key]
Here a sample:
GET /indexes/[index name]/docs/suggest?[query parameters]
Host: [search service url]
accept: application/json
api-key: [admin key]
C#
Uri uri = new Uri(_serviceUri, "/indexes/catalog/docs/suggest?$filter=discontinuedDate eq null&$select=productNumber&search=" + Uri.EscapeDataString(searchText));
There's a sample project on Codeplex:
https://azuresearchadventureworksdemo.codeplex.com/
Suggestions (Azure Search API):
http://msdn.microsoft.com/en-us/library/azure/dn798936.aspx
(Azure Search API)
http://msdn.microsoft.com/en-us/library/azure/dn798927.aspx
Unfortunately this feature is not currently available in Azure Search.
See Pablo's comment on Scott Guthrie's blog.
I know that this is an antique question, but it's one of the first when googling for 'morelikethis azure search'.
Anyway, with the new API version 2019-05-06-Preview there is a new preview feature called moreLikeThis (not in the SDK yet) where you can pass in an id of an existing document (I know, not a text like the David asked for). E.g.
GET /indexes/[index]/docs?moreLikeThis=[documentId]&api-version=2019-05-06-Preview
You can filter the compared fields by defining a list of properties with the searchFields parameter, e.g.
GET /indexes/[index]/docs?moreLikeThis=[documentId]&searchFields=[field]&api-version=2019-05-06-Preview
Of course this can also be POSTed, for more details have a look here.

Resources