Merge "Add input tosca examples for guard frequency"
authorPamela Dragosh <pdragosh@research.att.com>
Sun, 24 Mar 2019 12:11:35 +0000 (12:11 +0000)
committerGerrit Code Review <gerrit@onap.org>
Sun, 24 Mar 2019 12:11:35 +0000 (12:11 +0000)
48 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
models-base/src/main/java/org/onap/policy/models/base/keys/PolicyTypeIdent.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java
models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/keys/TestPolicyTypeIdent.java [new file with mode: 0644]
models-decisions/pom.xml
models-pap/pom.xml
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java
models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java [new file with mode: 0644]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java [new file with mode: 0644]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java [new file with mode: 0644]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java [new file with mode: 0644]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java [new file with mode: 0644]
models-pdp/pom.xml [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpHealthCheck.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpResponseDetails.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpHealthStatus.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpMessageType.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpResponseStatus.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpState.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java [new file with mode: 0644]
models-provider/pom.xml
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java [new file with mode: 0644]
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/TestPojos.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyConnection.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java [new file with mode: 0644]
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
models-tosca/pom.xml
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyToscaProvider.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java [new file with mode: 0644]
pom.xml

index a18315c..8e77d3f 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.base;
 
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
 /**
  * Utility class for Policy Framework concept utilities.
  *
@@ -56,4 +61,20 @@ public final class PfUtils {
 
         return 0;
     }
+
+    /**
+     * Convenience method to apply a mapping function to all of the elements of a list,
+     * generating a new list.
+     *
+     * @param source list whose elements are to be mapped, or {@code null}
+     * @param mapFunc mapping function
+     * @return a new list, containing mappings of all of the items in the original list
+     */
+    public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
+        if (source == null) {
+            return null;
+        }
+
+        return source.stream().map(mapFunc).collect(Collectors.toList());
+    }
 }
diff --git a/models-base/src/main/java/org/onap/policy/models/base/keys/PolicyTypeIdent.java b/models-base/src/main/java/org/onap/policy/models/base/keys/PolicyTypeIdent.java
new file mode 100644 (file)
index 0000000..09e0381
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.keys;
+
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Identifies a policy type. Both the name and version must be non-null.
+ */
+@NonNull
+@NoArgsConstructor
+public class PolicyTypeIdent extends PfConceptKey {
+    private static final long serialVersionUID = 1L;
+
+    public PolicyTypeIdent(String name, String version) {
+        super(name, version);
+    }
+
+    public PolicyTypeIdent(PolicyTypeIdent source) {
+        super(source);
+    }
+}
index 2b495a1..bdbab5c 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +23,10 @@ package org.onap.policy.models.base;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 
+import java.util.Arrays;
+import java.util.List;
 import org.junit.Test;
 
 /**
@@ -33,11 +37,23 @@ import org.junit.Test;
 public class PfUtilsTest {
 
     @Test
-    public void testPfUtils() {
+    public void testCompareObjects() {
         assertEquals(0, PfUtils.compareObjects(null, null));
         assertEquals(-1, PfUtils.compareObjects("hello", null));
         assertEquals(1, PfUtils.compareObjects(null, "hello"));
         assertFalse(PfUtils.compareObjects("hello", "goodbye") == 0);
         assertEquals(0, PfUtils.compareObjects("hello", "hello"));
     }
+
+    @Test
+    public void testMapList() {
+        assertNull(PfUtils.mapList(null, item -> {
+            throw new RuntimeException("should not be invoked");
+        }));
+
+        List<String> origList = Arrays.asList("abc", "def");
+        List<String> newList = PfUtils.mapList(origList, text -> text + "X");
+
+        assertEquals(Arrays.asList("abcX", "defX"), newList);
+    }
 }
diff --git a/models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java b/models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java
new file mode 100644 (file)
index 0000000..a1bf3be
--- /dev/null
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.keys;
+
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.validation.ToStringTester;
+
+/**
+ * Class to perform unit testing of models.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestModels {
+
+    @Test
+    public void testModels() {
+        final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
+                .with(new GetterTester()).build();
+        validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
+    }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/keys/TestPolicyTypeIdent.java b/models-base/src/test/java/org/onap/policy/models/base/keys/TestPolicyTypeIdent.java
new file mode 100644 (file)
index 0000000..1638a87
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base.keys;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.models.base.keys.PolicyTypeIdent;
+import org.onap.policy.models.base.keys.TestModels;
+
+/**
+ * Test the other constructors, as {@link TestModels} tests the other methods.
+ */
+public class TestPolicyTypeIdent {
+    private static final String NAME = "my-name";
+    private static final String VERSION = "1.2.3";
+
+    @Test
+    public void testAllArgsConstructor() {
+        assertThatThrownBy(() -> new PolicyTypeIdent(null, VERSION)).isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> new PolicyTypeIdent(NAME, null)).isInstanceOf(NullPointerException.class);
+
+        PolicyTypeIdent orig = new PolicyTypeIdent(NAME, VERSION);
+        assertEquals(NAME, orig.getName());
+        assertEquals(VERSION, orig.getVersion());
+    }
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PolicyTypeIdent(null)).isInstanceOf(NullPointerException.class);
+
+        PolicyTypeIdent orig = new PolicyTypeIdent();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString());
+
+        // verify with all values
+        orig = new PolicyTypeIdent(NAME, VERSION);
+        assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString());
+    }
+}
index 230c5e4..ca7458a 100644 (file)
@@ -27,7 +27,7 @@
         <version>2.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>models-decisions</artifactId>
+    <artifactId>policy-models-decisions</artifactId>
 
     <name>${project.artifactId}</name>
     <description>The models for Policy Decision API's.</description>
index 1cc5603..9257b9b 100644 (file)
@@ -27,7 +27,7 @@
         <version>2.0.0-SNAPSHOT</version>
     </parent>
 
-    <artifactId>models-pap</artifactId>
+    <artifactId>policy-models-pap</artifactId>
 
     <name>${project.artifactId}</name>
     <description>The models for Policy Administration (PAP) REST API's.</description>
             <artifactId>pdp-common</artifactId>
             <version>${policy.common.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.models</groupId>
+            <artifactId>policy-models-base</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+         <dependency>
+             <groupId>org.onap.policy.models</groupId>
+             <artifactId>policy-models-dao</artifactId>
+             <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
-</project>
\ No newline at end of file
+</project>
index 148168d..a42ac21 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.pap.concepts;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-
 import lombok.Getter;
+import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
-
+import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.pdp.common.enums.PdpState;
 
 /**
@@ -41,9 +43,29 @@ public class PdpGroup {
 
     private String name;
     private String version;
-    private PdpState pdpGroupstate;
+    private PdpState pdpGroupState;
     private String description;
     private Map<String, String> properties;
     private List<PdpSubGroup> pdpSubgroups;
 
+    /**
+     * Constructs the object.
+     */
+    public PdpGroup() {
+        super();
+    }
+
+    /**
+     * Constructs the object, making a deep copy from the source.
+     *
+     * @param source source from which to copy fields
+     */
+    public PdpGroup(@NonNull PdpGroup source) {
+        this.name = source.name;
+        this.version = source.version;
+        this.pdpGroupState = source.pdpGroupState;
+        this.description = source.description;
+        this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
+        this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new);
+    }
 }
index 168c20e..4f9041c 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,9 +22,9 @@
 package org.onap.policy.models.pap.concepts;
 
 import lombok.Getter;
