|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Apache License, Version 2.0 which is available at |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: Apache-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation |
| 12 | + * |
| 13 | + */ |
| 14 | + |
| 15 | +package org.eclipse.edc.policy.engine.spi; |
| 16 | + |
| 17 | +import org.eclipse.edc.policy.model.Operator; |
| 18 | +import org.eclipse.edc.policy.model.Rule; |
| 19 | +import org.eclipse.edc.spi.result.Result; |
| 20 | + |
| 21 | +/** |
| 22 | + * Invoked during policy evaluation as when the left operand of an atomic constraint evaluates to a key that is not bound to a {@link AtomicConstraintRuleFunction}. |
| 23 | + * The function is responsible for performing policy evaluation on the right operand and the left operand. |
| 24 | + */ |
| 25 | +public interface DynamicAtomicConstraintRuleFunction<R extends Rule, C extends PolicyContext> { |
| 26 | + |
| 27 | + /** |
| 28 | + * Performs the evaluation. |
| 29 | + * |
| 30 | + * @param leftValue the left-side expression for the constraint |
| 31 | + * @param operator the operation |
| 32 | + * @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection. |
| 33 | + * @param rule the rule associated with the constraint |
| 34 | + * @param context the policy context |
| 35 | + */ |
| 36 | + boolean evaluate(Object leftValue, Operator operator, Object rightValue, R rule, C context); |
| 37 | + |
| 38 | + /** |
| 39 | + * Returns true if the function can evaluate the input left operand. |
| 40 | + * |
| 41 | + * @param leftValue the left-side expression for the constraint |
| 42 | + * @return true if the function can evaluate the left operand, false otherwise |
| 43 | + */ |
| 44 | + boolean canHandle(Object leftValue); |
| 45 | + |
| 46 | + /** |
| 47 | + * Performs a validation of an atomic constraint |
| 48 | + * |
| 49 | + * @param leftValue the left-side expression for the constraint |
| 50 | + * @param operator the operation |
| 51 | + * @param rightValue the right-side expression for the constraint; the concrete type may be a string, primitive or object such as a JSON-LD encoded collection |
| 52 | + * @param rule the rule associated with the constraint |
| 53 | + * @return the result of the validation |
| 54 | + */ |
| 55 | + default Result<Void> validate(Object leftValue, Operator operator, Object rightValue, R rule) { |
| 56 | + return Result.success(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns the name of the function |
| 61 | + */ |
| 62 | + default String name() { |
| 63 | + return getClass().getSimpleName(); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments