Skip to content

Commit

Permalink
pr remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Aug 3, 2023
1 parent b8af255 commit 6d8a223
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
* <li>{@link org.eclipse.edc.connector.contract.spi.validation.ContractValidationService#NEGOTIATION_SCOPE}</li>
* <li>{@link org.eclipse.edc.connector.contract.spi.validation.ContractValidationService#TRANSFER_SCOPE}</li>
* </ul>
* The rule to which the function is bound is {@link BusinessPartnerEvaluationExtension#BUSINESS_PARTNER_CONSTRAINT_KEY}. That means, that policies that are bound to these scopes look
* The rule to which the function is bound is {@link BusinessPartnerGroupFunction#BUSINESS_PARTNER_CONSTRAINT_KEY}. That means, that policies that are bound to these scopes look
* like this:
* <pre>
* {
* "constraint": {
* "leftOperand": "BusinessPartnerGroup",
* "leftOperand": "https://w3id.org/tractusx/v0.0.1/ns/BusinessPartnerGroup",
* "operator": "isAnyOf",
* "rightOperand": ["gold_customer","platin_partner"]
* }
Expand All @@ -52,7 +52,6 @@
@Extension(value = "Registers a function to evaluate whether a BPN number is covered by a certain policy or not", categories = {"policy", "contract"})
public class BusinessPartnerEvaluationExtension implements ServiceExtension {

public static final String BUSINESS_PARTNER_CONSTRAINT_KEY = "BusinessPartnerGroup";
private static final String USE = "USE";
@Inject
private RuleBindingRegistry ruleBindingRegistry;
Expand All @@ -72,8 +71,8 @@ public void initialize(ServiceExtensionContext context) {

private void bindToScope(BusinessPartnerGroupFunction function, String scope) {
ruleBindingRegistry.bind(USE, scope);
ruleBindingRegistry.bind(BUSINESS_PARTNER_CONSTRAINT_KEY, scope);
ruleBindingRegistry.bind(BusinessPartnerGroupFunction.BUSINESS_PARTNER_CONSTRAINT_KEY, scope);

policyEngine.registerFunction(scope, Permission.class, BUSINESS_PARTNER_CONSTRAINT_KEY, function);
policyEngine.registerFunction(scope, Permission.class, BusinessPartnerGroupFunction.BUSINESS_PARTNER_CONSTRAINT_KEY, function);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.eclipse.edc.policy.model.Operator.IS_ANY_OF;
import static org.eclipse.edc.policy.model.Operator.IS_NONE_OF;
import static org.eclipse.edc.policy.model.Operator.NEQ;
import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_NAMESPACE;

/**
* This function evaluates, that a particular {@link ParticipantAgent} is a member of a particular group.
Expand All @@ -46,7 +47,7 @@
* <pre>
* {
* "constraint": {
* "leftOperand": "BusinessPartnerGroup",
* "leftOperand": "https://w3id.org/tractusx/v0.0.1/ns/BusinessPartnerGroup",
* "operator": "isAnyOf",
* "rightOperand": ["gold_customer","platin_partner"]
* }
Expand All @@ -70,6 +71,7 @@
*/
public class BusinessPartnerGroupFunction implements AtomicConstraintFunction<Permission> {
public static final String REFERRING_CONNECTOR_CLAIM = "referringConnector";
public static final String BUSINESS_PARTNER_CONSTRAINT_KEY = TX_NAMESPACE + "BusinessPartnerGroup";
private static final List<Operator> ALLOWED_OPERATORS = List.of(EQ, NEQ, IN, IS_ALL_OF, IS_ANY_OF, IS_NONE_OF);
private static final Map<Operator, Function<BpnGroupHolder, Boolean>> OPERATOR_EVALUATOR_MAP = new HashMap<>();
private final BusinessPartnerGroupStore store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static org.eclipse.edc.policy.model.Operator.LEQ;
import static org.eclipse.edc.policy.model.Operator.LT;
import static org.eclipse.edc.policy.model.Operator.NEQ;
import static org.eclipse.tractusx.edc.validation.businesspartner.BusinessPartnerEvaluationExtension.BUSINESS_PARTNER_CONSTRAINT_KEY;
import static org.eclipse.tractusx.edc.validation.businesspartner.functions.BusinessPartnerGroupFunction.BUSINESS_PARTNER_CONSTRAINT_KEY;
import static org.eclipse.tractusx.edc.validation.businesspartner.functions.BusinessPartnerGroupFunction.REFERRING_CONNECTOR_CLAIM;
import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package org.eclipse.tractusx.edc.validation.businesspartner.store.sql;

/**
* Statement templates and SQL table+column names required for the {@link SqlBusinessPartnerGroupStore}
*/
public interface BusinessPartnerGroupStatements {

default String getBpnColumn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import static java.lang.String.format;

/**
* Postgres-specific statement templates for the {@link SqlBusinessPartnerGroupStore}
*/
public class PostgresBusinessPartnerGroupStatements implements BusinessPartnerGroupStatements {
@Override
public String findByBpnTemplate() {
Expand All @@ -44,7 +47,7 @@ public String countQuery() {
public String updateTemplate() {
return format("UPDATE %s SET %s=?%s WHERE %s=?", getTable(), getGroupsColumn(), getFormatJsonOperator(), getBpnColumn());
}

@NotNull
private String getFormatJsonOperator() {
return PostgresDialect.getJsonCastOperator();
Expand Down

0 comments on commit 6d8a223

Please sign in to comment.