+import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
-
 import org.onap.policy.pdp.common.enums.PdpHealthStatus;
 import org.onap.policy.pdp.common.enums.PdpState;
 
@@ -41,4 +42,23 @@ public class PdpInstanceDetails {
     private PdpState pdpState;
     private PdpHealthStatus healthy;
     private String message;
+
+    /**
+     * Constructs the object.
+     */
+    public PdpInstanceDetails() {
+        super();
+    }
+
+    /**
+     * Constructs the object, making a deep copy from the source.
+     *
+     * @param source source from which to copy fields
+     */
+    public PdpInstanceDetails(@NonNull PdpInstanceDetails source) {
+        this.instanceId = source.instanceId;
+        this.pdpState = source.pdpState;
+        this.healthy = source.healthy;
+        this.message = source.message;
+    }
 }
index ebb476d..4335698 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.pap.concepts;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-
 import lombok.Getter;
+import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.keys.PolicyTypeIdent;
 
 /**
- * Class to represent a group of all PDP's of the same pdp type running for a particular domain.
+ * Class to represent a group of all PDP's of the same pdp type running for a particular
+ * domain.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
@@ -38,11 +43,32 @@ import lombok.ToString;
 public class PdpSubGroup {
 
     private String pdpType;
-    private List<String> supportedPolicyTypes;
+    private List<PolicyTypeIdent> supportedPolicyTypes;
     private List<Policy> policies;
     private int currentInstanceCount;
     private int desiredInstanceCount;
     private Map<String, String> properties;
     private List<PdpInstanceDetails> pdpInstances;
 
+    /**
+     * Constructs the object.
+     */
+    public PdpSubGroup() {
+        super();
+    }
+
+    /**
+     * Constructs the object, making a deep copy from the source.
+     *
+     * @param source source from which to copy fields
+     */
+    public PdpSubGroup(@NonNull PdpSubGroup source) {
+        this.pdpType = source.pdpType;
+        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, PolicyTypeIdent::new);
+        this.policies = PfUtils.mapList(source.policies, Policy::new);
+        this.currentInstanceCount = source.currentInstanceCount;
+        this.desiredInstanceCount = source.desiredInstanceCount;
+        this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
+        this.pdpInstances = PfUtils.mapList(source.pdpInstances, PdpInstanceDetails::new);
+    }
 }
