diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java index 8cad644c21..aac16c6448 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/controllers/PolicyStoreController.java @@ -34,7 +34,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; @@ -141,10 +140,13 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr summary = "Lists the registered policies that should be accepted in EDC negotiation.", security = @SecurityRequirement(name = "api_key"), tags = { "Item Relationship Service" }, description = "Lists the registered policies that should be accepted in EDC negotiation.") - @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Returns the policies.", - content = { @Content(mediaType = APPLICATION_JSON_VALUE, array = @ArraySchema( - schema = @Schema(implementation = Policy.class))) - // TODO #199 OpenApi does not describe returned map correctly + @ApiResponses(value = { @ApiResponse(responseCode = "200", + description = "Returns the policies as map of BPN to list of policies.", + content = { @Content(mediaType = APPLICATION_JSON_VALUE, + examples = @ExampleObject( + value = PolicyResponse.BPN_TO_POLICY_MAP_EXAMPLE), + schema = @Schema( + description = "Map of BPN to list of policies")) }), @ApiResponse(responseCode = "401", description = UNAUTHORIZED_DESC, content = { @Content(mediaType = APPLICATION_JSON_VALUE, @@ -165,7 +167,9 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr public Map> getPolicies(// @RequestParam(required = false) // @ValidListOfBusinessPartnerNumbers // - @Parameter(description = "List of business partner numbers.") final List businessPartnerNumbers) { + @Parameter(description = "List of business partner numbers.") // + final List businessPartnerNumbers // + ) { final Map parameterMap = this.httpServletRequest.getParameterMap(); if (CollectionUtils.containsAny(parameterMap.keySet(), List.of("bpn", "bpns", "bpnls"))) { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java index f48f1775ef..b4c583a91a 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/models/PolicyResponse.java @@ -26,12 +26,58 @@ import org.eclipse.tractusx.irs.edc.client.policy.Policy; /** - * Policy representation for get all policies response + * Policy representation for policies response */ @Builder @Schema(example = PolicyResponse.EXAMPLE_PAYLOAD) public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { + public static final String BPN_TO_POLICY_MAP_EXAMPLE = """ + { + "BPNL1234567890AB": [ + { + "validUntil": "2025-12-12T23:59:59.999Z", + "payload": { + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/" + }, + "@id": "policy-id3", + "policy": { + "policyId": "p3", + "createdOn": "2024-03-28T03:34:42.9454448Z", + "validUntil": "2025-12-12T23:59:59.999Z", + "permissions": [ + { + "action": "USE", + "constraint": { + "and": [ + { + "leftOperand": "Membership", + "operator": { + "@id": "eq" + }, + "odrl:rightOperand": "active" + }, + { + "leftOperand": "PURPOSE", + "operator": { + "@id": "eq" + }, + "odrl:rightOperand": "ID 3.1 Trace" + } + ], + "or": null + } + } + ] + } + } + } + ], + "BPNA1234567890DF": [] + } + """; + @SuppressWarnings({ "FileTabCharacter", "java:S2479" }) @@ -44,7 +90,7 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { "@context": { "odrl": "http://www.w3.org/ns/odrl/2/" }, - "@id": "policy-id", + "@id": "policy-id1", "policy": { "odrl:permission": [ { @@ -71,9 +117,21 @@ public record PolicyResponse(OffsetDateTime validUntil, Payload payload) { ] } } + }, + { + "validUntil": "2025-12-31T23:59:59.999Z", + "payload": { + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/" + }, + "@id": "policy-id2", + "policy": { + ... + } + } } ] - """; + """; public static PolicyResponse fromPolicy(final Policy policy) { return PolicyResponse.builder()