Skip to content

Commit

Permalink
feat: id availability check endpoints (#1003)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Christophe Loiseau <[email protected]>
  • Loading branch information
kamilczaja and ununhexium authored Jul 18, 2024
1 parent d185e6b commit a78b169
Show file tree
Hide file tree
Showing 11 changed files with 512 additions and 234 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).
#### Minor Changes

- Both providers and consumers can now terminate their contracts.
- Added endpoints for checking ID availability for policies, assets and contract definitions

#### Patch Changes

Expand Down
75 changes: 73 additions & 2 deletions docs/api/postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "a842e697-4b5e-4308-b802-35c446ea6135",
"_postman_id": "14267003-be4b-40ee-a9b6-83b5dd32ba57",
"name": "sovity EDC Community Edition",
"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",
Expand Down Expand Up @@ -735,6 +735,77 @@
]
}
]
},
{
"name": "Data Offer",
"item": [
{
"name": "Check Policy ID Availability",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{CONSUMER_EDC_MANAGEMENT_URL}}/wrapper/ui/pages/data-offer-page/validate-policy-id/{{POLICY_ID}}",
"host": [
"{{CONSUMER_EDC_MANAGEMENT_URL}}"
],
"path": [
"wrapper",
"ui",
"pages",
"data-offer-page",
"validate-policy-id",
"{{POLICY_ID}}"
]
}
},
"response": []
},
{
"name": "Check Asset ID Availability",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{CONSUMER_EDC_MANAGEMENT_URL}}/wrapper/ui/pages/data-offer-page/validate-asset-id/{{ASSET_ID}}",
"host": [
"{{CONSUMER_EDC_MANAGEMENT_URL}}"
],
"path": [
"wrapper",
"ui",
"pages",
"data-offer-page",
"validate-asset-id",
"{{ASSET_ID}}"
]
}
},
"response": []
},
{
"name": "Check Contract Definition ID Availability",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{CONSUMER_EDC_MANAGEMENT_URL}}/wrapper/ui/pages/data-offer-page/validate-contract-definition-id/{{CONTRACT_DEFINITION_ID}}",
"host": [
"{{CONSUMER_EDC_MANAGEMENT_URL}}"
],
"path": [
"wrapper",
"ui",
"pages",
"data-offer-page",
"validate-contract-definition-id",
"{{CONTRACT_DEFINITION_ID}}"
]
}
},
"response": []
}
]
}
]
},
Expand Down Expand Up @@ -2002,4 +2073,4 @@
"type": "default"
}
]
}
}
69 changes: 69 additions & 0 deletions docs/api/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,63 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/IdResponseDto'
/wrapper/ui/pages/data-offer-page/validate-asset-id/{assetId}:
get:
tags:
- UI
description: Validates if the provided assetId is already taken
operationId: isAssetIdAvailable
parameters:
- name: assetId
in: path
required: true
schema:
type: string
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdAvailabilityResponse'
/wrapper/ui/pages/data-offer-page/validate-contract-definition-id/{contractDefinitionId}:
get:
tags:
- UI
description: Validates if the provided contractDefinitionId is already taken
operationId: isContractDefinitionIdAvailable
parameters:
- name: contractDefinitionId
in: path
required: true
schema:
type: string
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdAvailabilityResponse'
/wrapper/ui/pages/data-offer-page/validate-policy-id/{policyId}:
get:
tags:
- UI
description: Validates if the provided policyId is already taken
operationId: isPolicyIdAvailable
parameters:
- name: policyId
in: path
required: true
schema:
type: string
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/IdAvailabilityResponse'
/wrapper/ui/pages/content-agreement-page/{contractAgreementId}/terminate:
post:
tags:
Expand Down Expand Up @@ -1784,6 +1841,18 @@ components:
description: Additional transfer process properties. These are not passed
to the consumer EDC
description: "For type PARAMS_ONLY: Required data for starting a Transfer Process"
IdAvailabilityResponse:
required:
- id
type: object
properties:
id:
type: string
description: ID
available:
type: boolean
description: Object indicates whether an ID for the given object type is already
taken or not
ContractTerminationRequest:
required:
- detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.sovity.edc.extension.e2e.extension.E2eScenario;
import de.sovity.edc.extension.e2e.extension.E2eTestExtension;
import de.sovity.edc.extension.e2e.extension.Provider;
import de.sovity.edc.extension.utils.junit.DisabledOnGithub;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -34,6 +35,7 @@
@ExtendWith(E2eTestExtension.class)
class ContractAgreementTerminationDetailsQueryTest {

@DisabledOnGithub
@Test
void fetchAgreementDetailsOrThrow_whenAgreementIsPresent_shouldReturnTheAgreementDetails(
E2eScenario scenario,
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.IdAvailabilityResponse;
import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateCustomTransferRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateTransferRequest;
Expand Down Expand Up @@ -187,4 +188,22 @@ IdResponseDto terminateContractAgreement(
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Queries a transfer process' asset")
UiAsset getTransferProcessAsset(@PathParam("transferProcessId") String transferProcessId);

@GET
@Path("pages/data-offer-page/validate-policy-id/{policyId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Validates if the provided policyId is already taken")
IdAvailabilityResponse isPolicyIdAvailable(@PathParam("policyId") String policyId);

@GET
@Path("pages/data-offer-page/validate-asset-id/{assetId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Validates if the provided assetId is already taken")
IdAvailabilityResponse isAssetIdAvailable(@PathParam("assetId") String assetId);

@GET
@Path("pages/data-offer-page/validate-contract-definition-id/{contractDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Validates if the provided contractDefinitionId is already taken")
IdAvailabilityResponse isContractDefinitionIdAvailable(@PathParam("contractDefinitionId") String contractDefinitionId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.sovity.edc.ext.wrapper.api.ui.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@AllArgsConstructor
@RequiredArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "Object indicates whether an ID for the given object type is already taken or not")
public class IdAvailabilityResponse {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED)
private final String id;

@Schema(description = "ID Availability", requiredMode = Schema.RequiredMode.REQUIRED)
private boolean isAvailable;
}

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.MiwConfigService;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.OwnConnectorEndpointServiceImpl;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.SelfDescriptionService;
import de.sovity.edc.ext.wrapper.api.ui.pages.data_offer.DataOfferPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
Expand Down Expand Up @@ -252,6 +253,7 @@ public static WrapperExtensionContext buildContext(
miwConfigBuilder,
selfDescriptionService
);
var dataOfferPageApiService = new DataOfferPageApiService();
var uiResource = new UiResourceImpl(
contractAgreementApiService,
contractAgreementTransferApiService,
Expand All @@ -264,7 +266,8 @@ public static WrapperExtensionContext buildContext(
contractDefinitionApiService,
contractNegotiationApiService,
dashboardApiService,
dslContextFactory
dslContextFactory,
dataOfferPageApiService
);

// Use Case API
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.IdAvailabilityResponse;
import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateCustomTransferRequest;
import de.sovity.edc.ext.wrapper.api.ui.model.InitiateTransferRequest;
Expand All @@ -41,15 +42,12 @@
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.DashboardPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.data_offer.DataOfferPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
import de.sovity.edc.extension.db.directaccess.DslContextFactory;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validation;
import jakarta.validation.ValidatorFactory;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -72,6 +70,7 @@ public class UiResourceImpl implements UiResource {
private final ContractNegotiationApiService contractNegotiationApiService;
private final DashboardPageApiService dashboardPageApiService;
private final DslContextFactory dslContextFactory;
private final DataOfferPageApiService dataOfferPageApiService;

@Override
public DashboardPage getDashboardPage() {
Expand Down Expand Up @@ -178,4 +177,22 @@ public TransferHistoryPage getTransferHistoryPage() {
public UiAsset getTransferProcessAsset(String transferProcessId) {
return transferHistoryPageAssetFetcherService.getAssetForTransferHistoryPage(transferProcessId);
}

@Override
public IdAvailabilityResponse isPolicyIdAvailable(String policyId) {
return dslContextFactory.transactionResult(dsl ->
dataOfferPageApiService.checkIfPolicyIdAvailable(dsl, policyId));
}

@Override
public IdAvailabilityResponse isAssetIdAvailable(String assetId) {
return dslContextFactory.transactionResult(dsl ->
dataOfferPageApiService.checkIfAssetIdAvailable(dsl, assetId));
}

@Override
public IdAvailabilityResponse isContractDefinitionIdAvailable(String contractDefinitionId) {
return dslContextFactory.transactionResult(dsl ->
dataOfferPageApiService.checkIfContractDefinitionIdAvailable(dsl, contractDefinitionId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package de.sovity.edc.ext.wrapper.api.ui.pages.data_offer;

import de.sovity.edc.ext.db.jooq.Tables;
import de.sovity.edc.ext.wrapper.api.ui.model.IdAvailabilityResponse;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import org.jooq.Table;
import org.jooq.TableField;

@RequiredArgsConstructor
public class DataOfferPageApiService {
@NotNull
public IdAvailabilityResponse checkIfPolicyIdAvailable(DSLContext dsl, String id) {
val table = Tables.EDC_POLICYDEFINITIONS;
val field = table.POLICY_ID;

return new IdAvailabilityResponse(id, isIdAvailable(dsl, table, field, id));
}

@NotNull
public IdAvailabilityResponse checkIfAssetIdAvailable(DSLContext dsl, String id) {
val table = Tables.EDC_ASSET;
val field = table.ASSET_ID;

return new IdAvailabilityResponse(id, isIdAvailable(dsl, table, field, id));
}

@NotNull
public IdAvailabilityResponse checkIfContractDefinitionIdAvailable(DSLContext dsl, String id) {
val table = Tables.EDC_CONTRACT_DEFINITIONS;
val field = table.CONTRACT_DEFINITION_ID;

return new IdAvailabilityResponse(id, isIdAvailable(dsl, table, field, id));
}

private boolean isIdAvailable(DSLContext dsl, Table<?> table, TableField<?, String> idField, String id) {
return !dsl.fetchExists(
dsl.select(idField)
.from(table)
.where(idField.eq(id))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void limitTheReasonSizeAt100Chars(
// termination completed == success
}

@DisabledOnGithub
@Test
void limitTheDetailSizeAt1000Chars(
E2eScenario scenario,
Expand Down
Loading

0 comments on commit a78b169

Please sign in to comment.