index e1281fc..b83510e 100644 (file)
@@ -1,6 +1,7 @@
-/*-
+/*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
 package org.onap.policy.models.pap.concepts;
 
 import lombok.Getter;
+import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
 
@@ -39,4 +41,24 @@ public class Policy {
     private String policyType;
     private String policyTypeVersion;
     private String policyTypeImpl;
+
+    /**
+     * Constructs the object.
+     */
+    public Policy() {
+        super();
+    }
+
+    /**
+     * Constructs the object, making a deep copy from the source.
+     *
+     * @param source source from which to copy fields
+     */
+    public Policy(@NonNull Policy source) {
+        this.name = source.name;
+        this.policyVersion = source.policyVersion;
+        this.policyType = source.policyType;
+        this.policyTypeVersion = source.policyTypeVersion;
+        this.policyTypeImpl = source.policyTypeImpl;
+    }
 }
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java b/models-pap/src/main/java/org/onap/policy/models/pap/provider/PapProvider.java
new file mode 100644 (file)
index 0000000..4b80bea
--- /dev/null
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.provider;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.pap.concepts.PdpGroups;
+
+/**
+ * This class provides the provision of information on PAP concepts in the database to callers.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PapProvider {
+    /**
+     * Get PDP groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroupFilter a filter for the get
+     * @return the PDP groups found
+     * @throws PfModelException on errors getting PDP groups
+     */
+    public PdpGroups getPdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter)
+            throws PfModelException {
+        return new PdpGroups();
+    }
+
+    /**
+     * Creates PDP groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroups a specification of the PDP groups to create
+     * @return the PDP groups created
+     * @throws PfModelException on errors creating PDP groups
+     */
+    public PdpGroups createPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroups pdpGroups)
+            throws PfModelException {
+        return new PdpGroups();
+    }
+
+    /**
+     * Updates PDP groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroups a specification of the PDP groups to update
+     * @return the PDP groups updated
+     * @throws PfModelException on errors updating PDP groups
+     */
+    public PdpGroups updatePdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroups pdpGroups)
+            throws PfModelException {
+        return new PdpGroups();
+    }
+
+    /**
+     * Delete PDP groups.
+     *
+     * @param dao the DAO to use to access the database
+     * @param pdpGroupFilter a filter for the get
+     * @return the PDP groups deleted
+     * @throws PfModelException on errors deleting PDP groups
+     */
+    public PdpGroups deletePdpGroups(@NonNull final PfDao dao, @NonNull final String pdpGroupFilter)
+            throws PfModelException {
+        return new PdpGroups();
+    }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java
new file mode 100644 (file)
index 0000000..3dc3c24
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.pdp.common.enums.PdpState;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpGroup {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class);
+
+        PdpGroup orig = new PdpGroup();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PdpGroup(orig).toString());
+
+        // verify with all values
+        orig.setDescription("my-descript");
+        orig.setName("my-name");
+        orig.setPdpGroupState(PdpState.SAFE);
+
+        PdpSubGroup sub1 = new PdpSubGroup();
+        sub1.setCurrentInstanceCount(10);
+        PdpSubGroup sub2 = new PdpSubGroup();
+        sub2.setCurrentInstanceCount(11);
+        orig.setPdpSubgroups(Arrays.asList(sub1, sub2));
+
+        Map<String, String> props = new TreeMap<>();
+        props.put("key-A", "value-A");
+        props.put("key-B", "value-B");
+        orig.setProperties(props);
+
+        System.out.println("orig=" + orig);
+
+        assertEquals(orig.toString(), new PdpGroup(orig).toString());
+    }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java
new file mode 100644 (file)
index 0000000..9e48480
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.pdp.common.enums.PdpHealthStatus;
+import org.onap.policy.pdp.common.enums.PdpState;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpInstanceDetails {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpInstanceDetails(null)).isInstanceOf(NullPointerException.class);
+
+        PdpInstanceDetails orig = new PdpInstanceDetails();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
+
+        // verify with all values
+        orig.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
+        orig.setInstanceId("my-id");
+        orig.setMessage("my-message");
+        orig.setPdpState(PdpState.SAFE);
+        assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
+    }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java
new file mode 100644 (file)
index 0000000..9af2f4e
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.models.base.keys.PolicyTypeIdent;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpSubGroup {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class);
+
+        PdpSubGroup orig = new PdpSubGroup();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
+
+        // verify with all values
+        orig.setCurrentInstanceCount(10);
+        orig.setDesiredInstanceCount(11);
+
+        PdpInstanceDetails inst1 = new PdpInstanceDetails();
+        inst1.setInstanceId("my-id-A");
+        PdpInstanceDetails inst2 = new PdpInstanceDetails();
+        inst2.setInstanceId("my-id-B");
+        orig.setPdpInstances(Arrays.asList(inst1, inst2));
+
+        orig.setPdpType("my-type");
+
+        Policy pol1 = new Policy();
+        pol1.setName("policy-A");
+        Policy pol2 = new Policy();
+        pol2.setName("policy-B");
+        orig.setPolicies(Arrays.asList(pol1, pol2));
+
+        Map<String, String> props = new TreeMap<>();
+        props.put("key-A", "value-A");
+        props.put("key-B", "value-B");
+        orig.setProperties(props);
+
+        PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2");
+        PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4");
+        orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2));
+
+        assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
+    }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java
new file mode 100644 (file)
index 0000000..6a042d3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPolicy {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new Policy(null)).isInstanceOf(NullPointerException.class);
+
+        Policy orig = new Policy();
+
+        // verify with null values
+        assertEquals(orig.toString(), new Policy(orig).toString());
+
+        // verify with all values
+        orig.setName("my-name");
+        orig.setPolicyType("my-type");
+        orig.setPolicyTypeImpl("my-impl");
+        orig.setPolicyTypeVersion("my-type-vers");
+        assertEquals(orig.toString(), new Policy(orig).toString());
+    }
+}
diff --git a/models-pdp/pom.xml b/models-pdp/pom.xml
new file mode 100644 (file)
index 0000000..1a46856
--- /dev/null
@@ -0,0 +1,48 @@
+<!--
+  ============LICENSE_START=======================================================
+   Copyright (C) 2019 Nordix Foundation.
+   Modifications Copyright (C) 2019 AT&T Intellectual Property.
+  ================================================================================
+  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.
+
+  SPDX-License-Identifier: Apache-2.0
+  ============LICENSE_END=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.onap.policy.models</groupId>
+        <artifactId>policy-models</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>models-pdp</artifactId>
+
+    <name>${project.artifactId}</name>
+    <description>The models for internal PDP API's.</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onap.policy.models</groupId>
+            <artifactId>policy-models-base</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.models</groupId>
+            <artifactId>policy-models-tosca</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpHealthCheck.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpHealthCheck.java
new file mode 100644 (file)
index 0000000..b82af02
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+
+/**
+ * Class to represent the PDP_HEALTH_CHECK message that PAP will send to either PDPGroup/Subgroup or a PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpHealthCheck extends PdpMessage {
+
+    private String name;
+    private String pdpGroup;
+    private String pdpSubgroup;
+
+    /**
+     * Constructor for instantiating PdpHealthCheck class with message name.
+     *
+     */
+    public PdpHealthCheck() {
+        super(PdpMessageType.PDP_HEALTH_CHECK);
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java
new file mode 100644 (file)
index 0000000..6160027
--- /dev/null
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+
+/**
+ * Class to represent the base class for various messages that will ve exchanged between PAP and PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpMessage {
+
+    @Setter(AccessLevel.NONE)
+    private PdpMessageType messageName;
+
+    private String requestId = UUID.randomUUID().toString();
+
+    /**
+     * Time-stamp, in milliseconds, when the message was created. Defaults to the current
+     * time.
+     */
+    private long timestampMs = System.currentTimeMillis();
+
+    /**
+     * Constructor for instantiating PdpMessage class with message name.
+     *
+     * @param messageName the message name
+     */
+    public PdpMessage(final PdpMessageType messageName) {
+        this.messageName = messageName;
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpResponseDetails.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpResponseDetails.java
new file mode 100644 (file)
index 0000000..c28d01a
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpResponseStatus;
+
+/**
+ * Class to represent PDP response details.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpResponseDetails {
+
+    // The responseTo field should match the original request id in the request.
+    private String responseTo;
+    private PdpResponseStatus responseStatus;
+    private String responseMessage;
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java
new file mode 100644 (file)
index 0000000..bca162e
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.pdp.enums.PdpState;
+
+/**
+ * Class to represent the PDP_STATE_CHANGE message that PAP will send to either PDPGroup/Subgroup or a PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpStateChange extends PdpMessage {
+
+    private String name;
+    private PdpState state;
+    private String pdpGroup;
+    private String pdpSubgroup;
+
+    /**
+     * Constructor for instantiating PdpStateChange class with message name.
+     *
+     */
+    public PdpStateChange() {
+        super(PdpMessageType.PDP_STATE_CHANGE);
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
new file mode 100644 (file)
index 0000000..6f9b9c9
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Class to represent statistics of a running PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpStatistics {
+
+    private long policyDownloadCount;
+    private long policyDownloadSuccessCount;
+    private long policyDownloadFailCount;
+    private long policyExecutedCount;
+    private long policyExecutedSuccessCount;
+    private long policyExecutedFailCount;
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java
new file mode 100644 (file)
index 0000000..f7b911f
--- /dev/null
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.base.keys.PolicyTypeIdent;
+import org.onap.policy.models.pdp.enums.PdpHealthStatus;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+
+/**
+ * Class to represent the PDP_STATUS message that all the PDP's will send to PAP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpStatus extends PdpMessage {
+
+    private String name;
+    private String version;
+    private String pdpType;
+    private PdpState state;
+    private PdpHealthStatus healthy;
+    private String description;
+    private String pdpGroup;
+    private String pdpSubgroup;
+    private List<PolicyTypeIdent> supportedPolicyTypes;
+    private List<ToscaPolicy> policies;
+    private String instance;
+    private String deploymentInstanceInfo;
+    private String properties;
+    private PdpStatistics statistics;
+    private PdpResponseDetails response;
+
+    /**
+     * Constructor for instantiating PdpStatus class with message name.
+     *
+     */
+    public PdpStatus() {
+        super(PdpMessageType.PDP_STATUS);
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java
new file mode 100644 (file)
index 0000000..a048cde
--- /dev/null
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import java.util.List;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+
+/**
+ * Class to represent the PDP_UPDATE message that PAP will send to a PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+@Getter
+@Setter
+@ToString
+public class PdpUpdate extends PdpMessage {
+
+    private String name;
+    private String pdpType;
+    private String description;
+    private String pdpGroup;
+    private String pdpSubgroup;
+    private List<ToscaPolicy> policies;
+
+    /**
+     * Constructor for instantiating PdpUpdate class with message name.
+     *
+     */
+    public PdpUpdate() {
+        super(PdpMessageType.PDP_UPDATE);
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpHealthStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpHealthStatus.java
new file mode 100644 (file)
index 0000000..7d31c33
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.enums;
+
+/**
+ * Class to hold the possible values for health status of PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public enum PdpHealthStatus {
+
+    /**
+     * PDP is healthy and working fine.
+     */
+    HEALTHY,
+
+    /**
+     * PDP is not healthy.
+     */
+    NOT_HEALTHY,
+
+    /**
+     * PDP is currently under test state and performing tests.
+     */
+    TEST_IN_PROGRESS,
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpMessageType.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpMessageType.java
new file mode 100644 (file)
index 0000000..7ba4ad7
--- /dev/null
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.enums;
+
+/**
+ * Class to hold the possible values for the type of PDP messages.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public enum PdpMessageType {
+
+    /**
+     * Used by PDPs to report status to PAP.
+     */
+    PDP_STATUS,
+
+    /**
+     * Used by PAP to update the policies running on PDPs, triggers a PDP_STATUS message with the result of the
+     * PDP_UPDATE operation.
+     */
+    PDP_UPDATE,
+
+    /**
+     * Used by PAP to change the state of PDPs, triggers a PDP_STATUS message with the result of the PDP_STATE_CHANGE
+     * operation.
+     */
+    PDP_STATE_CHANGE,
+
+    /**
+     * Used by PAP to order a health check on PDPs, triggers a PDP_STATUS message with the result of the
+     * PDP_HEALTH_CHECK operation.
+     */
+    PDP_HEALTH_CHECK,
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpResponseStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpResponseStatus.java
new file mode 100644 (file)
index 0000000..e6b94f4
--- /dev/null
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.enums;
+
+/**
+ * Class to hold the possible values for PDP response status.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public enum PdpResponseStatus {
+
+    /**
+     * PDP operation was successful.
+     */
+    SUCCESS,
+
+    /**
+     * PDP operation failed.
+     */
+    FAIL,
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpState.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpState.java
new file mode 100644 (file)
index 0000000..a1b96ac
--- /dev/null
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.enums;
+
+/**
+ * Class to hold the possible values for state of PDP.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public enum PdpState {
+
+    /**
+     * Policy execution is always rejected irrespective of PDP type.
+     */
+    PASSIVE,
+
+    /**
+     * Policy execution proceeds, but changes to domain state or context are not carried out. The PDP returns an
+     * indication that it is running in SAFE mode together with the action it would have performed if it was operating
+     * in ACTIVE mode.
+     */
+    SAFE,
+
+    /**
+     * Policy execution proceeds and changes to domain and state are carried out in a test environment. The PDP returns
+     * an indication that it is running in TEST mode together with the action it has performed on the test environment.
+     */
+    TEST,
+
+    /**
+     * Policy execution is executed in the live environment by the PDP.
+     */
+    ACTIVE,
+
+    /**
+     * Policy execution is terminated and not available.
+     */
+    TERMINATED
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
new file mode 100644 (file)
index 0000000..39aee6f
--- /dev/null
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.validation.ToStringTester;
+
+/**
+ * Class to perform unit testing of models.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestModels {
+
+    @Test
+    public void testPapModels() {
+        final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
+                .with(new GetterTester()).build();
+        validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
+    }
+}
index 44756be..b6021b0 100644 (file)
             <version>${project.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.onap.policy.models</groupId>
+            <artifactId>policy-models-pap</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index fa666c0..9bc4983 100644 (file)
@@ -24,6 +24,7 @@ import lombok.NonNull;
 
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PdpGroups;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
@@ -34,7 +35,13 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-public interface PolicyModelsProvider {
+public interface PolicyModelsProvider extends AutoCloseable {
+    /**
+     * Open the policy model provider initializing whatever internal handling it needs.
+     *
+     * @throws PfModelException on errors opening the models provider
+     */
+    public void init() throws PfModelException;
 
     /**
      * Get policy types.
@@ -200,34 +207,36 @@ public interface PolicyModelsProvider {
     /**
      * Get PDP groups.
      *
-     * @param somePdpGroupFilter a filter for the get
+     * @param pdpGroupFilter a filter for the get
      * @return the PDP groups found
      * @throws PfModelException on errors getting PDP groups
      */
-    public Object getPdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException;
+    public PdpGroups getPdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException;
 
     /**
      * Creates PDP groups.
      *
-     * @param somePdpGroupSpecification a specification for the PDP group
+     * @param pdpGroups a specification of the PDP groups to create
+     * @return the PDP groups created
      * @throws PfModelException on errors creating PDP groups
      */
-    public Object createPdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException;
-
+    public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
 
     /**
      * Updates PDP groups.
      *
-     * @param somePdpGroupSpecification a specification for the PDP group
+     * @param pdpGroups a specification of the PDP groups to update
+     * @return the PDP groups updated
      * @throws PfModelException on errors updating PDP groups
      */
-    public Object updatePdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException;
+    public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException;
 
     /**
      * Delete PDP groups.
      *
-     * @param somePdpGroupFilter a filter for the get
+     * @param pdpGroupFilter a filter for the get
+     * @return the PDP groups deleted
      * @throws PfModelException on errors deleting PDP groups
      */
-    public Object deletePdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException;
+    public PdpGroups deletePdpGroups(@NonNull final String pdpGroupFilter) throws PfModelException;
 }
index b4b5f1d..718668b 100644 (file)
 
 package org.onap.policy.models.provider;
 
-import org.onap.policy.models.provider.impl.DummyPolicyModelsProviderImpl;
+import javax.ws.rs.core.Response;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A factory for creating PolicyModelsProvider objects using the default Policy Framework implementation.
@@ -28,11 +35,44 @@ import org.onap.policy.models.provider.impl.DummyPolicyModelsProviderImpl;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class PolicyModelsProviderFactory {
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
 
     /**
      * Creates a new PolicyModelsProvider object from its implementation.
+     *
+     * @param parameters The parameters for the implementation of the PolicyModelProvider
+     * @throws PfModelException on errors creating an implementation of the PolicyModelProvider
      */
-    public  PolicyModelsProvider createPolicyModelsProvider() {
-        return new DummyPolicyModelsProviderImpl();
+    public PolicyModelsProvider createPolicyModelsProvider(@NonNull final PolicyModelsProviderParameters parameters)
+            throws PfModelException {
+        // Get the class for the PolicyModelsProvider
+        Class<?> implementationClass = null;
+        try {
+            // Check if the implementation class is on the classpath
+            implementationClass = Class.forName(parameters.getImplementation());
+        } catch (final Exception exc) {
+            String errorMessage = "could not find implementation of the \"PolicyModelsProvider\" interface \""
+                    + parameters.getImplementation() + "\"";
+            LOGGER.warn(errorMessage, exc);
+            throw new PfModelException(Response.Status.NOT_FOUND, errorMessage, exc);
+        }
+
+        // It is, now check if it is a PolicyModelsProvider
+        if (!PolicyModelsProvider.class.isAssignableFrom(implementationClass)) {
+            String errorMessage = "the class \"" + implementationClass.getCanonicalName()
+                    + "\" is not an implementation of the \"PolicyModelsProvider\" interface";
+            LOGGER.warn(errorMessage);
+            throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage);
+        }
+
+        try {
+            return (PolicyModelsProvider) implementationClass.getConstructor(PolicyModelsProviderParameters.class)
+                    .newInstance(parameters);
+        } catch (Exception exc) {
+            String errorMessage =
+                    "could not create an instance of PolicyModelsProvider \"" + parameters.getImplementation() + "\"";
+            LOGGER.warn(errorMessage, exc);
+            throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc);
+        }
     }
 }
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
new file mode 100644 (file)
index 0000000..5abafed
--- /dev/null
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider;
+
+import lombok.Data;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
+
+// @formatter:off
+/**
+ * Class to hold all the plugin handler parameters.
+ *
+ * <p>The following parameters are defined:
+ * <ol>
+ * <li>name: A name for the parameters.
+ * <li>implementation: The implementation of the PolicyModelsProvider to use for writing and reading concepts,
+ * defaults to {@link DatabasePolicyModelsProviderImpl} and may not be null
+ * <li>databaseUrl: The JDBC URL for the database, mandatory.
+ * <li>databaseUser: The user id to use for connecting to the database, optional, defaults to null.
+ * <li>databasePassword: The password to use for connecting to the database encoded in Base64, optional,
+ * defaults to null.
+ * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
+ * to the database, mandatory.
+ * </ol>
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+//@formatter:on
+
+@Data
+public class PolicyModelsProviderParameters implements ParameterGroup {
+    private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getCanonicalName();
+
+    private String name;
+    private String implementation = DEFAULT_IMPLEMENTATION;
+    private String databaseUrl;
+    private String databaseUser;
+    private String databasePassword;
+    private String persistenceUnit;
+
+    /**
+     * Validate the model provider parameters.
+     *
+     */
+    @Override
+    public GroupValidationResult validate() {
+        final GroupValidationResult validationResult = new GroupValidationResult(this);
+
+        if (!ParameterValidationUtils.validateStringParameter(implementation)) {
+            validationResult.setResult("implementation", ValidationStatus.INVALID,
+                    "a PolicyModelsProvider implementation must be specified");
+        }
+
+        if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
+            validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
+                    "a URL must be specified for the JDBC connection to the database");
+        }
+
+        if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
+            validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
+                    "a persistence unit must be specified for connecting to the database");
+        }
+
+        return validationResult;
+    }
+}
index 8136a75..970aa8f 100644 (file)
 
 package org.onap.policy.models.provider.impl;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Base64;
