Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: switch ODRL action USE to use #3927

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ContractExpiryCheckFunctionEvaluationTest {
@BeforeEach
void setup() {
// bind/register rule to evaluate contract expiry
bindingRegistry.bind("USE", TRANSFER_SCOPE);
bindingRegistry.bind("use", TRANSFER_SCOPE);
bindingRegistry.bind(CONTRACT_EXPIRY_EVALUATION_KEY, TRANSFER_SCOPE);
policyEngine = new PolicyEngineImpl(new ScopeFilter(bindingRegistry));
policyEngine.registerFunction(TRANSFER_SCOPE, Permission.class, CONTRACT_EXPIRY_EVALUATION_KEY, function);
Expand Down Expand Up @@ -152,7 +152,7 @@ private Policy createInForcePolicy(Operator operatorStart, Object startDate, Ope
.build())
.build();
var permission = Permission.Builder.newInstance()
.action(Action.Builder.newInstance().type("USE").build())
.action(Action.Builder.newInstance().type("use").build())
.constraint(fixedInForceTimeConstraint).build();

return Policy.Builder.newInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class PolicyEngineImplScenariosTest {
private static final String TEST_SCOPE = "test";
private static final String ABS_SPATIAL_CONSTRAINT = "absoluteSpatialPosition";
private static final String CONNECTOR_CONSTRAINT = "connector";
private static final Action USE_ACTION = Action.Builder.newInstance().type("USE").build();
private static final Action USE_ACTION = Action.Builder.newInstance().type("use").build();

private final RuleBindingRegistry bindingRegistry = new RuleBindingRegistryImpl();
private PolicyEngineImpl policyEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void validateScopeIsInheritedByChildren() {
void validateRuleFunctionOutOfScope() {
bindingRegistry.bind("foo", ALL_SCOPES);

var action = Action.Builder.newInstance().type("USE").build();
var action = Action.Builder.newInstance().type("use").build();

var permission = Permission.Builder.newInstance().action(action).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void verifyDynamicProhibitionFunctionsHierarchy() {

@Test
void verifyPermissionRuleFunctions() {
var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("USE").build()).build();
var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("use").build()).build();
var policy = Policy.Builder.newInstance().permission(permission).build();

var evaluator = PolicyEvaluator.Builder.newInstance().permissionRuleFunction((p) -> true).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void setUp() {

@Test
void transform_policyWithAllRuleTypes_returnJsonObject() {
var action = Action.Builder.newInstance().type("USE").build();
var action = Action.Builder.newInstance().type("use").build();
var permission = Permission.Builder.newInstance().action(action).build();
var prohibition = Prohibition.Builder.newInstance().action(action).build();
var duty = Duty.Builder.newInstance().action(action).build();
Expand Down Expand Up @@ -147,7 +147,7 @@ void transform_policyWithAllRuleTypes_returnJsonObject() {
void transform_actionWithAllAttributes_returnJsonObject() {
var constraint = getConstraint();
var action = Action.Builder.newInstance()
.type("USE")
.type("use")
.includedIn("includedIn")
.constraint(constraint)
.build();
Expand Down Expand Up @@ -357,7 +357,7 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext extensionCo
}

private Action getAction() {
return Action.Builder.newInstance().type("USE").build();
return Action.Builder.newInstance().type("use").build();
}

private AtomicConstraint getConstraint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ void setUp() {

@Test
void transform_onlyActionType_returnAction() {
var action = jsonFactory.createObjectBuilder().add(ODRL_ACTION_TYPE_ATTRIBUTE, "USE").build();
var action = jsonFactory.createObjectBuilder().add(ODRL_ACTION_TYPE_ATTRIBUTE, "use").build();

var result = transformer.transform(getExpanded(action), context);

assertThat(result).isNotNull();
assertThat(result.getType()).isEqualTo("USE");
assertThat(result.getType()).isEqualTo("use");
assertThat(result.getIncludedIn()).isNull();
assertThat(result.getConstraint()).isNull();

Expand All @@ -73,14 +73,14 @@ void transform_onlyActionType_returnAction() {

@Test
void transform_onlyActionAttribute_returnAction() {
var actionContainer = jsonFactory.createObjectBuilder().add(ODRL_ACTION_ATTRIBUTE, "USE").build();
var actionContainer = jsonFactory.createObjectBuilder().add(ODRL_ACTION_ATTRIBUTE, "use").build();
var expanded = getExpanded(actionContainer);
var action = expanded.getJsonArray(ODRL_ACTION_ATTRIBUTE).get(0).asJsonObject();

var result = transformer.transform(action, context);

assertThat(result).isNotNull();
assertThat(result.getType()).isEqualTo("USE");
assertThat(result.getType()).isEqualTo("use");
assertThat(result.getIncludedIn()).isNull();
assertThat(result.getConstraint()).isNull();

Expand Down Expand Up @@ -114,15 +114,15 @@ void transform_allAttributes_returnAction() {
when(context.transform(any(JsonObject.class), eq(Constraint.class))).thenReturn(constraint);

var action = jsonFactory.createObjectBuilder()
.add(ODRL_ACTION_TYPE_ATTRIBUTE, "USE")
.add(ODRL_ACTION_TYPE_ATTRIBUTE, "use")
.add(ODRL_INCLUDED_IN_ATTRIBUTE, "includedIn")
.add(ODRL_REFINEMENT_ATTRIBUTE, jsonFactory.createObjectBuilder().build())
.build();

var result = transformer.transform(getExpanded(action), context);

assertThat(result).isNotNull();
assertThat(result.getType()).isEqualTo("USE");
assertThat(result.getType()).isEqualTo("use");
assertThat(result.getIncludedIn()).isEqualTo("includedIn");
assertThat(result.getConstraint()).isEqualTo(constraint);

Expand Down
1 change: 1 addition & 0 deletions core/control-plane/contract-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
}

dependencies {
api(project(":spi:common:json-ld-spi"))
api(project(":spi:common:policy-engine-spi"))
api(project(":spi:control-plane:contract-spi"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import static org.eclipse.edc.connector.core.entity.AbstractStateEntityManager.DEFAULT_SEND_RETRY_BASE_DELAY;
import static org.eclipse.edc.connector.core.entity.AbstractStateEntityManager.DEFAULT_SEND_RETRY_LIMIT;
import static org.eclipse.edc.connector.core.policy.ContractExpiryCheckFunction.CONTRACT_EXPIRY_EVALUATION_KEY;
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_USE_ACTION_ATTRIBUTE;

@Provides({
ContractValidationService.class, ConsumerContractNegotiationManager.class,
Expand Down Expand Up @@ -180,8 +180,7 @@ private void registerServices(ServiceExtensionContext context) {
context.registerService(ContractValidationService.class, validationService);

// bind/register rule to evaluate contract expiry
ruleBindingRegistry.bind("USE", TRANSFER_SCOPE);
ruleBindingRegistry.bind(ODRL_SCHEMA + "use", TRANSFER_SCOPE);
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, TRANSFER_SCOPE);
ruleBindingRegistry.bind(CONTRACT_EXPIRY_EVALUATION_KEY, TRANSFER_SCOPE);
var function = new ContractExpiryCheckFunction();
policyEngine.registerFunction(TRANSFER_SCOPE, Permission.class, CONTRACT_EXPIRY_EVALUATION_KEY, function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private ContractOffer getContractOffer() {
.assigner("assigner")
.assignee("assignee")
.duty(Duty.Builder.newInstance()
.action(Action.Builder.newInstance().type("USE").build())
.action(Action.Builder.newInstance().type("use").build())
.build())
.build())
.build();
Expand Down
1 change: 1 addition & 0 deletions core/policy-monitor/policy-monitor-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {

dependencies {
api(project(":spi:policy-monitor:policy-monitor-spi"))
api(project(":spi:common:json-ld-spi"))
api(project(":spi:control-plane:control-plane-spi"))
api(project(":spi:control-plane:policy-spi"))
api(project(":spi:control-plane:transfer-spi"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import static org.eclipse.edc.connector.core.entity.AbstractStateEntityManager.DEFAULT_ITERATION_WAIT;
import static org.eclipse.edc.connector.core.policy.ContractExpiryCheckFunction.CONTRACT_EXPIRY_EVALUATION_KEY;
import static org.eclipse.edc.connector.policy.monitor.PolicyMonitorExtension.NAME;
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_USE_ACTION_ATTRIBUTE;

@Extension(value = NAME)
@Provides({ PolicyMonitorManager.class })
Expand Down Expand Up @@ -94,7 +94,7 @@ public void initialize(ServiceExtensionContext context) {
var iterationWaitMillis = context.getSetting(POLICY_MONITOR_ITERATION_WAIT_MILLIS, DEFAULT_ITERATION_WAIT);
var waitStrategy = new ExponentialWaitStrategy(iterationWaitMillis);

ruleBindingRegistry.bind(ODRL_SCHEMA + "use", POLICY_MONITOR_SCOPE);
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, POLICY_MONITOR_SCOPE);
ruleBindingRegistry.bind(CONTRACT_EXPIRY_EVALUATION_KEY, POLICY_MONITOR_SCOPE);
policyEngine.registerFunction(POLICY_MONITOR_SCOPE, Permission.class, CONTRACT_EXPIRY_EVALUATION_KEY, new ContractExpiryCheckFunction());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private ContractAgreement contractAgreement() {
}

private Policy policy() {
var action = Action.Builder.newInstance().type("USE").build();
var action = Action.Builder.newInstance().type("use").build();
var permission = Permission.Builder.newInstance().action(action).build();
var prohibition = Prohibition.Builder.newInstance().action(action).build();
var duty = Duty.Builder.newInstance().action(action).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private JsonObject contractAgreement() {
}

private Policy policy() {
var action = Action.Builder.newInstance().type("USE").build();
var action = Action.Builder.newInstance().type("use").build();
var permission = Permission.Builder.newInstance().action(action).build();
var prohibition = Prohibition.Builder.newInstance().action(action).build();
var duty = Duty.Builder.newInstance().action(action).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private JsonObject contractOffer() {
}

private Policy policy() {
var action = Action.Builder.newInstance().type("USE").build();
var action = Action.Builder.newInstance().type("use").build();
var permission = Permission.Builder.newInstance().action(action).build();
var prohibition = Prohibition.Builder.newInstance().action(action).build();
var duty = Duty.Builder.newInstance().action(action).build();
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/policy-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ As an example, we create the module `:extensions:policy:ids-policy`.
### Step 2: Implement a `ServiceExtension`

The new policy extension will provide a service extension class and two constraint functions. In
`IdsPolicyExtension`, first, the scope `ALL_SCOPES` is bound to the rule type `USE`. Next, both policy
`IdsPolicyExtension`, first, the scope `ALL_SCOPES` is bound to the rule type `use`. Next, both policy
functions are registered to the policy engine.

```java
Expand All @@ -59,7 +59,7 @@ public class IdsPolicyExtension implements ServiceExtension {

@Override
public void initialize(ServiceExtensionContext context) {
ruleBindingRegistry.bind(USE, ALL_SCOPES);
ruleBindingRegistry.bind("use", ALL_SCOPES);

policyEngine.registerFunction(ALL_SCOPES, Permission.class, ABS_SPATIAL_POSITION, new AbsSpatialPositionConstraintFunction());
policyEngine.registerFunction(ALL_SCOPES, Permission.class, PARTNER_LEVEL, new PartnerLevelConstraintFunction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public interface PropertyAndTypeNames {
String ODRL_AND_CONSTRAINT_ATTRIBUTE = ODRL_SCHEMA + "and";
String ODRL_OR_CONSTRAINT_ATTRIBUTE = ODRL_SCHEMA + "or";
String ODRL_XONE_CONSTRAINT_ATTRIBUTE = ODRL_SCHEMA + "xone";
String ODRL_USE_ACTION_ATTRIBUTE = ODRL_SCHEMA + "use";

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DutyTest {
@Test
void serializeDeserialize() throws JsonProcessingException {
var mapper = new ObjectMapper();
var serialized = mapper.writeValueAsString(Duty.Builder.newInstance().action(Action.Builder.newInstance().type("USE").build()).build());
var serialized = mapper.writeValueAsString(Duty.Builder.newInstance().action(Action.Builder.newInstance().type("use").build()).build());
assertThat(mapper.readValue(serialized, Duty.class).getAction()).isNotNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PermissionTest {
@Test
void serializeDeserialize() throws JsonProcessingException {
var mapper = new ObjectMapper();
var serialized = mapper.writeValueAsString(Permission.Builder.newInstance().action(Action.Builder.newInstance().type("USE").build()).build());
var serialized = mapper.writeValueAsString(Permission.Builder.newInstance().action(Action.Builder.newInstance().type("use").build()).build());
assertThat(mapper.readValue(serialized, Permission.class).getAction()).isNotNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PolicyTest {
void serializeDeserialize() throws JsonProcessingException {
var mapper = new ObjectMapper();

var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("USE").build()).build();
var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("use").build()).build();
var policy = Policy.Builder.newInstance().permission(permission).build();

var serialized = mapper.writeValueAsString(policy);
Expand All @@ -39,7 +39,7 @@ void serializeDeserialize() throws JsonProcessingException {
@Test
void withTarget() {
var target = "target-id";
var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("USE").build()).build();
var permission = Permission.Builder.newInstance().action(Action.Builder.newInstance().type("use").build()).build();
var prohibition = Prohibition.Builder.newInstance().action(Action.Builder.newInstance().type("MODIFY").build()).build();
var duty = Duty.Builder.newInstance().action(Action.Builder.newInstance().type("DELETE").build()).build();
var policy = Policy.Builder.newInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void byPolicyAssignee() {
.assigner("test-assigner")
.permission(Permission.Builder.newInstance()
.action(Action.Builder.newInstance()
.type("USE")
.type("use")
.build())
.constraint(AtomicConstraint.Builder.newInstance()
.leftExpression(new LiteralExpression("foo"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static Policy createPolicy() {
return Policy.Builder.newInstance()
.permission(Permission.Builder.newInstance()
.action(Action.Builder.newInstance()
.type("USE")
.type("use")
.build())
.constraint(AtomicConstraint.Builder.newInstance()
.leftExpression(new LiteralExpression("foo"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void whenPolicyExists_updatingPolicyFields() {
var store = getPolicyDefinitionStore();
store.create(policy);

var action = Action.Builder.newInstance().type("UPDATED_USE").build();
var action = Action.Builder.newInstance().type("play").build();
var updatedPermission = Permission.Builder.newInstance().action(action).build();
var updatedDuty = Duty.Builder.newInstance().action(action).build();
var updatedProhibition = Prohibition.Builder.newInstance().action(action).build();
Expand Down
Loading