From 5ad5fd61d3aa5ef5b5558a548f656c0de48f21fc Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Thu, 4 Jul 2024 15:51:55 +0200 Subject: [PATCH] feat(policy-api):[#639] cleanup using static imports --- .../common/SearchParameterParser.java | 13 ++++--- .../controllers/PolicyStoreController.java | 5 ++- .../services/PolicyPagingService.java | 34 +++++++++++-------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/SearchParameterParser.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/SearchParameterParser.java index d6095d2c1..6d1d1c27e 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/SearchParameterParser.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/common/SearchParameterParser.java @@ -19,6 +19,11 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.policystore.common; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_ACTION; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_BPN; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_CREATED_ON; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_POLICY_ID; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_VALID_UNTIL; import static org.eclipse.tractusx.irs.policystore.models.SearchCriteria.Operation.BETWEEN; import java.util.ArrayList; @@ -35,11 +40,9 @@ @Getter public class SearchParameterParser { - public static final List SUPPORTED_PROPERTIES = List.of(CommonConstants.PROPERTY_BPN, - CommonConstants.PROPERTY_VALID_UNTIL, CommonConstants.PROPERTY_POLICY_ID, - CommonConstants.PROPERTY_CREATED_ON, CommonConstants.PROPERTY_ACTION); - public static final List DATE_PROPERTIES = List.of(CommonConstants.PROPERTY_VALID_UNTIL, - CommonConstants.PROPERTY_CREATED_ON); + public static final List SUPPORTED_PROPERTIES = List.of(PROPERTY_BPN, PROPERTY_VALID_UNTIL, + PROPERTY_POLICY_ID, PROPERTY_CREATED_ON, PROPERTY_ACTION); + public static final List DATE_PROPERTIES = List.of(PROPERTY_VALID_UNTIL, PROPERTY_CREATED_ON); public static final String CRITERIA_INNER_SEPARATOR = ","; public static final int NUM_PARTS_OF_FILTERS = 3; 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 a4188b2ef..76e8a7913 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 @@ -25,6 +25,7 @@ import static org.eclipse.tractusx.irs.common.ApiConstants.FORBIDDEN_DESC; import static org.eclipse.tractusx.irs.common.ApiConstants.UNAUTHORIZED_DESC; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_BPN; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import java.util.AbstractMap; @@ -52,7 +53,6 @@ import org.eclipse.tractusx.irs.data.JsonParseException; import org.eclipse.tractusx.irs.dtos.ErrorResponse; import org.eclipse.tractusx.irs.edc.client.policy.Policy; -import org.eclipse.tractusx.irs.policystore.common.CommonConstants; import org.eclipse.tractusx.irs.policystore.common.SearchParameterParser; import org.eclipse.tractusx.irs.policystore.models.CreatePoliciesResponse; import org.eclipse.tractusx.irs.policystore.models.CreatePolicyRequest; @@ -215,8 +215,7 @@ public Map> getPolicies(// @ResponseStatus(HttpStatus.OK) @PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')") public Page getPoliciesPaged(// - @PageableDefault(size = DEFAULT_PAGE_SIZE, sort = CommonConstants.PROPERTY_BPN, - direction = Sort.Direction.ASC) // + @PageableDefault(size = DEFAULT_PAGE_SIZE, sort = PROPERTY_BPN, direction = Sort.Direction.ASC) // final Pageable pageable, // @RequestParam(required = false) // @ValidListOfBusinessPartnerNumbers // diff --git a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyPagingService.java b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyPagingService.java index 4efd14db4..00cb666c5 100644 --- a/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyPagingService.java +++ b/irs-policy-store/src/main/java/org/eclipse/tractusx/irs/policystore/services/PolicyPagingService.java @@ -19,6 +19,11 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.policystore.services; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_ACTION; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_BPN; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_CREATED_ON; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_POLICY_ID; +import static org.eclipse.tractusx.irs.policystore.common.CommonConstants.PROPERTY_VALID_UNTIL; import static org.eclipse.tractusx.irs.policystore.models.SearchCriteria.Operation.EQUALS; import static org.eclipse.tractusx.irs.policystore.models.SearchCriteria.Operation.STARTS_WITH; @@ -31,7 +36,6 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.irs.edc.client.policy.Permission; import org.eclipse.tractusx.irs.edc.client.policy.Policy; -import org.eclipse.tractusx.irs.policystore.common.CommonConstants; import org.eclipse.tractusx.irs.policystore.models.PolicyWithBpn; import org.eclipse.tractusx.irs.policystore.models.SearchCriteria; import org.springframework.data.domain.Page; @@ -120,15 +124,15 @@ private static class PolicyComparatorBuilder { private Comparator getPolicyComparator(final Pageable pageable, final Sort.Order order) { Comparator fieldComparator; final String property = order.getProperty(); - if (CommonConstants.PROPERTY_BPN.equalsIgnoreCase(property)) { + if (PROPERTY_BPN.equalsIgnoreCase(property)) { fieldComparator = Comparator.comparing(PolicyWithBpn::bpn); - } else if (CommonConstants.PROPERTY_VALID_UNTIL.equalsIgnoreCase(property)) { + } else if (PROPERTY_VALID_UNTIL.equalsIgnoreCase(property)) { fieldComparator = Comparator.comparing(p -> p.policy().getValidUntil()); - } else if (CommonConstants.PROPERTY_POLICY_ID.equalsIgnoreCase(property)) { + } else if (PROPERTY_POLICY_ID.equalsIgnoreCase(property)) { fieldComparator = Comparator.comparing(p -> p.policy().getPolicyId()); - } else if (CommonConstants.PROPERTY_CREATED_ON.equalsIgnoreCase(property)) { + } else if (PROPERTY_CREATED_ON.equalsIgnoreCase(property)) { fieldComparator = Comparator.comparing(p -> p.policy().getCreatedOn()); - } else if (CommonConstants.PROPERTY_ACTION.equalsIgnoreCase(property)) { + } else if (PROPERTY_ACTION.equalsIgnoreCase(property)) { fieldComparator = Comparator.comparing(p -> { final List permissions = p.policy().getPermissions(); if (permissions == null || permissions.isEmpty()) { @@ -194,21 +198,21 @@ private static class PolicyFilterBuilder { private Predicate getPolicyPredicate(final SearchCriteria searchCriteria) { - if (CommonConstants.PROPERTY_BPN.equalsIgnoreCase(searchCriteria.getProperty())) { + if (PROPERTY_BPN.equalsIgnoreCase(searchCriteria.getProperty())) { return getBpnFilter(searchCriteria); - } else if (CommonConstants.PROPERTY_POLICY_ID.equalsIgnoreCase(searchCriteria.getProperty())) { + } else if (PROPERTY_POLICY_ID.equalsIgnoreCase(searchCriteria.getProperty())) { return getPolicyIdFilter(searchCriteria); // TODO (mfischer): #750: add test coverage for createdOn, validUntil - } else if (CommonConstants.PROPERTY_ACTION.equalsIgnoreCase(searchCriteria.getProperty())) { + } else if (PROPERTY_ACTION.equalsIgnoreCase(searchCriteria.getProperty())) { return getActionFilter(searchCriteria); - } else if (CommonConstants.PROPERTY_CREATED_ON.equalsIgnoreCase(searchCriteria.getProperty())) { + } else if (PROPERTY_CREATED_ON.equalsIgnoreCase(searchCriteria.getProperty())) { // TODO (mfischer): #750: implement createdOn filter - throw new IllegalArgumentException("Filtering by '%s' has not been implemented yet".formatted( - CommonConstants.PROPERTY_CREATED_ON)); - } else if (CommonConstants.PROPERTY_VALID_UNTIL.equalsIgnoreCase(searchCriteria.getProperty())) { + throw new IllegalArgumentException( + "Filtering by '%s' has not been implemented yet".formatted(PROPERTY_CREATED_ON)); + } else if (PROPERTY_VALID_UNTIL.equalsIgnoreCase(searchCriteria.getProperty())) { // TODO (mfischer): #750: implement validUntil filter - throw new IllegalArgumentException("Filtering by '%s' has not been implemented yet".formatted( - CommonConstants.PROPERTY_VALID_UNTIL)); + throw new IllegalArgumentException( + "Filtering by '%s' has not been implemented yet".formatted(PROPERTY_VALID_UNTIL)); } else { throw new IllegalArgumentException("Not supported"); }