+
+import javax.ws.rs.core.Response;
+
 import lombok.NonNull;
 
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.dao.DaoParameters;
+import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.dao.PfDaoFactory;
+import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.pap.provider.PapProvider;
 import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.legacy.provider.LegacyToscaProvider;
 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework
- * that works towards a relational database.
+ * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework that works towards
+ * a relational database.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
+
+    private final PolicyModelsProviderParameters parameters;
+
+    // Database connection and the DAO for reading and writing Policy Framework concepts
+    private Connection connection;
+    private PfDao pfDao;
+
+    /**
+     * Constructor that takes the parameters.
+     *
+     * @param parameters the parameters for the provider
+     */
+    public DatabasePolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {
+        this.parameters = parameters;
+    }
+
+    @Override
+    public void init() throws PfModelException {
+        LOGGER.debug("opening the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
+                parameters.getPersistenceUnit());
+
+        // Decode the password using Base64
+        String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
+
+        // Connect to the database, call does not implement AutoCloseable for try-with-resources
+        try {
+            connection = DriverManager.getConnection(parameters.getDatabaseUrl(), parameters.getDatabaseUser(),
+                    decodedPassword);
+        } catch (Exception exc) {
+            String errorMessage = "could not connect to database with URL \"" + parameters.getDatabaseUrl() + "\"";
+            LOGGER.warn(errorMessage, exc);
+            throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc);
+        }
+
+        // Parameters for the DAO
+        final DaoParameters daoParameters = new DaoParameters();
+        daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
+        daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
+
+        try {
+            pfDao = new PfDaoFactory().createPfDao(daoParameters);
+            pfDao.init(daoParameters);
+        } catch (Exception exc) {
+            String errorMessage = "could not create Data Access Object (DAO) using url \"" + parameters.getDatabaseUrl()
+                    + "\" and persistence unit \"" + parameters.getPersistenceUnit() + "\"";
+            LOGGER.warn(errorMessage, exc);
+
+            this.close();
+            throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc);
+        }
+    }
+
+    @Override
+    public void close() throws PfModelException {
+        LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
+                parameters.getPersistenceUnit());
+
+        if (pfDao != null) {
+            pfDao.close();
+            pfDao = null;
+        }
+
+        if (connection != null) {
+            try {
+                connection.close();
+            } catch (Exception exc) {
+
+                String errorMessage =
+                        "could not close connection to database with URL \"" + parameters.getDatabaseUrl() + "\"";
+                LOGGER.warn(errorMessage, exc);
+                throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc);
+            } finally {
+                connection = null;
+            }
+        }
+
+        LOGGER.debug("closed the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
+                parameters.getPersistenceUnit());
+    }
 
     @Override
