Skip to content

Commit

Permalink
feat(policy-api):[#639] cleanup using static imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed Jul 4, 2024
1 parent 521055b commit 5ad5fd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,11 +40,9 @@
@Getter
public class SearchParameterParser {

public static final List<String> 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<String> DATE_PROPERTIES = List.of(CommonConstants.PROPERTY_VALID_UNTIL,
CommonConstants.PROPERTY_CREATED_ON);
public static final List<String> SUPPORTED_PROPERTIES = List.of(PROPERTY_BPN, PROPERTY_VALID_UNTIL,
PROPERTY_POLICY_ID, PROPERTY_CREATED_ON, PROPERTY_ACTION);
public static final List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -215,8 +215,7 @@ public Map<String, List<PolicyResponse>> getPolicies(//
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')")
public Page<PolicyResponse> 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 //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -120,15 +124,15 @@ private static class PolicyComparatorBuilder {
private Comparator<PolicyWithBpn> getPolicyComparator(final Pageable pageable, final Sort.Order order) {
Comparator<PolicyWithBpn> 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<Permission> permissions = p.policy().getPermissions();
if (permissions == null || permissions.isEmpty()) {
Expand Down Expand Up @@ -194,21 +198,21 @@ private static class PolicyFilterBuilder {

private Predicate<PolicyWithBpn> 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");
}
Expand Down

0 comments on commit 5ad5fd6

Please sign in to comment.