From cd17779350f2edaf07d899810f2ff7ca0189a401 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Tue, 14 May 2024 05:27:03 -0700 Subject: [PATCH] refactor(EdcRequestBodyBuilder): make PolicyConstraintDto a private record --- .../edc/logic/dto/PolicyConstraintDto.java | 34 ------------------- .../edc/logic/util/EdcRequestBodyBuilder.java | 29 +++++++++------- 2 files changed, 17 insertions(+), 46 deletions(-) delete mode 100644 backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/dto/PolicyConstraintDto.java diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/dto/PolicyConstraintDto.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/dto/PolicyConstraintDto.java deleted file mode 100644 index 8b7b8d53..00000000 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/dto/PolicyConstraintDto.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2024 Volkswagen AG - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.eclipse.tractusx.puris.backend.common.edc.logic.dto; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@AllArgsConstructor -@Getter -public class PolicyConstraintDto { - - private String leftOperand; - private String operator; - private String rightOperand; - -} diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java index 1a6476e4..59f8f7ca 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java @@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.puris.backend.common.edc.logic.dto.PolicyConstraintDto; import org.eclipse.tractusx.puris.backend.common.util.VariablesService; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; import org.springframework.beans.factory.annotation.Autowired; @@ -58,6 +57,12 @@ public class EdcRequestBodyBuilder { public static final String AAS_SEMANTICS_NAMESPACE = "https://admin-shell.io/aas/3/0/HasSemantics/"; public static final String CONTRACT_POLICY_ID = "Contract_Policy"; + /** + * helper class to encapsulate PolicyConstraint + **/ + private record PolicyConstraint(String leftOperand, String operator, String rightOperand) { + } + /** * Creates a request body for requesting a catalog in DSP protocol. * You can add filter criteria. However, at the moment there are issues @@ -100,7 +105,7 @@ public ObjectNode buildBasicCatalogRequestBody(String counterPartyDspUrl, String * @param policyProfile profile to use for odrl:policy, may be null (should only be used for contract policies) * @return body to use for policy request */ - private JsonNode buildPolicy(String policyId, List constraints, String policyProfile) { + private JsonNode buildPolicy(String policyId, List constraints, String policyProfile) { ObjectNode body = getPolicyContextObject(); body.put("@type", "PolicyDefinitionRequestDto"); body.put("@id", policyId); @@ -127,14 +132,14 @@ private JsonNode buildPolicy(String policyId, List constrai var andArray = MAPPER.createArrayNode(); constraintObject.set("and", andArray); - for (PolicyConstraintDto policyConstraintDto : constraints) { + for (PolicyConstraint policyConstraint : constraints) { ObjectNode constraint = MAPPER.createObjectNode(); constraint.put("@type", "LogicalConstraint"); - constraint.put("leftOperand", policyConstraintDto.getLeftOperand()); + constraint.put("leftOperand", policyConstraint.leftOperand); - constraint.put("operator", policyConstraintDto.getOperator()); + constraint.put("operator", policyConstraint.operator); - constraint.put("rightOperand", policyConstraintDto.getRightOperand()); + constraint.put("rightOperand", policyConstraint.rightOperand); andArray.add(constraint); } @@ -151,15 +156,15 @@ private JsonNode buildPolicy(String policyId, List constrai */ public JsonNode buildBpnAndMembershipRestrictedPolicy(Partner partner) { - List constraints = new ArrayList<>(); + List constraints = new ArrayList<>(); - constraints.add(new PolicyConstraintDto( + constraints.add(new PolicyConstraint( "BusinessPartnerNumber", "eq", partner.getBpnl() )); - constraints.add(new PolicyConstraintDto( + constraints.add(new PolicyConstraint( "Membership", "eq", "active" @@ -183,15 +188,15 @@ public JsonNode buildBpnAndMembershipRestrictedPolicy(Partner partner) { */ public JsonNode buildFrameworkPolicy() { - List constraints = new ArrayList<>(); + List constraints = new ArrayList<>(); - constraints.add(new PolicyConstraintDto( + constraints.add(new PolicyConstraint( CX_POLICY_NAMESPACE + "FrameworkAgreement", "eq", variablesService.getPurisFrameworkAgreementWithVersion() )); - constraints.add(new PolicyConstraintDto( + constraints.add(new PolicyConstraint( CX_POLICY_NAMESPACE + "UsagePurpose", "eq", variablesService.getPurisPuposeWithVersion()