-    public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().getPolicyTypes(pfDao, policyTypeKey);
     }
 
     @Override
-    public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
-        return null;
+        assertInitilized();
+        return new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
-        return null;
+        assertInitilized();
+        return new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().deletePolicyTypes(pfDao, policyTypeKey);
     }
 
     @Override
-    public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().getPolicies(pfDao, policyKey);
     }
 
     @Override
-    public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().updatePolicies(pfDao, serviceTemplate);
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
+        assertInitilized();
+        return new SimpleToscaProvider().deletePolicies(pfDao, policyKey);
     }
 
     @Override
-    public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException {
-        return null;
+    public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().getOperationalPolicy(pfDao, policyId);
     }
 
     @Override
-    public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
-            throws PfModelException {
-        return null;
+    public LegacyOperationalPolicy createOperationalPolicy(
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().createOperationalPolicy(pfDao, legacyOperationalPolicy);
     }
 
     @Override
-    public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
-            throws PfModelException {
-        return null;
+    public LegacyOperationalPolicy updateOperationalPolicy(
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().updateOperationalPolicy(pfDao, legacyOperationalPolicy);
     }
 
     @Override
-    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException {
-        return null;
+    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().deleteOperationalPolicy(pfDao, policyId);
     }
 
     @Override
-    public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException {
-        return null;
+    public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().getGuardPolicy(pfDao, policyId);
     }
 
     @Override
-    public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
-        return null;
+    public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
+            throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().createGuardPolicy(pfDao, legacyGuardPolicy);
     }
 
     @Override
-    public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
-        return null;
+    public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
+            throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().updateGuardPolicy(pfDao, legacyGuardPolicy);
     }
 
     @Override
-    public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException {
-        return null;
+    public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException {
+        assertInitilized();
+        return new LegacyToscaProvider().deleteGuardPolicy(pfDao, policyId);
     }
 
     @Override
-    public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
-        return null;
+    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        assertInitilized();
+        return new PapProvider().getPdpGroups(pfDao, pdpGroupFilter);
     }
 
     @Override
-    public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
-        return null;
+    public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        assertInitilized();
+        return new PapProvider().createPdpGroups(pfDao, pdpGroups);
     }
 
     @Override
-    public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
-        return null;
+    public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        assertInitilized();
+        return new PapProvider().updatePdpGroups(pfDao, pdpGroups);
     }
 
     @Override
-    public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
-        return null;
+    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        assertInitilized();
+        return new PapProvider().deletePdpGroups(pfDao, pdpGroupFilter);
     }
 
+    /**
+     * Check if the model provider is initialized.
+     */
+    private void assertInitilized() {
+        if (pfDao == null) {
+            String errorMessage = "policy models provider is not initilaized";
+            LOGGER.warn(errorMessage);
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+        }
+    }
+
+    /**
+     * Hook for unit test mocking of database connection.
+     *
+     * @param client the mocked client
+     */
+    protected void setConnection(final Connection connection) {
+        this.connection = connection;
+    }
 }
index 3d57c54..d875019 100644 (file)
@@ -30,121 +30,145 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PdpGroups;
 import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
 
 /**
- * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy
- * Framework.
+ * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
+    /**
+     * Constructor that takes the parameters.
+     *
+     * @param parameters the parameters for the provider
+     */
+    public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {
+    }
+
+    @Override
+    public void init() throws PfModelException {
+        // Not required on the dummy provider
+    }
+
+    @Override
+    public void close() {
+        // Not required on the dummy provider
+    }
+
     @Override
-    public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
         return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json");
     }
 
     @Override
-    public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
         return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
     }
 
     @Override
-    public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
         return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json");
     }
 
     @Override
-    public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+    public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
         return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json");
     }
 
     @Override
-    public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException {
+
+    public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
         return new LegacyOperationalPolicy();
     }
 
     @Override
