From 70d1a20a2c87f926cfefc20c07c44bcc8a95c18b Mon Sep 17 00:00:00 2001
From: Fotis Soldatos <fsoldatos@ubitech.eu>
Date: Tue, 12 Jul 2022 00:13:09 +0300
Subject: [PATCH] feat(policy): add new policy related domain models

---
 .../policy/model/BooleanOperator.java         | 16 ++++
 .../policy/model/NumericalOperator.java       | 16 ++++
 .../policy/model/PolicyRuleActionEnum.java    | 16 ++++
 .../policy/model/PolicyRuleBasic.java         | 82 +++++++++++++++++++
 .../policy/model/PolicyRuleDevice.java        | 45 ++++++++++
 .../policy/model/PolicyRuleService.java       | 54 ++++++++++++
 6 files changed, 229 insertions(+)
 create mode 100644 src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java
 create mode 100644 src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleDevice.java
 create mode 100644 src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleService.java

diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/BooleanOperator.java b/src/policy/src/main/java/eu/teraflow/policy/model/BooleanOperator.java
index 4de1743d0..7231c02e5 100644
--- a/src/policy/src/main/java/eu/teraflow/policy/model/BooleanOperator.java
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/BooleanOperator.java
@@ -1,3 +1,19 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
 package eu.teraflow.policy.model;
 
 public enum BooleanOperator {
diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/NumericalOperator.java b/src/policy/src/main/java/eu/teraflow/policy/model/NumericalOperator.java
index ccd424a02..48029e550 100644
--- a/src/policy/src/main/java/eu/teraflow/policy/model/NumericalOperator.java
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/NumericalOperator.java
@@ -1,3 +1,19 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
 package eu.teraflow.policy.model;
 
 public enum NumericalOperator {
diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleActionEnum.java b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleActionEnum.java
index 317daa029..7d9354a05 100644
--- a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleActionEnum.java
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleActionEnum.java
@@ -1,3 +1,19 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
 package eu.teraflow.policy.model;
 
 public enum PolicyRuleActionEnum {
diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java
new file mode 100644
index 000000000..898b3a48c
--- /dev/null
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleBasic.java
@@ -0,0 +1,82 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
+package eu.teraflow.policy.model;
+
+import eu.teraflow.policy.common.Util;
+import java.util.List;
+
+public class PolicyRuleBasic {
+
+    private final String policyRuleId;
+    private final PolicyRuleState policyRuleState;
+    private final int priority;
+    private final List<PolicyRuleCondition> policyRuleConditions;
+    private final BooleanOperator booleanOperator;
+    private final List<PolicyRuleAction> policyRuleActions;
+
+    public PolicyRuleBasic(
+            String policyRuleId,
+            PolicyRuleState policyRuleState,
+            int priority,
+            List<PolicyRuleCondition> policyRuleConditions,
+            BooleanOperator booleanOperator,
+            List<PolicyRuleAction> policyRuleActions) {
+        this.policyRuleId = policyRuleId;
+        this.policyRuleState = policyRuleState;
+        this.priority = priority;
+        this.policyRuleConditions = policyRuleConditions;
+        this.booleanOperator = booleanOperator;
+        this.policyRuleActions = policyRuleActions;
+    }
+
+    public String getPolicyRuleId() {
+        return policyRuleId;
+    }
+
+    public PolicyRuleState getPolicyRuleState() {
+        return policyRuleState;
+    }
+
+    public int getPriority() {
+        return priority;
+    }
+
+    public List<PolicyRuleCondition> getPolicyRuleConditions() {
+        return policyRuleConditions;
+    }
+
+    public BooleanOperator getBooleanOperator() {
+        return booleanOperator;
+    }
+
+    public List<PolicyRuleAction> getPolicyRuleActions() {
+        return policyRuleActions;
+    }
+
+    @Override
+    public String toString() {
+        return String.format(
+                "%s:{policyRuleId:\"%s\", %s, priority:%d, [%s], booleanOperator:\"%s\", [%s]}",
+                getClass().getSimpleName(),
+                policyRuleId,
+                policyRuleState,
+                priority,
+                Util.toString(policyRuleConditions),
+                booleanOperator.toString(),
+                Util.toString(policyRuleActions));
+    }
+}
diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleDevice.java b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleDevice.java
new file mode 100644
index 000000000..46151ea5c
--- /dev/null
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleDevice.java
@@ -0,0 +1,45 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
+package eu.teraflow.policy.model;
+
+import eu.teraflow.policy.common.Util;
+import java.util.List;
+
+public class PolicyRuleDevice {
+
+    private final PolicyRuleBasic policyRuleBasic;
+    private final List<String> deviceIds;
+
+    public PolicyRuleDevice(PolicyRuleBasic policyRuleBasic, List<String> deviceIds) {
+        this.policyRuleBasic = policyRuleBasic;
+        this.deviceIds = deviceIds;
+    }
+
+    public PolicyRuleBasic getPolicyRuleBasic() {
+        return policyRuleBasic;
+    }
+
+    public List<String> getDeviceIds() {
+        return deviceIds;
+    }
+
+    @Override
+    public String toString() {
+        return String.format(
+                "%s:{%s, [%s]}", getClass().getSimpleName(), policyRuleBasic, Util.toString(deviceIds));
+    }
+}
diff --git a/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleService.java b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleService.java
new file mode 100644
index 000000000..ac0710d85
--- /dev/null
+++ b/src/policy/src/main/java/eu/teraflow/policy/model/PolicyRuleService.java
@@ -0,0 +1,54 @@
+/*
+* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://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.
+*/
+
+package eu.teraflow.policy.model;
+
+import eu.teraflow.policy.common.Util;
+import eu.teraflow.policy.context.model.ServiceId;
+import java.util.List;
+
+public class PolicyRuleService {
+
+    private final PolicyRuleBasic policyRuleBasic;
+    private final ServiceId serviceId;
+    private final List<String> deviceIds;
+
+    public PolicyRuleService(
+            PolicyRuleBasic policyRuleBasic, ServiceId serviceId, List<String> deviceIds) {
+        this.policyRuleBasic = policyRuleBasic;
+        this.serviceId = serviceId;
+        this.deviceIds = deviceIds;
+    }
+
+    public PolicyRuleBasic getPolicyRuleBasic() {
+        return policyRuleBasic;
+    }
+
+    public ServiceId getServiceId() {
+        return serviceId;
+    }
+
+    public List<String> getDeviceIds() {
+        return deviceIds;
+    }
+
+    @Override
+    public String toString() {
+        return String.format(
+                "%s:{%s, %s, [%s]}",
+                getClass().getSimpleName(), policyRuleBasic, serviceId, Util.toString(deviceIds));
+    }
+}
-- 
GitLab