From 8c523e71125cafa9da6b08db136c46d521d15c1b Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 13:53:26 +0200 Subject: [PATCH 1/7] fix(policy-api):[#734] return configured default policies if no custom default policy is defined --- .../services/PolicyStoreService.java | 9 +++-- .../services/PolicyStoreServiceTest.java | 36 +++++++++---------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java index 064de544d7..e9277ccf50 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreService.java @@ -41,6 +41,7 @@ import jakarta.json.JsonObject; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPoliciesProvider; import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy; import org.eclipse.tractusx.irs.edc.client.policy.Constraint; @@ -177,12 +178,16 @@ public List getStoredPolicies(final List bpnls) { public Map> getAllStoredPolicies() { final Map> bpnToPolicies = persistence.readAll(); - if (bpnToPolicies.isEmpty()) { - return Map.of("", allowedPoliciesFromConfig); + if (containsNoDefaultPolicyAvailable(bpnToPolicies)) { + bpnToPolicies.put("default", allowedPoliciesFromConfig); } return bpnToPolicies; } + private static boolean containsNoDefaultPolicyAvailable(final Map> bpnToPolicies) { + return bpnToPolicies.keySet().stream().noneMatch(key -> StringUtils.isEmpty(key) || DEFAULT.equals(key)); + } + public void deletePolicy(final String policyId) { log.info("Getting all policies to find correct BPN"); final List bpnsContainingPolicyId = PolicyHelper.findBpnsByPolicyId(getAllStoredPolicies(), policyId); diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java index ff40670cfb..9d473c9e04 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java @@ -24,7 +24,6 @@ package org.eclipse.tractusx.irs.policystore.services; import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; @@ -37,6 +36,7 @@ import java.time.Clock; import java.time.OffsetDateTime; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -313,7 +313,7 @@ class GetAcceptedPoliciesTests { void getAcceptedPolicies_whenParameterBpnIsNull_shouldReturnTheConfiguredDefaultPolicy() { // ARRANGE - when(persistenceMock.readAll()).thenReturn(emptyMap()); + when(persistenceMock.readAll()).thenReturn(new HashMap<>()); // ACT final var acceptedPolicies = testee.getAcceptedPolicies(null); @@ -389,12 +389,12 @@ void deletePolicyForEachBpn_success() { void deletePolicy_deleteSuccessful() { // ARRANGE final String policyId = randomPolicyId(); - when(persistenceMock.readAll()).thenReturn(Map.of(BPN, List.of(Policy.builder() - .policyId(policyId) - .createdOn(null) - .validUntil(null) - .permissions(null) - .build()))); + when(persistenceMock.readAll()).thenReturn(new HashMap<>(Map.of(BPN, List.of(Policy.builder() + .policyId(policyId) + .createdOn(null) + .validUntil(null) + .permissions(null) + .build())))); // ACT testee.deletePolicy(policyId); @@ -408,12 +408,12 @@ void deletePolicy_exceptionFromPolicyPersistence_shouldReturnHttpStatus500() { // ACT final String policyId = randomPolicyId(); - when(persistenceMock.readAll()).thenReturn(Map.of(BPN, List.of(Policy.builder() - .policyId(policyId) - .createdOn(null) - .validUntil(null) - .permissions(null) - .build()))); + when(persistenceMock.readAll()).thenReturn(new HashMap<>(Map.of(BPN, List.of(Policy.builder() + .policyId(policyId) + .createdOn(null) + .validUntil(null) + .permissions(null) + .build())))); doThrow(new PolicyStoreException("")).when(persistenceMock).delete(BPN, policyId); // ASSERT @@ -428,7 +428,7 @@ void deletePolicy_whenPolicyNotFound_shouldReturnHttpStatus404() { final String notExistingPolicyId = randomPolicyId(); final String policyId = randomPolicyId(); when(persistenceMock.readAll()).thenReturn( - Map.of(BPN, List.of(Policy.builder().policyId(policyId).build()))); + new HashMap<>(Map.of(BPN, List.of(Policy.builder().policyId(policyId).build())))); // ASSERT assertThatThrownBy(() -> testee.deletePolicy(notExistingPolicyId)).isInstanceOf( @@ -463,7 +463,7 @@ void updatePolicies_shouldUpdateBpnAndValidUntil() { .validUntil(originalValidUntil) .permissions(permissions) .build(); - when(persistenceMock.readAll()).thenReturn(Map.of(originalBpn, List.of(testPolicy))); + when(persistenceMock.readAll()).thenReturn(new HashMap<>(Map.of(originalBpn, List.of(testPolicy)))); // get policies for bpn when(persistenceMock.readAll(originalBpn)).thenReturn(List.of(testPolicy)); @@ -498,7 +498,7 @@ void updatePolicies_shouldAddPolicyToEachBpn() { .validUntil(validUntil) .permissions(permissions) .build(); - when(persistenceMock.readAll()).thenReturn(Map.of("bpn2", List.of(testPolicy))); + when(persistenceMock.readAll()).thenReturn(new HashMap<>(Map.of("bpn2", List.of(testPolicy)))); when(persistenceMock.readAll("bpn2")).thenReturn(List.of(testPolicy)); // ACT @@ -547,7 +547,7 @@ void updatePolicies_shouldAssociateEachGivenPolicyWithEachGivenBpn() { // BPN1 without any policies // BPN2 with testPolicy1 and testPolicy2 - when(persistenceMock.readAll()).thenReturn(Map.of(bpn2, List.of(testPolicy1, testPolicy2))); + when(persistenceMock.readAll()).thenReturn(new HashMap<>(Map.of(bpn2, List.of(testPolicy1, testPolicy2)))); when(persistenceMock.readAll(bpn2)).thenReturn(List.of(Policy.builder() .policyId(policyId1) .createdOn(createdOn) From b2295d17101af14ca19def104a04b646876e6266 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 14:02:41 +0200 Subject: [PATCH 2/7] fix(policy-api):[#734] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aadcf2980f..c89101cf15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha ### Fixed - Access and Usage Policy Validation flow correction. #757 +- GET /irs/policies and GET /irs/policies/paged return the configured default policies if no custom default policy is defined now. #734 ### Changed From 9820f43bb2f53038039f39affaf92e650dcbdc44 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 16:01:46 +0200 Subject: [PATCH 3/7] chore(policy-api): [#734] allow to filter for default policy via businessPartnerNumbers=default --- docs/src/api/irs-api.yaml | 6 +- .../controllers/PolicyStoreController.java | 10 +- .../BusinessPartnerNumberListValidator.java | 23 ++++- .../ValidListOfBusinessPartnerNumbers.java | 2 + .../services/PolicyStoreServiceTest.java | 3 - ...usinessPartnerNumberListValidatorTest.java | 96 +++++++++++++++++-- 6 files changed, 118 insertions(+), 22 deletions(-) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index b51cc259b3..ac3b68acd3 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -797,7 +797,8 @@ paths: description: Lists the registered policies that should be accepted in EDC negotiation. operationId: getAllowedPoliciesByBpn parameters: - - description: List of business partner numbers. + - description: List of business partner numbers. This may also contain the value + "default" in order to query the default policies. in: query name: businessPartnerNumbers required: false @@ -988,7 +989,8 @@ paths: Example: `page=1&size=20` operationId: getPoliciesPaged parameters: - - description: List of business partner numbers. + - description: List of business partner numbers. This may also contain the value + "default" in order to query the default policies. in: query name: businessPartnerNumbers required: false 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 2aa0e850ac..99083688e3 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 @@ -192,8 +192,9 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr @PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')") public Map> getPolicies(// @RequestParam(required = false) // - @ValidListOfBusinessPartnerNumbers // - @Parameter(description = "List of business partner numbers.") // + @ValidListOfBusinessPartnerNumbers(allowDefault = true) // + @Parameter(description = "List of business partner numbers. " + + "This may also contain the value \"default\" in order to query the default policies.") // final List businessPartnerNumbers // ) { @@ -256,8 +257,9 @@ public Page getPoliciesPaged(// @Parameter(description = "Page configuration", hidden = true) // final Pageable pageable, // @RequestParam(required = false) // - @ValidListOfBusinessPartnerNumbers // - @Parameter(name = "businessPartnerNumbers", description = "List of business partner numbers.") // + @ValidListOfBusinessPartnerNumbers(allowDefault = true) // + @Parameter(name = "businessPartnerNumbers", description = "List of business partner numbers. " + + "This may also contain the value \"default\" in order to query the default policies.") // final List businessPartnerNumbers) { if (pageable.getPageSize() > MAX_PAGE_SIZE) { diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidator.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidator.java index a487906cb5..26e34249a6 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidator.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidator.java @@ -31,6 +31,8 @@ public class BusinessPartnerNumberListValidator implements ConstraintValidator> { + private static final String DEFAULT = "default"; + /** * Regex for BPN. */ @@ -38,16 +40,29 @@ public class BusinessPartnerNumberListValidator private static final Pattern PATTERN = Pattern.compile(BPN_REGEX); + private boolean allowDefault; + + @Override + public void initialize(final ValidListOfBusinessPartnerNumbers constraintAnnotation) { + this.allowDefault = constraintAnnotation.allowDefault(); + } + @Override - public boolean isValid(final List value, final ConstraintValidatorContext context) { + public boolean isValid(final List businessPartnerNumbers, final ConstraintValidatorContext context) { // allow null and empty here (in order to allow flexible combination with @NotNull and @NotEmpty) - if (value == null || value.isEmpty()) { + if (businessPartnerNumbers == null || businessPartnerNumbers.isEmpty()) { return true; } - for (int index = 0; index < value.size(); index++) { - if (!PATTERN.matcher(value.get(index)).matches()) { + for (int index = 0; index < businessPartnerNumbers.size(); index++) { + final String bpn = businessPartnerNumbers.get(index); + + if (allowDefault && DEFAULT.equals(bpn)) { + return true; + } + + if (!PATTERN.matcher(bpn).matches()) { context.disableDefaultConstraintViolation(); final String msg = "The business partner number at index %d is invalid (should conform to pattern '%s')"; context.buildConstraintViolationWithTemplate(msg.formatted(index, BPN_REGEX)).addConstraintViolation(); diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java index 44b11e0a11..ad2501498e 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java @@ -44,4 +44,6 @@ Class[] groups() default { }; Class[] payload() default { }; + + boolean allowDefault() default false; } diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java index 9d473c9e04..27857d9483 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/services/PolicyStoreServiceTest.java @@ -312,9 +312,6 @@ class GetAcceptedPoliciesTests { @Test void getAcceptedPolicies_whenParameterBpnIsNull_shouldReturnTheConfiguredDefaultPolicy() { - // ARRANGE - when(persistenceMock.readAll()).thenReturn(new HashMap<>()); - // ACT final var acceptedPolicies = testee.getAcceptedPolicies(null); diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java index 50e0f7d191..b577b7796a 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java @@ -21,11 +21,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; +import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collections; import java.util.List; import jakarta.validation.ConstraintValidatorContext; +import jakarta.validation.Payload; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -33,7 +35,6 @@ import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -43,9 +44,6 @@ class BusinessPartnerNumberListValidatorTest { public static final String VALID_BPN_1 = "BPNL1234567890AB"; public static final String VALID_BPN_2 = "BPNL123456789012"; - @InjectMocks - private BusinessPartnerNumberListValidator validator; - @Captor private ArgumentCaptor messageCaptor; @@ -54,24 +52,26 @@ class BusinessPartnerNumberListValidatorTest { @Test void withEmptyListOfStrings() { - assertThat(validator.isValid(Collections.emptyList(), contextMock)).isTrue(); + assertThat(new BusinessPartnerNumberListValidatorBuilder().build() + .isValid(Collections.emptyList(), + contextMock)).isTrue(); } @Test void withNull() { - assertThat(validator.isValid(null, contextMock)).isTrue(); + assertThat(new BusinessPartnerNumberListValidatorBuilder().build().isValid(null, contextMock)).isTrue(); } @Test void withValidListOfStrings() { List validList = Arrays.asList(VALID_BPN_1, VALID_BPN_2); - assertThat(validator.isValid(validList, contextMock)).isTrue(); + assertThat(new BusinessPartnerNumberListValidatorBuilder().build().isValid(validList, contextMock)).isTrue(); } @Test void withListContainingInvalidBPN() { List invalidList = Arrays.asList(VALID_BPN_1, "INVALID_BPN", VALID_BPN_2); - assertThat(validator.isValid(invalidList, contextMock)).isFalse(); + assertThat(new BusinessPartnerNumberListValidatorBuilder().build().isValid(invalidList, contextMock)).isFalse(); verify(contextMock).buildConstraintViolationWithTemplate(messageCaptor.capture()); assertThat(messageCaptor.getValue()).contains("BPN").contains(" index 1 ").contains("invalid"); } @@ -86,8 +86,86 @@ void withListContainingInvalidBPN() { "ERRRES" }) void withInvalidBPN(final String invalidBPN) { - assertThat(validator.isValid(Collections.singletonList(invalidBPN), contextMock)).isFalse(); + assertThat(new BusinessPartnerNumberListValidatorBuilder().build() + .isValid(Collections.singletonList(invalidBPN), + contextMock)).isFalse(); verify(contextMock).buildConstraintViolationWithTemplate(messageCaptor.capture()); assertThat(messageCaptor.getValue()).contains("BPN").contains(" index 0 ").contains("invalid"); } + + @Test + void withAllowDefaultTrue_goodCase() { + final BusinessPartnerNumberListValidator validator = new BusinessPartnerNumberListValidatorBuilder().allowDefault( + true).build(); + final List listWithDefault = Arrays.asList("BPNL1234567890AB", "default"); + assertThat(validator.isValid(listWithDefault, contextMock)).isTrue(); + } + + @Test + void withAllowDefaultTrue_badCase() { + final BusinessPartnerNumberListValidator validator = new BusinessPartnerNumberListValidatorBuilder().build(); + final List listWithDefault = Arrays.asList("BPNL1234567890AB", "default"); + assertThat(validator.isValid(listWithDefault, contextMock)).isFalse(); + verify(contextMock).buildConstraintViolationWithTemplate(messageCaptor.capture()); + assertThat(messageCaptor.getValue()).startsWith("The business partner number at index 1 is invalid"); + } + + /** + * Builder for BusinessPartnerNumberListValidator. + */ + public static class BusinessPartnerNumberListValidatorBuilder { + + private String message = "Invalid list of business partner numbers"; + private Class[] groups = new Class[0]; + private Class[] payload = new Class[0]; + private boolean allowDefault = false; + + public BusinessPartnerNumberListValidatorBuilder setMessage(String message) { + this.message = message; + return this; + } + + public BusinessPartnerNumberListValidatorBuilder setGroups(Class[] groups) { + this.groups = groups; + return this; + } + + public BusinessPartnerNumberListValidatorBuilder setPayload(Class[] payload) { + this.payload = payload; + return this; + } + + public BusinessPartnerNumberListValidatorBuilder allowDefault(boolean allowDefault) { + this.allowDefault = allowDefault; + return this; + } + + public BusinessPartnerNumberListValidator build() { + ValidListOfBusinessPartnerNumbers annotation = new ValidListOfBusinessPartnerNumbers() { + public Class annotationType() { + return ValidListOfBusinessPartnerNumbers.class; + } + + public String message() { + return message; + } + + public Class[] groups() { + return groups; + } + + public Class[] payload() { + return payload; + } + + public boolean allowDefault() { + return allowDefault; + } + }; + + final BusinessPartnerNumberListValidator validator = new BusinessPartnerNumberListValidator(); + validator.initialize(annotation); + return validator; + } + } } From 99abd6184668a6f0cdf12e010250e07851ab7e49 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 16:30:24 +0200 Subject: [PATCH 4/7] chore(policy-api): [#734] update insomnia request collection - add "Register a default policy" - add more parameters to "Find policies (paged)" and add some descriptions --- .../IRS_Request_Collection.json | 96 ++++++++++++++++--- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/local/testing/request-collection/IRS_Request_Collection.json b/local/testing/request-collection/IRS_Request_Collection.json index dddf737b78..fb7ee04717 100644 --- a/local/testing/request-collection/IRS_Request_Collection.json +++ b/local/testing/request-collection/IRS_Request_Collection.json @@ -130,56 +130,91 @@ "id": "pair_0b54166258504534a4485bf109444618", "name": "sort", "value": "bpn,asc", - "description": "", + "description": "Sort by BPN ascending", "disabled": false }, { "id": "pair_beea0b998a0c4afbb0d1288b2ed73ee4", "name": "sort", "value": "policyId,asc", - "description": "", + "description": "Sort by policyId ascending", "disabled": false }, { "id": "pair_46baddf55de8401baae8c5a1c0dda650", "name": "sort", "value": "action,asc", - "description": "", + "description": "Sort by action ascending", "disabled": false }, { "id": "pair_479d0c25e9b04af8bf79647e55287cbd", "name": "sort", "value": "validUntil,asc", - "description": "", + "description": "Sort by validUntil ascending", "disabled": true }, { "id": "pair_5d1ba9763a7640cab07c6faa153b42c5", "name": "sort", "value": "createdOn,asc", - "description": "", + "description": "Sort by createdOn ascending", "disabled": true }, { "id": "pair_09ae1cec1dc74a38a16a410dbfcedfab", "name": "search", "value": "validUntil,AFTER_LOCAL_DATE,2024-06-04", - "description": "", + "description": "Filter / search all where validUntil is after the given date string", "disabled": true }, { "id": "pair_9d1b8c086d74456f86c88123d9ec940a", "name": "search", "value": "BPN,STARTS_WITH,BPNL12", - "description": "", - "disabled": false + "description": "Filter / search by BPN starting with the given string", + "disabled": true }, { "id": "pair_ad26500e1b5e41759f59881d1ceaca1a", "name": "search", "value": "action,EQUALS,use", - "description": "", + "description": "Filter / search by action", + "disabled": false + }, + { + "id": "pair_ad26500e1b5e41759f59881d1ceaca1b", + "name": "search", + "value": "policyId,STARTS_WITH,policy4", + "description": "Filter / search by policyId starting with the given string", + "disabled": false + }, + { + "id": "pair_ad26500e1b5e41759f59881d1ceaca1c", + "name": "page", + "value": "0", + "description": "The requested page", + "disabled": false + }, + { + "id": "pair_ad26500e1b5e41759f59881d1ceaca1d", + "name": "size", + "value": "10", + "description": "The page size", + "disabled": false + }, + { + "id": "pair_ad26500e1b5e41759f59881d1ceaca1e", + "name": "businessPartnerNumbers", + "value": "default", + "description": "Only default policies", + "disabled": false + }, + { + "id": "pair_ad26500e1b5e41759f59881d1ceaca1f", + "name": "search", + "value": "BPN,EQUALS,default", + "description": "Only default policies (same as the parameter businessPartnerNumbers)", "disabled": false } ], @@ -208,7 +243,7 @@ "modified": 1702990529632, "created": 1687243204155, "url": "{{IRS_HOST}}/irs/policies/{% prompt 'policyId', '', 'traceability-test', '', false, true %}", - "name": "Delete policy", + "name": "Delete policy by ID", "description": "", "method": "DELETE", "body": {}, @@ -311,6 +346,45 @@ "settingFollowRedirects": "global", "_type": "request" }, + { + "_id": "req_48a45cea23df4839879e1e813945f6aa", + "parentId": "fld_ad061853620b45c397a7906a6e566930", + "modified": 1717571530832, + "created": 1687243182397, + "url": "{{IRS_HOST}}/irs/policies", + "name": "Register a default policy", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"validUntil\": \"2025-12-12T23:59:59.999Z\",\n\t\"payload\":\n\t\t{\n\t\t\t\"@context\": {\n\t\t\t\t\"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n\t\t\t},\n\t\t\t\"@id\": \"my-default-policy-1\",\n\t\t\t\"policy\": {\n\t\t\t\t\"odrl:permission\": [\n\t\t\t\t\t{\n\t\t\t\t\t\t\"action\": \"use\",\n\t\t\t\t\t\t\"constraint\": {\n\t\t\t\t\t\t\t\"and\": [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"leftOperand\": \"Membership\",\n\t\t\t\t\t\t\t\t\t\"operator\": {\n\t\t\t\t\t\t\t\t\t\t\"@id\": \"odrl:eq\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\"rightOperand\": \"active\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"leftOperand\": \"PURPOSE\",\n\t\t\t\t\t\t\t\t\t\"operator\": {\n\t\t\t\t\t\t\t\t\t\t\"@id\": \"odrl:eq\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\"odrl:rightOperand\": \"Testtestetstetsatse\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t}\n}" + }, + "preRequestScript": "", + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "authentication": { + "type": "apikey", + "disabled": false, + "key": "X-API-KEY", + "value": "{{ _.ADMIN_API_KEY }}", + "addTo": "header" + }, + "metaSortKey": -1683962737633.5, + "isPrivate": false, + "pathParameters": [], + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, { "_id": "req_f966b9c4faa7496fa62c1bd2b3a8fd6a", "parentId": "fld_0ff5cc68c4964d86916293ab602e8681", @@ -3779,7 +3853,7 @@ "modified": 1717577274756, "created": 1717577274756, "url": "{{ _.PROVIDER_CONTROLPLANE_1 }}/management/v2/policydefinitions/request", - "name": "Get all Policies", + "name": "Get all policies", "description": "", "method": "POST", "body": { From 902469bbc8de95bc052d74c3dd2536052654175f Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 17:13:35 +0200 Subject: [PATCH 5/7] chore(policy-api): [#734] update insomnia request collection - add filter for default policies to "Get policies for BPN" - add some descriptions --- .../IRS_Request_Collection.json | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/local/testing/request-collection/IRS_Request_Collection.json b/local/testing/request-collection/IRS_Request_Collection.json index fb7ee04717..f937d7cfad 100644 --- a/local/testing/request-collection/IRS_Request_Collection.json +++ b/local/testing/request-collection/IRS_Request_Collection.json @@ -85,15 +85,22 @@ "id": "pair_8482da576c10480b9f7edf7a4aa752c6", "name": "businessPartnerNumbers", "value": "BPNL1234567890AB", - "description": "", + "description": "Get policies for the given BPN", "disabled": false }, { "id": "pair_ec0ce8fad21144aaa531cbbcb941f522", "name": "businessPartnerNumbers", - "value": "BPNL1234567890XX", - "description": "", + "value": "BPNL9834567890CD", + "description": "Get policies for the given BPN", "disabled": false + }, + { + "id": "pair_ec0ce8fad21144aaa531cbbcb941f533", + "name": "businessPartnerNumbers", + "value": "default", + "description": "Get the default policies", + "disabled": true } ], "headers": [], @@ -180,14 +187,14 @@ "name": "search", "value": "action,EQUALS,use", "description": "Filter / search by action", - "disabled": false + "disabled": true }, { "id": "pair_ad26500e1b5e41759f59881d1ceaca1b", "name": "search", "value": "policyId,STARTS_WITH,policy4", "description": "Filter / search by policyId starting with the given string", - "disabled": false + "disabled": true }, { "id": "pair_ad26500e1b5e41759f59881d1ceaca1c", @@ -208,14 +215,14 @@ "name": "businessPartnerNumbers", "value": "default", "description": "Only default policies", - "disabled": false + "disabled": true }, { "id": "pair_ad26500e1b5e41759f59881d1ceaca1f", "name": "search", "value": "BPN,EQUALS,default", "description": "Only default policies (same as the parameter businessPartnerNumbers)", - "disabled": false + "disabled": true } ], "headers": [], From 0f78d25cee17e7150eb006edf33ac5e399024ec2 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 17:53:29 +0200 Subject: [PATCH 6/7] chore(policy-api): [#734] CodeQL warnings --- .../BusinessPartnerNumberListValidatorTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java index b577b7796a..e4de073196 100644 --- a/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java +++ b/irs-policy-store/src/test/java/org/eclipse/tractusx/irs/policystore/validators/BusinessPartnerNumberListValidatorTest.java @@ -141,23 +141,30 @@ public BusinessPartnerNumberListValidatorBuilder allowDefault(boolean allowDefau } public BusinessPartnerNumberListValidator build() { - ValidListOfBusinessPartnerNumbers annotation = new ValidListOfBusinessPartnerNumbers() { + + final var annotation = new ValidListOfBusinessPartnerNumbers() { + + @Override public Class annotationType() { return ValidListOfBusinessPartnerNumbers.class; } + @Override public String message() { return message; } + @Override public Class[] groups() { return groups; } + @Override public Class[] payload() { return payload; } + @Override public boolean allowDefault() { return allowDefault; } From c48111b148ba3d7f5bc5925316abb516e05677e5 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 11 Jul 2024 18:06:47 +0200 Subject: [PATCH 7/7] chore(policy-api): [#734] javadoc --- .../validators/ValidListOfBusinessPartnerNumbers.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java index ad2501498e..e2929338db 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/validators/ValidListOfBusinessPartnerNumbers.java @@ -45,5 +45,12 @@ Class[] payload() default { }; + /** + * Whether to allow "default" as a valid value + * (This is used in {@link org.eclipse.tractusx.irs.policystore.controllers.PolicyStoreController} + * for filtering default policies). + * + * @return the value of the flag + */ boolean allowDefault() default false; }