-    public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
-            throws PfModelException {
+    public LegacyOperationalPolicy createOperationalPolicy(
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
         return legacyOperationalPolicy;
     }
 
     @Override
-    public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
-            throws PfModelException {
+    public LegacyOperationalPolicy updateOperationalPolicy(
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
         return legacyOperationalPolicy;
     }
 
     @Override
-    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException {
+    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
         return new LegacyOperationalPolicy();
     }
 
     @Override
-    public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException {
+    public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException {
         return new LegacyGuardPolicy();
     }
 
     @Override
-    public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+    public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
+            throws PfModelException {
         return legacyGuardPolicy;
     }
 
     @Override
-    public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+    public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
+            throws PfModelException {
         return legacyGuardPolicy;
     }
 
     @Override
-    public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException {
+    public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException {
         return new LegacyGuardPolicy();
     }
 
     @Override
-    public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
-        return null;
+    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        return new PdpGroups();
     }
 
     @Override
-    public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
-        return null;
+    public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        return new PdpGroups();
     }
 
     @Override
-    public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
-        return null;
+    public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        return new PdpGroups();
     }
 
     @Override
-    public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
-        return null;
+    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        return new PdpGroups();
     }
 
     /**
@@ -153,7 +177,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
      * @param fileName the file name containing the dummy response
      * @return the ToscaServiceTemplate with the dummy response
      */
