Skip to content

Commit

Permalink
chore: enhance code
Browse files Browse the repository at this point in the history
  • Loading branch information
efiege committed Jun 11, 2024
1 parent ed762fc commit 7c38a58
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.sovity.edc.ext.wrapper.api.common.model.PolicyElement;
import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest;
import de.sovity.edc.utils.JsonUtils;
import de.sovity.edc.utils.jsonld.vocab.Prop;
import jakarta.json.JsonObject;
import lombok.RequiredArgsConstructor;
import org.eclipse.edc.policy.model.Action;
Expand Down Expand Up @@ -78,11 +79,9 @@ public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) {
.build();
}

public Policy buildGenericPolicy(List<PolicyElement> constraintElements) {
public Policy buildMultiplicityPolicy(List<PolicyElement> constraintElements) {
var constraints = buildConstraints(constraintElements);

var action = Action.Builder.newInstance().type(PolicyValidator.ALLOWED_ACTION).build();

var action = Action.Builder.newInstance().type(Prop.Odrl.USE).build();
var permission = Permission.Builder.newInstance()
.action(action)
.constraints(constraints)
Expand All @@ -101,11 +100,11 @@ private List<Constraint> buildConstraints(List<PolicyElement> constraintElements
.toList();
}

private Constraint buildConstraint(PolicyElement uiPolicyConstraintElement) {
var constraintElements = uiPolicyConstraintElement.getConstraintElements();
return switch (uiPolicyConstraintElement.getConstraintType()) {
private Constraint buildConstraint(PolicyElement policyElement) {
var constraintElements = policyElement.getConstraintElements();
return switch (policyElement.getConstraintType()) {
case ATOMIC ->
atomicConstraintMapper.buildAtomicConstraint(uiPolicyConstraintElement.getAtomicConstraint());
atomicConstraintMapper.buildAtomicConstraint(policyElement.getAtomicConstraint());
case AND -> AndConstraint.Builder.newInstance()
.constraints(buildConstraints(constraintElements))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void buildGenericPolicy(String constraintTypeString) {
when(atomicConstraintMapper
.buildAtomicConstraint(eq(incomingConstraint)))
.thenReturn(mockAtomicConstraint);
var policy = policyMapper.buildGenericPolicy(List.of(baseConstraintElement));
var policy = policyMapper.buildMultiplicityPolicy(List.of(baseConstraintElement));

// assert
assertThat(policy.getType()).isEqualTo(PolicyType.SET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public IdResponseDto createGenericPolicyDefinition(GenericPolicyCreateRequest ge
}

private PolicyDefinition buildPolicyDefinition(GenericPolicyCreateRequest genericPolicyCreateRequest) {
var policy = policyMapper.buildGenericPolicy(genericPolicyCreateRequest.getConstraintElements());
var policy = policyMapper.buildMultiplicityPolicy(genericPolicyCreateRequest.getConstraintElements());
return PolicyDefinition.Builder.newInstance()
.id(genericPolicyCreateRequest.getPolicyDefinitionId())
.policy(policy)
Expand Down

0 comments on commit 7c38a58

Please sign in to comment.