Skip to content

Commit

Permalink
feat: add CreateDataOffer API endpoint (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium authored Sep 12, 2024
1 parent b191d85 commit 0ae66c2
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 66 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).

#### Minor Changes

- Extend the Wrapper API
- Adds `createDataOffer` endpoint to create an asset, policies and a contract definition in a single call

#### Patch Changes

### Deployment Migration Notes
Expand Down
38 changes: 37 additions & 1 deletion docs/api/postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "sovity EDC Community Edition Copy",
"description": "This is the official postman collection for the sovity EDC Community Edition.\n\nThe Management-API is based on core-edc v0.2.1.\n\nsovity EDC Community Edition: [https://github.com/sovity/edc-ce](https://github.com/sovity/edc-ce)\n\nLicense: [https://github.com/sovity/edc-ce/blob/main/LICENSE](https://github.com/sovity/edc-ce/blob/main/LICENSE)",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "31514741"
"_exporter_id": "32949497"
},
"item": [
{
Expand Down Expand Up @@ -854,6 +854,42 @@
}
},
"response": []
},
{
"name": "Create Data Offer",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"uiAssetCreateRequest\": {\n \"id\": \"create-data-offer-1\",\n \"title\": \"Create Data Offer Example\",\n \"language\": \"https://w3id.org/idsa/code/EN\",\n \"description\": \"Testdescription\",\n \"publisherHomepage\": \"https://www.sovity.de\",\n \"licenseUrl\": \"https://www.apache.org/licenses/LICENSE-2.0\",\n \"version\": \"v1.0\",\n \"keywords\": [\n \"keyword1\",\n \"keyword2\"\n ],\n \"mediaType\": \"application/json\",\n \"landingPageUrl\": \"https://www.google.com\",\n \"dataAddressProperties\": {\n \"https://w3id.org/edc/v0.0.1/ns/type\": \"HttpData\",\n \"https://w3id.org/edc/v0.0.1/ns/baseUrl\": \"https://www.google.com\",\n \"https://w3id.org/edc/v0.0.1/ns/method\": \"GET\",\n \"https://w3id.org/edc/v0.0.1/ns/queryParams\": \"\"\n },\n \"dataSource\": {\n \"type\": \"HTTP_DATA\",\n \"httpData\": {\n \"baseUrl\": \"http://example.com/baseUrl/\"\n }\n }\n },\n \"policy\": \"PUBLISH_RESTRICTED\",\n \"uiPolicyExpression\": {\n \"constraints\": [\n {\n \"left\": \"POLICY_EVALUATION_TIME\",\n \"operator\": \"GEQ\",\n \"right\": {\n \"type\": \"STRING\",\n \"value\": \"2024-03-31T22:00:00.000Z\"\n }\n },\n {\n \"left\": \"POLICY_EVALUATION_TIME\",\n \"operator\": \"LT\",\n \"right\": {\n \"type\": \"STRING\",\n \"value\": \"2024-04-30T22:00:00.000Z\"\n }\n }\n ]\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{PROVIDER_EDC_MANAGEMENT_URL}}/wrapper/ui/pages/create-asset/",
"host": [
"{{PROVIDER_EDC_MANAGEMENT_URL}}"
],
"path": [
"wrapper",
"ui",
"pages",
"create-asset",
""
]
}
},
"response": []
}
]
}
Expand Down
138 changes: 88 additions & 50 deletions docs/api/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/ui/pages/create-data-offer:
post:
tags:
- UI
description: "Create a new asset, contract definition and optional policies.\
\ Uses the same id for the asset, the contract policy, the access policy and\
\ the contract definition"
operationId: createDataOffer
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/DataOfferCreationRequest'
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/ui/pages/policy-page/policy-definitions:
post:
tags:
Expand Down Expand Up @@ -918,6 +938,24 @@ components:
- EQ
- IN
- LIKE
DataOfferCreationRequest:
required:
- policy
- uiAssetCreateRequest
type: object
properties:
uiAssetCreateRequest:
$ref: '#/components/schemas/UiAssetCreateRequest'
policy:
type: string
description: Which policy to apply to this asset.
enum:
- DONT_PUBLISH
- PUBLISH_UNRESTRICTED
- PUBLISH_RESTRICTED
uiPolicyExpression:
$ref: '#/components/schemas/UiPolicyExpression'
description: Request to create a data offer
OperatorDto:
type: string
description: Type-Safe ODRL Policy Operator as supported by the sovity product
Expand All @@ -935,19 +973,6 @@ components:
- IS_ALL_OF
- IS_ANY_OF
- IS_NONE_OF
PolicyDefinitionCreateRequest:
required:
- policy
- policyDefinitionId
type: object
properties:
policyDefinitionId:
type: string
description: Policy Definition ID
policy:
$ref: '#/components/schemas/UiPolicyCreateRequest'
description: "[Deprecated] Create a Policy Definition. Use PolicyDefinitionCreateDto"
deprecated: true
UiPolicyConstraint:
required:
- left
Expand All @@ -964,17 +989,36 @@ components:
$ref: '#/components/schemas/UiPolicyLiteral'
description: "ODRL AtomicConstraint as supported by the sovity product landscape.\
\ For example 'a EQ b', 'c IN [d, e, f]'"
UiPolicyCreateRequest:
UiPolicyExpression:
required:
- type
type: object
properties:
constraints:
type:
$ref: '#/components/schemas/UiPolicyExpressionType'
expressions:
type: array
description: Conjunction of required constraints
deprecated: true
description: "Only for types AND, OR, XONE. List of sub-expressions to be\
\ evaluated according to the expressionType."
items:
$ref: '#/components/schemas/UiPolicyConstraint'
description: "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)"
deprecated: true
$ref: '#/components/schemas/UiPolicyExpression'
constraint:
$ref: '#/components/schemas/UiPolicyConstraint'
description: ODRL constraint as supported by the sovity product landscape
UiPolicyExpressionType:
type: string
description: |
Ui Policy Expression types:
* `CONSTRAINT` - Expression 'a=b'
* `AND` - Conjunction of several expressions. Evaluates to true iff all child expressions are true.
* `OR` - Disjunction of several expressions. Evaluates to true iff at least one child expression is true.
* `XONE` - XONE operation. Evaluates to true iff exactly one child expression is true.
enum:
- EMPTY
- CONSTRAINT
- AND
- OR
- XONE
UiPolicyLiteral:
required:
- type
Expand All @@ -999,6 +1043,30 @@ components:
- STRING
- STRING_LIST
- JSON
PolicyDefinitionCreateRequest:
required:
- policy
- policyDefinitionId
type: object
properties:
policyDefinitionId:
type: string
description: Policy Definition ID
policy:
$ref: '#/components/schemas/UiPolicyCreateRequest'
description: "[Deprecated] Create a Policy Definition. Use PolicyDefinitionCreateDto"
deprecated: true
UiPolicyCreateRequest:
type: object
properties:
constraints:
type: array
description: Conjunction of required constraints
deprecated: true
items:
$ref: '#/components/schemas/UiPolicyConstraint'
description: "[Deprecated] Conjunction of constraints (simplified UiPolicyExpression)"
deprecated: true
PolicyDefinitionCreateDto:
required:
- expression
Expand All @@ -1011,36 +1079,6 @@ components:
expression:
$ref: '#/components/schemas/UiPolicyExpression'
description: Create a Policy Definition
UiPolicyExpression:
required:
- type
type: object
properties:
type:
$ref: '#/components/schemas/UiPolicyExpressionType'
expressions:
type: array
description: "Only for types AND, OR, XONE. List of sub-expressions to be\
\ evaluated according to the expressionType."
items:
$ref: '#/components/schemas/UiPolicyExpression'
constraint:
$ref: '#/components/schemas/UiPolicyConstraint'
description: ODRL constraint as supported by the sovity product landscape
UiPolicyExpressionType:
type: string
description: |
Ui Policy Expression types:
* `CONSTRAINT` - Expression 'a=b'
* `AND` - Conjunction of several expressions. Evaluates to true iff all child expressions are true.
* `OR` - Disjunction of several expressions. Evaluates to true iff at least one child expression is true.
* `XONE` - XONE operation. Evaluates to true iff exactly one child expression is true.
enum:
- EMPTY
- CONSTRAINT
- AND
- OR
- XONE
UiAssetEditRequest:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.sovity.edc.ext.wrapper.api.ui.model.ContractNegotiationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractTerminationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.DashboardPage;
import de.sovity.edc.ext.wrapper.api.ui.model.DataOfferCreationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.IdAvailabilityResponse;
import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateCustomTransferRequest;
Expand Down Expand Up @@ -136,6 +137,13 @@ interface UiResource {
@Operation(description = "Delete a Contract Definition")
IdResponseDto deleteContractDefinition(@PathParam("contractDefinitionId") String contractDefinitionId);

@POST
@Path("pages/create-data-offer/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(description = "Create a new asset, contract definition and optional policies. Uses the same id for the asset, the contract policy, the access policy and the contract definition")
IdResponseDto createDataOffer(DataOfferCreationRequest dataOfferCreationRequest);

@GET
@Path("pages/catalog-page/data-offers")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 sovity GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.ext.wrapper.api.ui.model;

import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest;
import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyExpression;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

@Data
@AllArgsConstructor
@RequiredArgsConstructor
@Builder(toBuilder = true)
@Schema(description = "Request to create a data offer")
public class DataOfferCreationRequest {

@Schema(description = "The asset to create", requiredMode = REQUIRED)
private UiAssetCreateRequest uiAssetCreateRequest;

@Schema(description = "Which policy to apply to this asset.", requiredMode = REQUIRED)
private PolicyDefinitionChoiceEnum policy;

@Schema(description = "Policy Expression.", requiredMode = NOT_REQUIRED)
private UiPolicyExpression uiPolicyExpression;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 sovity GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.ext.wrapper.api.ui.model;

public enum PolicyDefinitionChoiceEnum {
DONT_PUBLISH,
PUBLISH_UNRESTRICTED,
PUBLISH_RESTRICTED
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ public class PolicyDefinitionCreateDto {
@Schema(description = "Policy Expression", requiredMode = Schema.RequiredMode.REQUIRED)
private UiPolicyExpression expression;
}

Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ public static WrapperExtensionContext buildContext(
miwConfigBuilder,
selfDescriptionService
);
var dataOfferPageApiService = new DataOfferPageApiService();
var dataOfferPageApiService = new DataOfferPageApiService(
assetApiService,
contractDefinitionApiService,
policyDefinitionApiService
);
var uiResource = new UiResourceImpl(
contractAgreementApiService,
contractAgreementTransferApiService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.sovity.edc.ext.wrapper.api.ui.model.ContractNegotiationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.ContractTerminationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.DashboardPage;
import de.sovity.edc.ext.wrapper.api.ui.model.DataOfferCreationRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.IdAvailabilityResponse;
import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateCustomTransferRequest;
Expand Down Expand Up @@ -135,6 +136,11 @@ public IdResponseDto deleteContractDefinition(String contractDefinitionId) {
return contractDefinitionApiService.deleteContractDefinition(contractDefinitionId);
}

@Override
public IdResponseDto createDataOffer(DataOfferCreationRequest dataOfferCreationRequest) {
return dslContextFactory.transactionResult(trx -> dataOfferPageApiService.createDataOffer(trx, dataOfferCreationRequest));
}

@Override
public List<UiDataOffer> getCatalogPageDataOffers(String connectorEndpoint) {
return catalogApiService.fetchDataOffers(connectorEndpoint);
Expand Down
Loading

0 comments on commit 0ae66c2

Please sign in to comment.