Skip to content

Commit

Permalink
Merge branch 'main' into d032842_service_pojos
Browse files Browse the repository at this point in the history
  • Loading branch information
mofterdinger authored Nov 14, 2023
2 parents 93726e2 + 2b6f89a commit 749ea50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
15 changes: 9 additions & 6 deletions java/query-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1212,17 +1212,20 @@ The Query Builder API supports using expressions in many places. Expressions con

### Entity References {#entity-refs}

Entity references specify entity sets. They can be used to define the target entity set of a [CQL](../cds/cql) statement. They can either be defined inline using lambda expressions in the Query Builder (see [Target Entity Sets](#target-entity-sets)) or via the `CQL.entity` method. The following example shows an entity reference describing the set of *authors* that have published books in the year 2020:
Entity references specify entity sets. They can be used to define the target entity set of a [CQL](../cds/cql) statement. They can either be defined inline using lambda expressions in the Query Builder (see [Target Entity Sets](#target-entity-sets)) or via the `CQL.entity` method, which is available in an _untyped_ version as well as in a _typed_ version that uses the generated [model interfaces](../java/advanced#model-interfaces). The following example shows an entity reference describing the set of *authors* that have published books in the year 2020:

```java
import static com.sap.cds.ql.CQL.entity;
import com.sap.cds.ql.CQL;

// bookshop.Books[year = 2020].author // [!code focus]
Authors_ authors = CQL.entity(Books_.class).filter(b -> b.year().eq(2020)).author(); // [!code focus]

// bookshop.Books[year = 2020].author
// or as untyped entity ref
StructuredType<?> authors =
entity("bookshop.Books").filter(b -> b.get("year").eq(2020)).to("author");
CQL.entity("bookshop.Books").filter(b -> b.get("year").eq(2020)).to("author");

// SELECT from bookshop.Books[year = 2020].author { name }
Select.from(authors).columns("name");
// SELECT from bookshop.Books[year = 2020].author { name } // [!code focus]
Select.from(authors).columns("name"); // [!code focus]
```

You can also get [entity references](query-execution#entity-refs) from the result of a CDS QL statement to address an entity via its key values in other statements.
Expand Down
41 changes: 14 additions & 27 deletions java/remote-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ In this case, the destination with name `s4-business-partner-api` would be obtai
Given that this destination holds the URL `https://s4.sap.com`, the resulting service URL for OData requests would be `https://s4.sap.com/sap/opu/odata/sap/API_BUSINESS_PARTNER`.

The `type` property defines the protocol used by the remote API. The CAP Java SDK currently supports `odata-v4` (default) or `odata-v2`.
::: warning
When using SAP S/4HANA On-Premise via Cloud Connector with a non-default sap-client, you might observe 401 Unauthorized errors.
This is a known issue and can be avoided by adding an additional property `URL.headers.sap-client` with the value of the sap-client to the destination in the SAP BTP Destination Service's configuration.
:::

#### Configuring Destination Strategies

Expand Down Expand Up @@ -279,36 +275,27 @@ DefaultHttpDestination
#### OAuth2 Client Credentials { #oauth2-client-credentials}

```java
DefaultHttpDestination httpDestination = DefaultHttpDestination
.builder("https://example.org")
.name("my-destination").build();
ClientCredentials clientCredentials =
new ClientCredentials("clientid", "clientsecret");
ClientCredentialsHttpDestination clientCredentialsHttpDestination =
new ClientCredentialsHttpDestination(
httpDestination,
clientCredentials,
URI.create("https://xsuaa.url"),
new XsuaaService()
);
OAuth2DestinationBuilder
.forTargetUrl("https://example.org")
.withTokenEndpoint("https://xsuaa.url")
.withClient(clientCredentials, OnBehalfOf.TECHNICAL_USER_CURRENT_TENANT)
.withProperties(Map.of("name", "my-destination"))
.build();
```

#### User Token Authentication { #user-token-authentication}

```java
DefaultHttpDestination httpDestination = DefaultHttpDestination
.builder("https://example.org")
.name("my-destination").build();
ClientCredentials clientCredentials =
new ClientCredentials("clientid", "clientsecret");
ClientCredentialsHttpDestination clientCredentialsHttpDestination =
new ClientCredentialsHttpDestination(
httpDestination,
clientCredentials,
ClientCredentialsGrantType.USER_TOKEN,
URI.create("https://xsuaa.url"),
new XsuaaService()
);
OAuth2DestinationBuilder
.forTargetUrl("https://example.org")
.withTokenEndpoint("https://xsuaa.url")
.withClient(clientCredentials, OnBehalfOf.NAMED_USER_CURRENT_TENANT)
.withProperties(Map.of("name", "my-destination"))
.build();
```

0 comments on commit 749ea50

Please sign in to comment.