-    private ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
+    protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
         Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
         ToscaServiceTemplate serviceTemplate;
 
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
new file mode 100644 (file)
index 0000000..628d9fc
--- /dev/null
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import lombok.ToString;
+
+import org.junit.Test;
+
+/**
+ * Test the {@link PolicyModelsProviderFactory} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@ToString
+public class PolicyModelsProviderFactoryTest {
+
+    @Test
+    public void testFactory() {
+        PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
+
+        try {
+            factory.createPolicyModelsProvider(null);
+            fail("test should throw an exception here");
+        } catch (Exception exc) {
+            assertEquals("parameters is marked @NonNull but is null", exc.getMessage());
+        }
+
+        try {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation(null);
+            factory.createPolicyModelsProvider(pars);
+            fail("test should throw an exception here");
+        } catch (Exception exc) {
+            assertEquals("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"",
+                    exc.getMessage());
+        }
+
+        try {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation("com.acmecorp.RoadRunner");
+            factory.createPolicyModelsProvider(pars);
+            fail("test should throw an exception here");
+        } catch (Exception exc) {
+            assertEquals("could not find implementation of the \"PolicyModelsProvider\" "
+                    + "interface \"com.acmecorp.RoadRunner\"", exc.getMessage());
+        }
+
+        try {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation("java.lang.String");
+            factory.createPolicyModelsProvider(pars);
+            fail("test should throw an exception here");
+        } catch (Exception exc) {
+            assertEquals(
+                    "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface",
+                    exc.getMessage());
+        }
+
+        try {
+            PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+            pars.setImplementation("org.onap.policy.models.provider.impl.DummyBadProviderImpl");
+            factory.createPolicyModelsProvider(pars);
+            fail("test should throw an exception here");
+        } catch (Exception exc) {
+            assertEquals("could not create an instance of PolicyModelsProvider "
+                    + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"", exc.getMessage());
+        }
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java
new file mode 100644 (file)
index 0000000..626d2bf
--- /dev/null
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Test of {@link PolicyModelsProviderParameters} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PolicyModelsProviderParametersTest {
+
+    @Test
+    public void testParameters() {
+        PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+        pars.setDatabaseUrl("jdbc://www.acmecorp/roadrunner");
+        pars.setPersistenceUnit("WileECoyote");
+
+        GroupValidationResult result = pars.validate();
+        assertTrue(result.isValid());
+
+        pars.setImplementation(null);
+        result = pars.validate();
+        assertFalse(result.isValid());
+        pars.setImplementation("An Implementation");
+        result = pars.validate();
+        assertTrue(result.isValid());
+
+        pars.setDatabaseUrl(null);
+        result = pars.validate();
+        assertFalse(result.isValid());
+        pars.setDatabaseUrl("jdbc://www.acmecorp/roadrunner");
+        result = pars.validate();
+        assertTrue(result.isValid());
+
+        pars.setPersistenceUnit(null);
+        result = pars.validate();
+        assertFalse(result.isValid());
+        pars.setPersistenceUnit("WileECoyote");
+        result = pars.validate();
+        assertTrue(result.isValid());
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/TestPojos.java b/models-provider/src/test/java/org/onap/policy/models/provider/TestPojos.java
new file mode 100644 (file)
index 0000000..67b314c
--- /dev/null
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider;
+
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit tests of all pojos.
+ *
+ * @author liam.fallon@est.tech)
+ *
+ */
+public class TestPojos {
+
+    private static final String POJO_PACKAGE = "org.onap.policy.models.provider";
+
+    @Test
+    public void testPojos() {
+        // @formatter:off
+        final Validator validator = ValidatorBuilder
+                .create()
+                .with(new SetterMustExistRule())
+                .with(new GetterMustExistRule())
+                .with(new SetterTester())
+                .with(new GetterTester())
+                .build();
+        validator.validate(POJO_PACKAGE, new FilterPackageInfo());
+        // :formatter:on
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
new file mode 100644 (file)
index 0000000..3b30f98
--- /dev/null
@@ -0,0 +1,298 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Base64;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+
+/**
+ * Test the database models provider implementation.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DatabasePolicyModelsProviderTest {
+    PolicyModelsProviderParameters parameters;
+
+    /**
+     * Initialize parameters.
+     */
+    @Before
+    public void setupParameters() {
+        parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
+        parameters.setDatabaseUser("policy");
+        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setPersistenceUnit("ToscaConceptTest");
+
+    }
+
+    @Test
+    public void testInitAndClose() throws Exception {
+        PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+        parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
+        try {
+            databaseProvider.init();
+            fail("test should throw an exception");
+        } catch (Exception pfme) {
+            assertEquals("could not connect to database with URL \"jdbc://www.acmecorp.nonexist\"", pfme.getMessage());
+        }
+        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
+
+        try {
+            databaseProvider.init();
+            databaseProvider.close();
+        } catch (Exception pfme) {
+            fail("test shold not throw an exception here");
+        }
+
+        parameters.setPersistenceUnit("WileECoyote");
+        try {
+            databaseProvider.init();
+            fail("test should throw an exception");
+        } catch (Exception pfme) {
+            assertEquals("could not create Data Access Object (DAO) using url "
+                    + "\"jdbc:h2:mem:testdb\" and persistence unit \"WileECoyote\"", pfme.getMessage());
+        }
+        parameters.setPersistenceUnit("ToscaConceptTest");
+
+        try {
+            databaseProvider.init();
+            databaseProvider.close();
+        } catch (Exception pfme) {
+            fail("test shold not throw an exception here");
+        }
+
+        try {
+            databaseProvider.close();
+        } catch (Exception pfme) {
+            fail("test shold not throw an exception here");
+        }
+
+        try {
+            DatabasePolicyModelsProviderImpl databaseProviderImpl = (DatabasePolicyModelsProviderImpl) databaseProvider;
+            databaseProvider.init();
+            databaseProviderImpl.setConnection(new DummyConnection());
+            databaseProvider.close();
+            fail("test should throw an exception");
+        } catch (Exception pfme) {
+            assertEquals("could not close connection to database with URL \"jdbc:h2:mem:testdb\"", pfme.getMessage());
+        }
+    }
+
+    @Test
+    public void testProviderMethodsNull() throws Exception {
+        PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+        databaseProvider.init();
+
+        try {
+            databaseProvider.getPolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.createPolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.updatePolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.deletePolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            databaseProvider.getPolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.createPolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.updatePolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.deletePolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            databaseProvider.getOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.createOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.updateOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.deleteOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            databaseProvider.getGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.createGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.updateGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.deleteGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            databaseProvider.getPdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.createPdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.updatePdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            databaseProvider.deletePdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
+        }
+
+        databaseProvider.close();
+    }
+
+    @Test
+    public void testProviderMethodsNotInit() throws Exception {
+        PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+        try {
+            databaseProvider.getPolicyTypes(new PfConceptKey());
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policy models provider is not initilaized", npe.getMessage());
+        }
+    }
+
+    @Test
+    public void testProviderMethods() {
+        try (PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+            databaseProvider.init();
+
+            assertNull(databaseProvider.getPolicyTypes(new PfConceptKey()));
+            assertNull(databaseProvider.createPolicyTypes(new ToscaServiceTemplate()));
+            assertNull(databaseProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+            assertNull(databaseProvider.deletePolicyTypes(new PfConceptKey()));
+
+            assertNull(databaseProvider.getPolicies(new PfConceptKey()));
+            assertNull(databaseProvider.createPolicies(new ToscaServiceTemplate()));
+            assertNull(databaseProvider.updatePolicies(new ToscaServiceTemplate()));
+            assertNull(databaseProvider.deletePolicies(new PfConceptKey()));
+
+            assertNull(databaseProvider.getOperationalPolicy("policy_id"));
+            assertNull(databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
+            assertNull(databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
+            assertNull(databaseProvider.deleteOperationalPolicy("policy_id"));
+
+            assertNull(databaseProvider.getGuardPolicy("policy_id"));
+            assertNull(databaseProvider.createGuardPolicy(new LegacyGuardPolicy()));
+            assertNull(databaseProvider.updateGuardPolicy(new LegacyGuardPolicy()));
+            assertNull(databaseProvider.deleteGuardPolicy("policy_id"));
+
+            assertNotNull(databaseProvider.getPdpGroups("filter"));
+            assertNotNull(databaseProvider.createPdpGroups(new PdpGroups()));
+            assertNotNull(databaseProvider.updatePdpGroups(new PdpGroups()));
+            assertNotNull(databaseProvider.deletePdpGroups("filter"));
+
+        } catch (Exception exc) {
+            fail("test should not throw an exception");
+        }
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
new file mode 100644 (file)
index 0000000..fb0a241
--- /dev/null
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider.impl;
+
+import javax.ws.rs.core.Response;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+
+/**
+ * Dummy implementation of {@link PolicyModelsProvider} with bad constructor.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadProviderImpl implements PolicyModelsProvider {
+    public DummyBadProviderImpl() {
+        throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Bad Request");
+    }
+
+    @Override
+    public void close() throws Exception {}
+
+    @Override
+    public void init() throws PfModelException {
+    }
+
+    @Override
+    public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+            throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
+            throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
+            throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
+        return null;
+    }
+
+    @Override
+    public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
+        return null;
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyConnection.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyConnection.java
new file mode 100644 (file)
index 0000000..776e7f5
--- /dev/null
@@ -0,0 +1,322 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider.impl;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Executor;
+
+/**
+ * Dummy database connection.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyConnection implements Connection {
+
+    @Override
+    public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        return false;
+    }
+
+    @Override
+    public <T> T unwrap(Class<T> iface) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public void abort(Executor executor) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void clearWarnings() throws SQLException {
+        return;
+    }
+
+    @Override
+    public void close() throws SQLException {
+        throw new SQLException("Bad Request");
+    }
+
+    @Override
+    public void commit() throws SQLException {
+        return;
+    }
+
+    @Override
+    public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Blob createBlob() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Clob createClob() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public NClob createNClob() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public SQLXML createSQLXML() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Statement createStatement() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+            throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public boolean getAutoCommit() throws SQLException {
+        return false;
+    }
+
+    @Override
+    public String getCatalog() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Properties getClientInfo() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public String getClientInfo(String name) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public int getHoldability() throws SQLException {
+        return 0;
+    }
+
+    @Override
+    public DatabaseMetaData getMetaData() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public int getNetworkTimeout() throws SQLException {
+        return 0;
+    }
+
+    @Override
+    public String getSchema() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public int getTransactionIsolation() throws SQLException {
+        return 0;
+    }
+
+    @Override
+    public Map<String, Class<?>> getTypeMap() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public SQLWarning getWarnings() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public boolean isClosed() throws SQLException {
+        return false;
+    }
+
+    @Override
+    public boolean isReadOnly() throws SQLException {
+        return false;
+    }
+
+    @Override
+    public boolean isValid(int timeout) throws SQLException {
+        return false;
+    }
+
+    @Override
+    public String nativeSQL(String sql) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public CallableStatement prepareCall(String sql) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
+            int resultSetHoldability) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+            throws SQLException {
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
+            int resultSetHoldability) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void rollback() throws SQLException {
+        return;
+    }
+
+    @Override
+    public void rollback(Savepoint savepoint) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setAutoCommit(boolean autoCommit) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setCatalog(String catalog) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setClientInfo(Properties properties) throws SQLClientInfoException {
+        return;
+    }
+
+    @Override
+    public void setClientInfo(String name, String value) throws SQLClientInfoException {
+        return;
+    }
+
+    @Override
+    public void setHoldability(int holdability) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setReadOnly(boolean readOnly) throws SQLException {
+        return;
+    }
+
+    @Override
+    public Savepoint setSavepoint() throws SQLException {
+        return null;
+    }
+
+    @Override
+    public Savepoint setSavepoint(String name) throws SQLException {
+        return null;
+    }
+
+    @Override
+    public void setSchema(String schema) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setTransactionIsolation(int level) throws SQLException {
+        return;
+    }
+
+    @Override
+    public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+        return;
+    }
+}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java
new file mode 100644 (file)
index 0000000..9b68dd0
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.provider.impl;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+
+/**
+ * Sub class to check getDummyResponse() method in base class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyPolicyModelsProviderSubImpl extends DummyPolicyModelsProviderImpl {
+    /**
+     * Constructor.
+     *
+     * @param parameters the parameters
+     */
+    public DummyPolicyModelsProviderSubImpl(@NonNull PolicyModelsProviderParameters parameters) {
+        super(parameters);
+    }
+
+    public ToscaServiceTemplate getBadDummyResponse1() {
+        return super.getDummyResponse("/i/dont/exist");
+    }
+
+    public ToscaServiceTemplate getBadDummyResponse2() {
+        return super.getDummyResponse(null);
+    }
+}
index f7fe5b9..bf3382f 100644 (file)
@@ -22,28 +22,237 @@ package org.onap.policy.models.provider.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PdpGroups;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
 
 /**
- * Test the dummy moldes provider implementation.
+ * Test the dummy models provider implementation.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class DummyPolicyModelsProviderTest {
 
     @Test
-    public void test() throws PfModelException {
-        PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider();
+    public void testProvider() throws Exception {
+        PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getCanonicalName());
+        parameters.setDatabaseUrl("jdbc:dummy");
+        parameters.setPersistenceUnit("dummy");
+
+        PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+        dummyProvider.init();
 
         ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey());
         assertNotNull(serviceTemplate);
         assertEquals("onap.vcpe.tca:1.0.0",
                 serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+
+        dummyProvider.close();
+    }
+
+    @Test
+    public void testProviderMethods() throws Exception {
+        PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getCanonicalName());
+        parameters.setDatabaseUrl("jdbc:dummy");
+        parameters.setPersistenceUnit("dummy");
+
+        PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+        dummyProvider.init();
+
+        assertNotNull(dummyProvider.getPolicyTypes(new PfConceptKey()));
+        assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.deletePolicyTypes(new PfConceptKey()));
+
+        assertNotNull(dummyProvider.getPolicies(new PfConceptKey()));
+        assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
+        assertNotNull(dummyProvider.deletePolicies(new PfConceptKey()));
+
+        assertNotNull(dummyProvider.getOperationalPolicy("policy_id"));
+        assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
+        assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
+        assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id"));
+
+        assertNotNull(dummyProvider.getGuardPolicy("policy_id"));
+        assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicy()));
+        assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicy()));
+        assertNotNull(dummyProvider.deleteGuardPolicy("policy_id"));
+
+        assertNotNull(dummyProvider.getPdpGroups("filter"));
+        assertNotNull(dummyProvider.createPdpGroups(new PdpGroups()));
+        assertNotNull(dummyProvider.updatePdpGroups(new PdpGroups()));
+        assertNotNull(dummyProvider.deletePdpGroups("filter"));
+
+        try {
+            dummyProvider.getPolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.createPolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.updatePolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.deletePolicyTypes(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            dummyProvider.getPolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.createPolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.updatePolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.deletePolicies(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            dummyProvider.getOperationalPolicy(null);
+
+
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.createOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.updateOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.deleteOperationalPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+            dummyProvider.getGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.createGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.updateGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.deleteGuardPolicy(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
+        }
+
+        try {
+
+
+            dummyProvider.getPdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.createPdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.updatePdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
+        }
+        try {
+            dummyProvider.deletePdpGroups(null);
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
+        }
+
+        dummyProvider.close();
+    }
+
+    @Test
+    public void testDummyResponse() {
+        DummyPolicyModelsProviderSubImpl resp = null;
+
+        try {
+            resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
+            resp.getBadDummyResponse1();
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("error serializing object", npe.getMessage());
+        } finally {
+            if (resp != null) {
+                resp.close();
+            }
+        }
+
+        try {
+            resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
+            resp.getBadDummyResponse2();
+            fail("test should throw an exception");
+        } catch (Exception npe) {
+            assertEquals("fileName is marked @NonNull but is null", npe.getMessage());
+        } finally {
+            if (resp != null) {
+                resp.close();
+            }
+        }
     }
 }
index 019c5b3..5658a1c 100644 (file)
             <version>${project.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.onap.policy.models</groupId>
+            <artifactId>policy-models-dao</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.onap.policy.models</groupId>
             <artifactId>policy-models-examples</artifactId>
index 2c0d508..2f87020 100644 (file)
@@ -52,20 +52,20 @@ public class LegacyOperationalPolicyMapper
 
         // TODO: Find out how to parse the PolicyType from the content
         // TODO: Check if this is the correct way to set the policy type version
-        toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.0"));
+        toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.1"));
 
         Map<String, String> propertyMap = new HashMap<>();
         toscaPolicy.setProperties(propertyMap);
         toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent());
 
-        PfConceptKey serviceTemplateKey = new PfConceptKey("ServiceTemplate", "1.0.0");
+        PfConceptKey serviceTemplateKey = new PfConceptKey("ServiceTemplate", "1.0.2");
         ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey);
         serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
 
         PfReferenceKey topologyTemplateKey = new PfReferenceKey(serviceTemplateKey, "TopolocyTemplate");
         serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate(topologyTemplateKey));
 
-        PfConceptKey policiesKey = new PfConceptKey("Policies", "1.0.0");
+        PfConceptKey policiesKey = new PfConceptKey("Policies", "1.0.3");
         serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies(policiesKey));
         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy);
 
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyToscaProvider.java
new file mode 100644 (file)
index 0000000..da9d929
--- /dev/null
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.legacy.provider;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+
+/**
+ * This class provides the provision of information on TOSCA concepts in the database to callers in legacy formats.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class LegacyToscaProvider {
+    /**
+     * Get legacy operational policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyId ID of the policy.
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public LegacyOperationalPolicy getOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Create legacy operational policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param legacyOperationalPolicy the definition of the policy to be created.
+     * @return the created policy
+     * @throws PfModelException on errors creating policies
+     */
+    public LegacyOperationalPolicy createOperationalPolicy(@NonNull final PfDao dao,
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Update legacy operational policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param legacyOperationalPolicy the definition of the policy to be updated
+     * @return the updated policy
+     * @throws PfModelException on errors updating policies
+     */
+    public LegacyOperationalPolicy updateOperationalPolicy(@NonNull final PfDao dao,
+            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Delete legacy operational policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyId ID of the policy.
+     * @return the deleted policy
+     * @throws PfModelException on errors deleting policies
+     */
+    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Get legacy guard policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyId ID of the policy.
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public LegacyGuardPolicy getGuardPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Create legacy guard policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param legacyGuardPolicy the definition of the policy to be created.
+     * @return the created policy
+     * @throws PfModelException on errors creating policies
+     */
+    public LegacyGuardPolicy createGuardPolicy(@NonNull final PfDao dao,
+            @NonNull final LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Update legacy guard policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param legacyGuardPolicy the definition of the policy to be updated
+     * @return the updated policy
+     * @throws PfModelException on errors updating policies
+     */
+    public LegacyGuardPolicy updateGuardPolicy(@NonNull final PfDao dao,
+            @NonNull final LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Delete legacy guard policy.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyId ID of the policy.
+     * @return the deleted policy
+     * @throws PfModelException on errors deleting policies
+     */
+    public LegacyGuardPolicy deleteGuardPolicy(@NonNull final PfDao dao, @NonNull final String policyId)
+            throws PfModelException {
+        return null;
+    }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
new file mode 100644 (file)
index 0000000..3d563a1
--- /dev/null
@@ -0,0 +1,142 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.provider;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+
+/**
+ * This class provides the provision of information on TOSCA concepts in the database to callers.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class SimpleToscaProvider {
+    /**
+     * Get policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyTypeKey the policy type key for the policy types to be retrieved. A null key name returns all policy
+     *        types. A null key version returns all versions of the policy type name specified in the key.
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Create policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definition of the policy types to be created
+     * @return the TOSCA service template containing the created policy types
+     * @throws PfModelException on errors creating policy types
+     */
+    public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Create policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definition of the policy types to be modified
+     * @return the TOSCA service template containing the modified policy types
+     * @throws PfModelException on errors updating policy types
+     */
+    public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Delete policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyTypeKey the policy type key for the policy types to be deleted, if the version of the key is null,
+     *        all versions of the policy type are deleted.
+     * @return the TOSCA service template containing the policy types that were deleted
+     * @throws PfModelException on errors deleting policy types
+     */
+    public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Get policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyKey the policy key for the policies to be retrieved. The parent name and version must be specified.
+     *        A null local name returns all policies for a parent policy type.
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
+            throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Create policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definitions of the new policies to be created.
+     * @return the TOSCA service template containing the policy types that were created
+     * @throws PfModelException on errors creating policies
+     */
+    public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Update policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param serviceTemplate the service template containing the definitions of the policies to be updated.
+     * @return the TOSCA service template containing the policies that were updated
+     * @throws PfModelException on errors updating policies
+     */
+    public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
+            @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+        return null;
+    }
+
+    /**
+     * Delete policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param policyKey the policy key
+     * @return the TOSCA service template containing the policy types that were deleted
+     * @throws PfModelException on errors deleting policies
+     */
+    public ToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
+            throws PfModelException {
+        return null;
+    }
+}
diff --git a/pom.xml b/pom.xml
index 9694746..254a540 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,7 @@
         <module>models-dao</module>
         <module>models-tosca</module>
         <module>models-pap</module>
+        <module>models-pdp</module>
         <module>models-errors</module>
         <module>models-decisions</module>
         <module>models-provider</module>