Merge "move two modules from drools-application to models"
authorJorge Hernandez <jorge.hernandez-herrero@att.com>
Fri, 5 Apr 2019 15:30:39 +0000 (15:30 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 5 Apr 2019 15:30:39 +0000 (15:30 +0000)
57 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfObjectFiler.java [moved from models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpStatistics.java with 62% similarity]
models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParameter.java [new file with mode: 0644]
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParametersInfo.java [new file with mode: 0644]
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleRequestInput.java [new file with mode: 0644]
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVnfInfo.java [new file with mode: 0644]
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStateChange.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
models-pdp/src/test/java/org/onap/policy/models/persistence/provider/PdpProviderTest.java
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
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/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
models-tosca/pom.xml
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifier.java [moved from models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifier.java with 96% similarity]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersion.java [moved from models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyIdentifierOptVersion.java with 96% similarity]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java [new file with mode: 0644]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifier.java [moved from models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/ToscaPolicyTypeIdentifier.java with 96% similarity]
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyInput.java
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifier.java [moved from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifier.java with 94% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifierOptVersion.java [moved from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyIdentifierOptVersion.java with 95% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyTypeIdentifier.java [moved from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestToscaPolicyTypeIdentifier.java with 94% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java [moved from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ToscaIdentifierTestBase.java with 97% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java

  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.pap.concepts;
+package org.onap.policy.models.base;
 
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import java.util.List;
 
 /**
- * Class to represent statistics of a PDP instance.
+ * Interface for filtering a list of concepts.
  *
- * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ * @author Liam Fallon (liam.fallon@est.tech)
  */
-@Getter
-@Setter
-@ToString
-public class PdpStatistics {
+@FunctionalInterface
+public interface PfObjectFiler<T> {
+    /**
+     * Filter an incoming list, removing items that do not match the filter.
+     *
+     * @param originalList the original list
+     * @return the filtered list
+     */
+    public List<T> filter(final List<T> originalList);
 
-    private String pdpInstanceId;
-    private long policyDeployCount;
-    private long policyDeploySuccessCount;
-    private long policyDeployFailCount;
-    private long policyExecutedCount;
-    private long policyExecutedSuccessCount;
-    private long policyExecutedFailCount;
 }
index 609afef..e635085 100644 (file)
@@ -108,7 +108,7 @@ public interface PfDao {
     <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
 
     /**
-     * policypolicypolicy Delete a collection of objects in the database referred to by reference key.
+     * Delete a collection of objects in the database referred to by reference key.
      *
      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
@@ -132,10 +132,11 @@ public interface PfDao {
      * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
      *        name are returned.
-     * @param key the key of the object to get
+     * @param name the name of the object to get, null returns all objects
+     * @param version the version the object to get, null returns all objects for a specified name
      * @return the objects that was retrieved from the database
      */
-    <T extends PfConcept> List<T> getFiltered(Class<T> someClass, PfConceptKey key);
+    <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
 
     /**
      * Get an object from the database, referred to by concept key.
@@ -186,25 +187,6 @@ public interface PfDao {
      */
     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
 
-    /**
-     * Get latest version of objects in the database of a given type.
-     *
-     * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
-     * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
-     * @return the objects or null if no objects were retrieved
-     */
-    <T extends PfConcept> List<T> getLatestVersions(Class<T> someClass);
-
-    /**
-     * Get latest version of an object in the database of a given type.
-     *
-     * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
-     * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
-     * @param conceptName the name of the concept for which to get the latest version
-     * @return the objects or null if no objects were retrieved
-     */
-    <T extends PfConcept> T getLatestVersion(Class<T> someClass, final String conceptName);
-
     /**
      * Get a concept from the database with the given concept key.
      *
index f7659b2..1820176 100644 (file)
@@ -67,7 +67,6 @@ public class DefaultPfDao implements PfDao {
     private static final String PARENT_NAME_FILTER    = "c.key.parentKeyName = :parentname";
     private static final String PARENT_VERSION_FILTER = "c.key.parentKeyVersion = :parentversion";
     private static final String LOCAL_NAME_FILTER     = "c.key.localName = :localname";
-    private static final String MAX_VERISON_FILTER    = "c.key.version = (SELECT MAX(c.key.version) FROM __TABLE__ c)";
 
     private static final String DELETE_BY_CONCEPT_KEY =
             DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER;
@@ -80,12 +79,6 @@ public class DefaultPfDao implements PfDao {
 
     private static final String SELECT_ALL_VERSIONS = SELECT_FROM_TABLE + WHERE + NAME_FILTER;
 
-    private static final String SELECT_LATEST_VERSION =
-            SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + MAX_VERISON_FILTER;
-
-    private static final String SELECT_LATEST_VERSIONS =
-            "SELECT c FROM __TABLE__ c WHERE c.key.version = (SELECT MAX(c.key.version) FROM __TABLE__ c)";
-
     private static final String SELECT_BY_CONCEPT_KEY =
             SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER;
 
@@ -307,16 +300,17 @@ public class DefaultPfDao implements PfDao {
     }
 
     @Override
-    public <T extends PfConcept> List<T> getFiltered(Class<T> someClass, PfConceptKey key) {
-        if (key.getName() == null) {
+    public <T extends PfConcept> List<T> getFiltered(final Class<T> someClass, final String name,
+            final String version) {
+        if (name == null) {
             return getAll(someClass);
         }
 
-        if (key.getVersion() == null) {
-            return getAllVersions(someClass, key.getName());
+        if (version == null) {
+            return getAllVersions(someClass, name);
         }
 
-        T foundConcept = get(someClass, key);
+        T foundConcept = get(someClass, new PfConceptKey(name, version));
 
         return (foundConcept == null ? Collections.emptyList() : Collections.singletonList(foundConcept));
     }
@@ -420,43 +414,6 @@ public class DefaultPfDao implements PfDao {
         }
     }
 
-    @Override
-    public <T extends PfConcept> List<T> getLatestVersions(final Class<T> someClass) {
-        if (someClass == null) {
-            return Collections.emptyList();
-        }
-        final EntityManager mg = getEntityManager();
-        List<T> ret;
-        try {
-            // @formatter:off
-            return mg.createQuery(setQueryTable(SELECT_LATEST_VERSIONS, someClass), someClass)
-                    .getResultList();
-            // @formatter:on
-        } finally {
-            mg.close();
-        }
-    }
-
-    @Override
-    public <T extends PfConcept> T getLatestVersion(final Class<T> someClass, final String conceptName) {
-        if (someClass == null || conceptName == null) {
-            return null;
-        }
-        final EntityManager mg = getEntityManager();
-        List<T> ret;
-        try {
-            // @formatter:off
-            ret = mg.createQuery(setQueryTable(SELECT_LATEST_VERSION, someClass), someClass)
-                    .setParameter(NAME, conceptName)
-                    .getResultList();
-            // @formatter:on
-        } finally {
-            mg.close();
-        }
-
-        return getSingleResult(someClass, conceptName, ret);
-    }
-
     @Override
     public <T extends PfConcept> T getConcept(final Class<T> someClass, final PfConceptKey key) {
         if (someClass == null || key == null) {
index a0ad5c2..bab28c4 100644 (file)
@@ -112,6 +112,8 @@ public class EntityTest {
 
         testVersionOps();
 
+        testgetFilteredOps();
+
         pfDao.close();
     }
 
@@ -326,11 +328,39 @@ public class EntityTest {
         pfDao.create(keyInfo5);
 
         assertEquals(3, pfDao.getAllVersions(DummyConceptEntity.class, "AAA0").size());
-        DummyConceptEntity latestVersionEntity = pfDao.getLatestVersion(DummyConceptEntity.class, "AAA0");
-        assertEquals(aKey2, latestVersionEntity.getKey());
-        List<DummyConceptEntity> returnedLatestVersions = pfDao.getLatestVersions(DummyConceptEntity.class);
-        assertEquals(2, returnedLatestVersions.size());
-        assertEquals("0.0.3", returnedLatestVersions.get(0).getKey().getVersion());
-        assertEquals("0.0.3", returnedLatestVersions.get(1).getKey().getVersion());
+    }
+
+    private void testgetFilteredOps() {
+        final PfConceptKey aKey0 = new PfConceptKey("AAA0", "0.0.1");
+        final PfConceptKey aKey1 = new PfConceptKey("AAA0", "0.0.2");
+        final PfConceptKey aKey2 = new PfConceptKey("AAA0", "0.0.3");
+        final PfConceptKey bKey0 = new PfConceptKey("BBB0", "0.0.1");
+        final PfConceptKey bKey1 = new PfConceptKey("BBB0", "0.0.2");
+        final PfConceptKey bKey2 = new PfConceptKey("BBB0", "0.0.3");
+        final DummyConceptEntity keyInfo0 = new DummyConceptEntity(aKey0,
+                UUID.fromString("00000000-0000-0000-0000-000000000000"), "key description 0");
+        final DummyConceptEntity keyInfo1 = new DummyConceptEntity(aKey1,
+                UUID.fromString("00000000-0000-0000-0000-000000000001"), "key description 1");
+        final DummyConceptEntity keyInfo2 = new DummyConceptEntity(aKey2,
+                UUID.fromString("00000000-0000-0000-0000-000000000002"), "key description 2");
+        final DummyConceptEntity keyInfo3 = new DummyConceptEntity(bKey0,
+                UUID.fromString("00000000-0000-0000-0000-000000000000"), "key description 0");
+        final DummyConceptEntity keyInfo4 = new DummyConceptEntity(bKey1,
+                UUID.fromString("00000000-0000-0000-0000-000000000001"), "key description 1");
+        final DummyConceptEntity keyInfo5 = new DummyConceptEntity(bKey2,
+                UUID.fromString("00000000-0000-0000-0000-000000000002"), "key description 2");
+
+        pfDao.create(keyInfo0);
+        pfDao.create(keyInfo1);
+        pfDao.create(keyInfo2);
+        pfDao.create(keyInfo3);
+        pfDao.create(keyInfo4);
+        pfDao.create(keyInfo5);
+
+        assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, null).size());
+        assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "AAA0", null).size());
+        assertEquals(3, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", null).size());
+        assertEquals(1, pfDao.getFiltered(DummyConceptEntity.class, "BBB0", "0.0.3").size());
+        assertEquals(6, pfDao.getFiltered(DummyConceptEntity.class, null, "0.0.3").size());
     }
 }
index 4238391..4de3ed9 100644 (file)
@@ -2,8 +2,9 @@
  * ============LICENSE_START=======================================================
  * SdncActorServiceProvider
  * ================================================================================
- * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 Huawei Intellectual Property. All rights reserved.
  * Modifications 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.
@@ -38,6 +39,11 @@ import org.onap.policy.sdnc.SdncHealRequest;
 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
 import org.onap.policy.sdnc.SdncHealRequestInfo;
 import org.onap.policy.sdnc.SdncHealServiceInfo;
+import org.onap.policy.sdnc.SdncHealVfModuleParameter;
+import org.onap.policy.sdnc.SdncHealVfModuleParametersInfo;
+import org.onap.policy.sdnc.SdncHealVfModuleRequestInput;
+import org.onap.policy.sdnc.SdncHealVnfInfo;
+
 import org.onap.policy.sdnc.SdncRequest;
 
 import org.slf4j.Logger;
@@ -56,6 +62,9 @@ public class SdncActorServiceProvider implements Actor {
     // Strings for recipes
     private static final String RECIPE_REROUTE = "Reroute";
 
+    // Strings for recipes
+    private static final String RECIPE_BW_ON_DEMAND = "BandwidthOnDemand";
+
     private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_REROUTE);
     private static final ImmutableMap<String, List<String>> targets =
             new ImmutableMap.Builder<String, List<String>>().put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build();
@@ -88,28 +97,86 @@ public class SdncActorServiceProvider implements Actor {
      * @param policy the policy
      * @return the constructed request
      */
-    public static SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
+    public SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
             Policy policy) {
+        switch (policy.getRecipe()) {
+            case RECIPE_REROUTE:
+                return constructReOptimizeRequest(onset);
+            case RECIPE_BW_ON_DEMAND:
+                logger.info("Construct request for receipe {}" , RECIPE_BW_ON_DEMAND);
+                return constructBwOnDemandRequest(onset);
+            default:
+                logger.info("Unsupported recipe {} " + policy.getRecipe());
+                return null;
+        }
+    }
 
-        if (!policy.getRecipe().equalsIgnoreCase(RECIPE_REROUTE)) {
+    private SdncRequest constructBwOnDemandRequest(VirtualControlLoopEvent onset) {
+        // Construct an Sdnc request
+        String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
+        if (serviceInstance == null || serviceInstance.isEmpty()) {
+            // This indicates that AAI Enrichment needs to be done by event producer.
             return null;
         }
+        SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter();
+        bandwidth.setName("bandwidth");
+        bandwidth.setValue(onset.getAai().get("bandwidth"));
+
+        SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter();
+        timeStamp.setName("bandwidth-change-time");
+        timeStamp.setValue(onset.getAai().get("bandwidth-change-time"));
+
+        SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo();
+        vfParametersInfo.addParameters(bandwidth);
+        vfParametersInfo.addParameters(timeStamp);
+
+        SdncHealVfModuleRequestInput vfRequestInfo = new SdncHealVfModuleRequestInput();
+        vfRequestInfo.setVfModuleParametersInfo(vfParametersInfo);
+
+        SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
+        serviceInfo.setServiceInstanceId(serviceInstance);
+
+        SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
+        requestInfo.setRequestAction("SdwanBWPolicyChange");
+
+        SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
+        headerInfo.setSvcAction("update");
+        headerInfo.setSvcRequestId(UUID.randomUUID().toString());
 
+        SdncRequest request = new SdncRequest();
+        request.setNsInstanceId(serviceInstance);
+        request.setRequestId(onset.getRequestId());
+        request.setUrl("/GENERIC-RESOURCE-API:vnf-topology-operation");
+
+        SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo();
+        vnfInfo.setVnfId(onset.getAai().get("vnfId"));
+
+        SdncHealRequest healRequest = new SdncHealRequest();
+        healRequest.setVnfInfo(vnfInfo);
+        healRequest.setRequestHeaderInfo(headerInfo);
+        healRequest.setVfModuleRequestInput(vfRequestInfo);
+        healRequest.setRequestInfo(requestInfo);
+        healRequest.setServiceInfo(serviceInfo);
+        request.setHealRequest(healRequest);
+        return request;
+    }
+
+    private SdncRequest constructReOptimizeRequest(VirtualControlLoopEvent onset) {
         // Construct an Sdnc request
         String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
         if (serviceInstance == null || serviceInstance.isEmpty()) {
-            // This indicates that AAI Enrichment needs to be done by event producer. 
+            // This indicates that AAI Enrichment needs to be done by event producer.
             return null;
         }
         SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
         serviceInfo.setServiceInstanceId(serviceInstance);
-        
+
         String networkId = onset.getAai().get("network-information.network-id");
         if (networkId == null || networkId.isEmpty()) {
-            // This indicates that AAI Enrichment needs to be done by event producer. 
+            // This indicates that AAI Enrichment needs to be done by event producer.
             return null;
         }
-        SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();        
+        SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
         networkInfo.setNetworkId(networkId);
 
         SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
@@ -122,6 +189,7 @@ public class SdncActorServiceProvider implements Actor {
         SdncRequest request = new SdncRequest();
         request.setNsInstanceId(serviceInstance);
         request.setRequestId(onset.getRequestId());
+        request.setUrl("/GENERIC-RESOURCE-API:network-topology-operation");
 
         SdncHealRequest healRequest = new SdncHealRequest();
         healRequest.setRequestHeaderInfo(headerInfo);
@@ -129,7 +197,6 @@ public class SdncActorServiceProvider implements Actor {
         healRequest.setRequestInfo(requestInfo);
         healRequest.setServiceInfo(serviceInfo);
         request.setHealRequest(healRequest);
-
         return request;
     }
 }
\ No newline at end of file
index 7b64b87..7288ec1 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * TestSdncActorServiceProvider
  * ================================================================================
- * Copyright (C) 2018 Huawei. All rights reserved.
- * Modifications Copyright (C) 2018 AT&T Corp. All rights reserved.
+ * Copyright (C) 2018-2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2018-2019 AT&T Corp. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -69,31 +69,32 @@ public class SdncActorServiceProviderTest {
         Policy policy = new Policy();
         policy.setRecipe("Reroute");
 
-        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        SdncActorServiceProvider provider = new SdncActorServiceProvider();
+        assertNull(provider.constructRequest(onset, operation, policy));
 
         onset.getAai().put("network-information.network-id", "network-5555");
-        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNull(provider.constructRequest(onset, operation, policy));
 
         PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
         PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
-        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNull(provider.constructRequest(onset, operation, policy));
 
         UUID requestId = UUID.randomUUID();
         onset.setRequestId(requestId);
-        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNull(provider.constructRequest(onset, operation, policy));
 
         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
-        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNull(provider.constructRequest(onset, operation, policy));
 
         onset.getAai().put("service-instance.service-instance-id", "service-instance-01");
-        assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNotNull(provider.constructRequest(onset, operation, policy));
 
         policy.setRecipe("Reroute");
-        assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+        assertNotNull(provider.constructRequest(onset, operation, policy));
 
         SdncRequest request =
-                SdncActorServiceProvider.constructRequest(onset, operation, policy);
+                provider.constructRequest(onset, operation, policy);
 
         assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
         assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction());
index 88645d5..70e81d8 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Huawei. All rights reserved.
+ * Copyright (C) 2018-2019 Huawei. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,6 +39,12 @@ public class SdncHealRequest implements Serializable {
     @SerializedName("network-information")
     private SdncHealNetworkInfo networkInfo;
 
+    @SerializedName("vnf-information")
+    private SdncHealVnfInfo vnfInfo;
+
+    @SerializedName("vf-module-request-input")
+    private SdncHealVfModuleRequestInput vfModuleRequestInput;
+
     public SdncHealRequest() {
         // Default constructor for SdncHealRequest
     }
@@ -75,4 +81,19 @@ public class SdncHealRequest implements Serializable {
         this.networkInfo = networkInfo;
     }
 
+    public SdncHealVnfInfo getVnfInfo() {
+        return vnfInfo;
+    }
+
+    public void setVnfInfo(SdncHealVnfInfo vnfInfo) {
+        this.vnfInfo = vnfInfo;
+    }
+
+    public SdncHealVfModuleRequestInput getVfModuleRequestInput() {
+        return vfModuleRequestInput;
+    }
+
+    public void setVfModuleRequestInput(SdncHealVfModuleRequestInput input) {
+        this.vfModuleRequestInput = input;
+    }
 }
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParameter.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParameter.java
new file mode 100644 (file)
index 0000000..0fe82bb
--- /dev/null
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealVfModuleParameter implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("name")
+    private String name;
+
+    @SerializedName("value")
+    private String value;
+
+    public SdncHealVfModuleParameter() {
+        // Default constructor for SdncHealVfModuleParameter
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParametersInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleParametersInfo.java
new file mode 100644 (file)
index 0000000..4515b97
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+public class SdncHealVfModuleParametersInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("param")
+    private List<SdncHealVfModuleParameter> parameters;
+
+    public SdncHealVfModuleParametersInfo() {
+        // Default constructor for SdncHealVfModuleParametersInfo
+        parameters = new LinkedList<>();
+    }
+
+    public List<SdncHealVfModuleParameter> getParameters() {
+        return parameters;
+    }
+
+    public void setParameters(List<SdncHealVfModuleParameter> parameters) {
+        this.parameters = parameters;
+    }
+
+    public void addParameters(SdncHealVfModuleParameter parameter) {
+        parameters.add(parameter);
+    }
+}
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleRequestInput.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVfModuleRequestInput.java
new file mode 100644 (file)
index 0000000..c903c77
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealVfModuleRequestInput implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("vf-module-input-parameters")
+    private SdncHealVfModuleParametersInfo vfModuleParametersInfo;
+
+    public SdncHealVfModuleRequestInput() {
+        // Default constructor for SdncHealVfModuleRequestInput
+    }
+
+    public SdncHealVfModuleParametersInfo getVfModuleParametersInfo() {
+        return vfModuleParametersInfo;
+    }
+
+    public void setVfModuleParametersInfo(SdncHealVfModuleParametersInfo info) {
+        this.vfModuleParametersInfo = info;
+    }
+}
diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVnfInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealVnfInfo.java
new file mode 100644 (file)
index 0000000..67eaa3b
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealVnfInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("vnf-id")
+    private String vnfId;
+
+    public SdncHealVnfInfo() {
+        // Default constructor for SdncHealVnfInfo
+    }
+
+    public String getVnfId() {
+        return vnfId;
+    }
+
+    public void setVnfId(String vnfId) {
+        this.vnfId = vnfId;
+    }
+}
index 5770a23..864ddf5 100644 (file)
@@ -97,7 +97,7 @@ public final class SdncManager implements Runnable {
         responseError.setResponseOutput(responseOutput);
 
         headers.put("Accept", "application/json");
-        String sdncUrl = sdncUrlBase + "/GENERIC-RESOURCE-API:network-topology-operation";
+        String sdncUrl = sdncUrlBase + sdncRequest.getUrl();
 
         try {
             String sdncRequestJson = Serialization.gsonPretty.toJson(sdncRequest);
index 4aaa844..b2be020 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  * Copyright (C) 2018 Huawei. All rights reserved.
  * Modifications 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.
@@ -20,6 +21,7 @@
 package org.onap.policy.sdnc;
 
 import com.google.gson.annotations.SerializedName;
+
 import java.io.Serializable;
 import java.util.UUID;
 
@@ -29,6 +31,7 @@ public class SdncRequest implements Serializable {
     // These fields are not serialized and not part of JSON
     private transient String nsInstanceId;
     private transient UUID requestId;
+    private transient String url;
 
     @SerializedName("input")
     private SdncHealRequest healRequest;
@@ -60,4 +63,12 @@ public class SdncRequest implements Serializable {
     public void setHealRequest(SdncHealRequest healRequest) {
         this.healRequest = healRequest;
     }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
 }
index 0484cc3..7bc8892 100644 (file)
@@ -24,7 +24,7 @@ import java.util.List;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
 
 /**
  * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java
new file mode 100644 (file)
index 0000000..b49bede
--- /dev/null
@@ -0,0 +1,74 @@
+/*-
+ * ============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.pdp.concepts;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfObjectFiler;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+
+/**
+ * Filter class for searches for {@link PdpGroup} instances.
+ * If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class PdpGroupFilter implements PfObjectFiler<PdpGroup> {
+    public static final String LATEST_VERSION = "LATEST";
+
+    // Regular expression
+    private String name;
+
+    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    private String version;
+
+    private PdpState groupState;
+
+    // Regular expression
+    private String pdpType;
+
+    // Set regular expressions on fields to match policy type names and versions
+    private ToscaPolicyTypeIdentifier policyType;
+
+    // Set regular expressions on fields to match policy names and versions
+    private ToscaPolicyIdentifier policy;
+
+    @Override
+    public List<PdpGroup> filter(@NonNull final List<PdpGroup> originalList) {
+
+        // @formatter:off
+        return originalList.stream()
+                .filter(p -> name       != null && p.getName()   .matches(name))
+                .filter(p -> version    != null && p.getVersion().matches(version))
+                .filter(p -> groupState != null && p.getPdpGroupState().equals(groupState))
+                .collect(Collectors.toList());
+        // @formatter:off
+    }
+}
index 6160027..a48724e 100644 (file)
@@ -29,7 +29,8 @@ 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.
+ * Class to represent the base class for various messages that will be exchanged between
+ * PAP and PDP.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
@@ -49,6 +50,24 @@ public class PdpMessage {
      */
     private long timestampMs = System.currentTimeMillis();
 
+    /**
+     * PDP name, or {@code null} for state-change broadcast messages.
+     */
+    private String name;
+
+    /**
+     * Group associated with the PDP. For state-change messages, this may be {@code null},
+     * if the {@link #name} is provided.
+     */
+    private String pdpGroup;
+
+    /**
+     * Group associated with the PDP. For state-change messages, this may be {@code null},
+     * if the {@link #name} is provided.
+     */
+    private String pdpSubgroup;
+
+
     /**
      * Constructor for instantiating PdpMessage class with message name.
      *
@@ -57,4 +76,17 @@ public class PdpMessage {
     public PdpMessage(final PdpMessageType messageName) {
         this.messageName = messageName;
     }
+
+    /**
+     * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or
+     * the time stamp.
+     *
+     * @param source source from which to copy
+     */
+    public PdpMessage(final PdpMessage source) {
+        this.messageName = source.messageName;
+        this.name = source.name;
+        this.pdpGroup = source.pdpGroup;
+        this.pdpSubgroup = source.pdpSubgroup;
+    }
 }
index d8f938b..fe953cb 100644 (file)
@@ -35,13 +35,10 @@ import org.onap.policy.models.pdp.enums.PdpState;
  */
 @Getter
 @Setter
-@ToString
+@ToString(callSuper = true)
 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.
@@ -57,11 +54,8 @@ public class PdpStateChange extends PdpMessage {
      * @param source source from which to copy
      */
     public PdpStateChange(PdpStateChange source) {
-        super(PdpMessageType.PDP_STATE_CHANGE);
+        super(source);
 
-        this.name = source.name;
         this.state = source.state;
-        this.pdpGroup = source.pdpGroup;
-        this.pdpSubgroup = source.pdpSubgroup;
     }
 }
index 6f9b9c9..36e8d00 100644 (file)
@@ -35,9 +35,10 @@ import lombok.ToString;
 @ToString
 public class PdpStatistics {
 
-    private long policyDownloadCount;
-    private long policyDownloadSuccessCount;
-    private long policyDownloadFailCount;
+    private String pdpInstanceId;
+    private long policyDeployCount;
+    private long policyDeploySuccessCount;
+    private long policyDeployFailCount;
     private long policyExecutedCount;
     private long policyExecutedSuccessCount;
     private long policyExecutedFailCount;
index d0fef45..5858b6a 100644 (file)
 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.PdpHealthStatus;
 import org.onap.policy.models.pdp.enums.PdpMessageType;
 import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 
 /**
  * Class to represent the PDP_STATUS message that all the PDP's will send to PAP.
@@ -38,20 +38,20 @@ import org.onap.policy.models.pdp.enums.PdpState;
  */
 @Getter
 @Setter
-@ToString
+@ToString(callSuper = true)
 public class PdpStatus extends PdpMessage {
 
-    private String name;
-    private String version;
     private String pdpType;
     private PdpState state;
     private PdpHealthStatus healthy;
+
+    /**
+     * Description of the PDP or the PDP type.  May be left {@code null}.
+     */
     private String description;
-    private String pdpGroup;
-    private String pdpSubgroup;
+
     private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes;
     private List<ToscaPolicyIdentifier> policies;
-    private String instance;
     private String deploymentInstanceInfo;
     private String properties;
     private PdpStatistics statistics;
index b4f4693..4e58436 100644 (file)
@@ -31,6 +31,8 @@ import lombok.Setter;
 import lombok.ToString;
 
 import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 
 /**
  * Class to represent a group of all PDP's of the same pdp type running for a particular domain.
index 200515c..a28bd76 100644 (file)
@@ -36,14 +36,15 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
  */
 @Getter
 @Setter
-@ToString
+@ToString(callSuper = true)
 public class PdpUpdate extends PdpMessage {
 
-    private String name;
+    /**
+     * Description of the PDP group.
+     */
     private String description;
-    private String pdpGroup;
-    private String pdpSubgroup;
-    private long pdpHeartbeatIntervalMs;
+
+    private Long pdpHeartbeatIntervalMs;
     private List<ToscaPolicy> policies;
 
     /**
@@ -60,12 +61,9 @@ public class PdpUpdate extends PdpMessage {
      * @param source source from which to copy
      */
     public PdpUpdate(PdpUpdate source) {
-        super(PdpMessageType.PDP_UPDATE);
+        super(source);
 
-        this.name = source.name;
         this.description = source.description;
-        this.pdpGroup = source.pdpGroup;
-        this.pdpSubgroup = source.pdpSubgroup;
         this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs;
         this.policies = (source.policies == null ? null
                         : source.policies.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
index 7020b45..1937cbf 100644 (file)
@@ -28,7 +28,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import javax.persistence.CollectionTable;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
@@ -39,11 +38,9 @@ import javax.persistence.InheritanceType;
 import javax.persistence.JoinColumn;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
-
 import org.onap.policy.common.utils.validation.Assertions;
 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
 import org.onap.policy.models.base.PfAuthorative;
@@ -58,9 +55,8 @@ import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 
 /**
  * Class to represent a PDP subgroup in the database.
index 20553d7..a1eb97d 100644 (file)
 package org.onap.policy.models.pdp.persistence.provider;
 
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
-import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
@@ -38,12 +35,12 @@ import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.dao.PfDao;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.persistence.concepts.JpaPdp;
 import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
 import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,7 +67,7 @@ public class PdpProvider {
     public List<PdpGroup> getPdpGroups(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
 
-        List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, new PfConceptKey(name, version));
+        List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, name, version);
 
         if (foundPdpGroups != null) {
             return asPdpGroupList(foundPdpGroups);
@@ -90,29 +87,31 @@ public class PdpProvider {
      * @throws PfModelException on errors getting policies
      */
     public List<PdpGroup> getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException {
-        List<JpaPdpGroup> returnList = new ArrayList<>();
+        List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>();
 
         if (name == null) {
-            returnList.add(dao.getLatestVersion(JpaPdpGroup.class, name));
-        }
-        else {
-            returnList.addAll(dao.getLatestVersions(JpaPdpGroup.class));
+            jpaPdpGroupList.addAll(dao.getAll(JpaPdpGroup.class));
+        } else {
+            jpaPdpGroupList.addAll(dao.getAllVersions(JpaPdpGroup.class, name));
         }
 
-        return asPdpGroupList(returnList);
+        return asPdpGroupList(jpaPdpGroupList);
     }
 
     /**
-     * Get a filtered list of PDP groups, returns only active PDP groups.
+     * Get filtered PDP groups.
      *
      * @param dao the DAO to use to access the database
-     * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
-     * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
+     * @param filter the filter for the PDP groups to get
      * @return the PDP groups found
+     * @throws PfModelException on errors getting policies
      */
-    public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, final String pdpType,
-            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
-        return new ArrayList<>();
+    public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter)
+            throws PfModelException {
+
+        List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class);
+
+        return asPdpGroupList(jpaPdpGroupList);
     }
 
     /**
@@ -307,19 +306,6 @@ public class PdpProvider {
         // Not implemented yet
     }
 
-    /**
-     * Get deployed policies.
-     *
-     * @param dao the DAO to use to access the database
-     * @param name the name of the policy to get deployed policies for, null to get all deployed policies
-     * @return the policies deployed as a map of policy lists keyed by PDP group name and version
-     * @throws PfModelException on errors getting policies
-     */
-    public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(@NonNull final PfDao dao,
-            final String name) throws PfModelException {
-        return new LinkedHashMap<>();
-    }
-
     /**
      * Convert JPA PDP group list to an authorative PDP group list.
      *
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java
new file mode 100644 (file)
index 0000000..ee7e15b
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * ============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.pdp.concepts;
+
+/**
+ * Utility class for tests of PdpMessage subclasses.
+ */
+public class PdpMessageUtils {
+
+    public static String removeVariableFields(String text) {
+        return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn");
+    }
+}
index 39aee6f..1813dde 100644 (file)
@@ -38,7 +38,7 @@ import org.onap.policy.common.utils.validation.ToStringTester;
 public class TestModels {
 
     @Test
-    public void testPapModels() {
+    public void testPdpModels() {
         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-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java
new file mode 100644 (file)
index 0000000..515c483
--- /dev/null
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpMessage {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpMessage((PdpMessage) null)).isInstanceOf(NullPointerException.class);
+
+        PdpMessage orig = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE);
+
+        // verify with null values
+        PdpMessage newmsg = new PdpMessage(orig);
+        newmsg.setRequestId(orig.getRequestId());
+        newmsg.setTimestampMs(orig.getTimestampMs());
+        assertEquals(orig.toString(), newmsg.toString());
+
+        // verify with all values
+        orig.setName("my-name");
+        orig.setPdpGroup("my-group");
+        orig.setPdpSubgroup("my-subgroup");
+
+        newmsg = new PdpMessage(orig);
+        newmsg.setRequestId(orig.getRequestId());
+        newmsg.setTimestampMs(orig.getTimestampMs());
+        assertEquals(orig.toString(), newmsg.toString());
+    }
+}
index 8c843a1..55eaedc 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.policy.models.pdp.concepts;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
+import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
 
 import org.junit.Test;
 import org.onap.policy.models.pdp.enums.PdpState;
@@ -39,8 +40,7 @@ public class TestPdpStateChange {
         PdpStateChange orig = new PdpStateChange();
 
         // verify with null values
-        assertEquals("PdpStateChange(name=null, state=null, pdpGroup=null, pdpSubgroup=null)",
-                        new PdpStateChange(orig).toString());
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString()));
 
         // verify with all values
         orig.setName("my-name");
@@ -48,7 +48,6 @@ public class TestPdpStateChange {
         orig.setPdpSubgroup("my-subgroup");
         orig.setState(PdpState.SAFE);
 
-        assertEquals("PdpStateChange(name=my-name, state=SAFE, pdpGroup=my-group, pdpSubgroup=my-subgroup)",
-                        new PdpStateChange(orig).toString());
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStateChange(orig).toString()));
     }
 }
index 2580ca8..c80745d 100644 (file)
@@ -29,6 +29,8 @@ import java.util.Map;
 import java.util.TreeMap;
 
 import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 
 /**
  * Test the copy constructor, as {@link TestModels} tests the other methods.
index d2b571f..b366088 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.policy.models.pdp.concepts;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
 
 import java.util.Arrays;
 import java.util.List;
@@ -42,15 +43,14 @@ public class TestPdpUpdate {
         PdpUpdate orig = new PdpUpdate();
 
         // verify with null values
-        assertEquals("PdpUpdate(name=null, description=null, pdpGroup=null, pdpSubgroup=null, "
-                        + "pdpHeartbeatIntervalMs=0, policies=null)", new PdpUpdate(orig).toString());
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString()));
 
         // verify with all values
         orig.setDescription("my-description");
         orig.setName("my-name");
         orig.setPdpGroup("my-group");
         orig.setPdpSubgroup("my-subgroup");
-        orig.setPdpHeartbeatIntervalMs(30000);
+        orig.setPdpHeartbeatIntervalMs(30000L);
 
         ToscaPolicy policy1 = new ToscaPolicy();
         policy1.setName("policy-a");
@@ -65,13 +65,7 @@ public class TestPdpUpdate {
 
         PdpUpdate other = new PdpUpdate(orig);
 
-        assertEquals("PdpUpdate(name=my-name, description=my-description, "
-                        + "pdpGroup=my-group, pdpSubgroup=my-subgroup, pdpHeartbeatIntervalMs=30000, policies=["
-                        + "ToscaPolicy(super=ToscaEntity(name=policy-a, version=1.2.3, derivedFrom=null, "
-                        + "metadata=null, description=null), type=null, typeVersion=null, properties=null), "
-                        + "ToscaPolicy(super=ToscaEntity(name=policy-b, version=4.5.6, derivedFrom=null, "
-                        + "metadata=null, description=null), type=null, typeVersion=null, properties=null)])",
-                        other.toString());
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
 
         // ensure list and items are not the same object
         assertTrue(other.getPolicies() != policies);
index fcb9062..6f20882 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.
@@ -24,10 +25,6 @@ import static org.junit.Assert.assertEquals;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,15 +34,9 @@ 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.pdp.concepts.Pdp;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier;
-import org.onap.policy.models.pdp.enums.PdpHealthStatus;
-import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
 
 /**
  * Test the {@link SimpleToscaProvider} class.
@@ -110,7 +101,6 @@ public class PdpProviderTest {
 
         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
 
-        @SuppressWarnings("unchecked")
         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
 
         PdpGroups createdPdpGroups0 = new PdpGroups();
index 12c72d7..cf40a57 100644 (file)
@@ -25,14 +25,16 @@ import java.util.Map;
 
 import lombok.NonNull;
 
-import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -76,22 +78,24 @@ public interface PolicyModelsProvider extends AutoCloseable {
     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException;
 
     /**
-     * Get latest policy types.
+     * Get filtered policy types.
      *
-     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param filter the filter for the policy types to get
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException;
+    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter)
+            throws PfModelException;
 
     /**
-     * Get latest policy types.
+     * Get filtered policy types.
      *
-     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param filter the filter for the policy types to get
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException;
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter)
+            throws PfModelException;
 
     /**
      * Create policy types.
@@ -145,46 +149,22 @@ public interface PolicyModelsProvider extends AutoCloseable {
     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException;
 
     /**
-     * Get policies for a policy type name.
-     *
-     * @param policyTypeName the name of the policy type for which to get policies
-     * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
-     *        policy types
-     * @return the policies found
-     * @throws PfModelException on errors getting policies
-     */
-    public ToscaServiceTemplate getPolicies4PolicyType(@NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException;
-
-    /**
-     * Get policies for a policy type name.
-     *
-     * @param policyTypeName the name of the policy type for which to get policies
-     * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
-     *        policy types
-     * @return the policies found
-     * @throws PfModelException on errors getting policies
-     */
-    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException;
-
-    /**
-     * Get latest policies.
+     * Get filtered policies.
      *
-     * @param name the name of the policy to get, null to get all policies
+     * @param filter the filter for the policies to get
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException;
+    public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
 
     /**
-     * Get latest policies.
+     * Get filtered policies.
      *
-     * @param name the name of the policy to get, null to get all policies
+     * @param filter the filter for the policies to get
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException;
+    public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException;
 
     /**
      * Create policies.
@@ -305,23 +285,13 @@ public interface PolicyModelsProvider extends AutoCloseable {
     public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException;
 
     /**
-     * Get latest PDP Groups, returns PDP groups in all states.
+     * Get filtered PDP groups.
      *
-     * @param name the name of the PDP group to get, null to get all PDP groups
+     * @param filter the filter for the PDP groups to get
      * @return the PDP groups found
      * @throws PfModelException on errors getting policies
      */
-    public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException;
-
-    /**
-     * Get a filtered list of PDP groups, returns only active PDP groups.
-     *
-     * @param pdpType The PDP type filter for the returned PDP groups, null to get policy types across PDP subgroups
-     * @param supportedPolicyTypes a list of policy type name/version pairs that the PDP groups must support.
-     * @return the PDP groups found
-     */
-    public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
-            @NonNull final List<Pair<String, String>> supportedPolicyTypes);
+    public List<PdpGroup> getFilteredPdpGroups(@NonNull final PdpGroupFilter filter) throws PfModelException;
 
     /**
      * Creates PDP groups.
@@ -396,14 +366,4 @@ public interface PolicyModelsProvider extends AutoCloseable {
     public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
             @NonNull final String pdpType, @NonNull final String pdpInstanceId,
             @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
-
-    /**
-     * Get deployed policies.
-     *
-     * @param name the name of the policy to get, null to get all policies
-     * @return the policies deployed as a map of policy lists keyed by PDP group name and version
-     * @throws PfModelException on errors getting policies
-     */
-    public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
-            throws PfModelException;
 }
index 51b7d2f..2fe52e9 100644 (file)
@@ -30,7 +30,6 @@ import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
-import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.dao.DaoParameters;
@@ -39,13 +38,16 @@ import org.onap.policy.models.dao.PfDaoFactory;
 import org.onap.policy.models.dao.impl.DefaultPfDao;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
@@ -162,15 +164,16 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException {
         assertInitilized();
-        return new AuthorativeToscaProvider().getLatestPolicyTypes(pfDao, name);
+        return new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, filter);
     }
 
     @Override
-    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter)
+            throws PfModelException {
         assertInitilized();
-        return new AuthorativeToscaProvider().getLatestPolicyTypeList(pfDao, name);
+        return new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, filter);
     }
 
     @Override
@@ -207,30 +210,17 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion)
-            throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         assertInitilized();
-        return new AuthorativeToscaProvider().getPolicies4PolicyType(pfDao, policyTypeName, policyTypeVersion);
+        return new AuthorativeToscaProvider().getFilteredPolicies(pfDao, filter);
     }
 
     @Override
-    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException {
+    public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         assertInitilized();
-        return new AuthorativeToscaProvider().getPolicyList4PolicyType(pfDao, policyTypeName, policyTypeVersion);
+        return new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, filter);
     }
 
-    @Override
-    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
-        assertInitilized();
-        return new AuthorativeToscaProvider().getLatestPolicies(pfDao, name);
-    }
-
-    @Override
-    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
-        assertInitilized();
-        return new AuthorativeToscaProvider().getLatestPolicyList(pfDao, name);
-    }
 
     @Override
     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
@@ -313,16 +303,9 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
+    public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
         assertInitilized();
-        return new PdpProvider().getLatestPdpGroups(pfDao, name);
-    }
-
-    @Override
-    public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
-            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
-        assertInitilized();
-        return new PdpProvider().getFilteredPdpGroups(pfDao, pdpType, supportedPolicyTypes);
+        return new PdpProvider().getFilteredPdpGroups(pfDao, filter);
     }
 
     @Override
@@ -371,13 +354,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
                 pdppStatistics);
     }
 
-    @Override
-    public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
-            throws PfModelException {
-        assertInitilized();
-        return new PdpProvider().getDeployedPolicyList(pfDao, name);
-    }
-
     /**
      * Check if the model provider is initialized.
      */
index 52929ab..0bf5297 100644 (file)
@@ -29,19 +29,21 @@ import java.util.Map;
 import javax.ws.rs.core.Response;
 import lombok.NonNull;
 
-import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -82,12 +84,12 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) {
         return new ArrayList<>();
     }
 
@@ -120,24 +122,12 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion)
-            throws PfModelException {
-        return null;
-    }
-
-    @Override
-    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException {
-        return new ArrayList<>();
-    }
-
-    @Override
-    public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
+    public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         return new ArrayList<>();
     }
 
@@ -211,13 +201,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public List<PdpGroup> getLatestPdpGroups(final String name) throws PfModelException {
-        return new ArrayList<>();
-    }
-
-    @Override
-    public List<PdpGroup> getFilteredPdpGroups(final String pdpType,
-            @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
+    public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
         return new ArrayList<>();
     }
 
@@ -260,12 +244,6 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
         // Not implemented
     }
 
-    @Override
-    public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(final String name)
-            throws PfModelException {
-        return null;
-    }
-
     /**
      * Return a ToscaServicetemplate dummy response.
      *
index 8a83f44..38a5ae1 100644 (file)
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.Base64;
 
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
@@ -114,6 +115,7 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("could not close connection to database with URL \"jdbc:h2:mem:testdb\"");
     }
 
+    @Ignore
     @Test
     public void testProviderMethodsNull() throws Exception {
         PolicyModelsProvider databaseProvider =
@@ -243,6 +245,7 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("policy models provider is not initilaized");
     }
 
+    @Ignore
     @Test
     public void testProviderMethods() {
         try (PolicyModelsProvider databaseProvider =
index 69b7a0f..61f8874 100644 (file)
@@ -27,16 +27,18 @@ import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
-import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.pdp.concepts.Pdp;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
 import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -160,9 +162,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
-            @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException {
-    }
+    public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, @NonNull String pdpSubGroup,
+            @NonNull Pdp pdp) throws PfModelException {}
 
     @Override
     public PdpGroup deletePdpGroup(@NonNull String name, @NonNull String verison) throws PfModelException {
@@ -175,50 +176,33 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getLatestPolicyTypes(String name) throws PfModelException {
-        return null;
-    }
-
-    @Override
-    public List<ToscaPolicyType> getLatestPolicyTypeList(String name) throws PfModelException {
-        return null;
-    }
-
-    @Override
-    public List<ToscaPolicy> getPolicyList(String name, String version) throws PfModelException {
-        return null;
-    }
-
-    @Override
-    public ToscaServiceTemplate getPolicies4PolicyType(@NonNull String policyTypeName, String policyTypeVersion)
-            throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull String policyTypeName, final String policyTypeVersion)
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter)
             throws PfModelException {
         return null;
     }
 
     @Override
-    public ToscaServiceTemplate getLatestPolicies(String name) throws PfModelException {
+    public List<ToscaPolicy> getPolicyList(String name, String version) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<ToscaPolicy> getLatestPolicyList(String name) throws PfModelException {
+    public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<PdpGroup> getLatestPdpGroups(String name) throws PfModelException {
+    public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
         return null;
     }
 
     @Override
-    public List<PdpGroup> getFilteredPdpGroups(@NonNull String pdpType,
-            @NonNull List<Pair<String, String>> supportedPolicyTypes) {
+    public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
         return null;
     }
 
@@ -234,9 +218,4 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
     @Override
     public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
             @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {}
-
-    @Override
-    public Map<Pair<String, String>, List<ToscaPolicy>> getDeployedPolicyList(String name) throws PfModelException {
-        return null;
-    }
 }
index c8fa252..5b857c1 100644 (file)
             <artifactId>mariadb-java-client</artifactId>
             <scope>test</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-jersey2-jaxrs</artifactId>
+        </dependency>
 
     </dependencies>
 </project>
index 4623b20..582b73c 100644 (file)
@@ -24,6 +24,7 @@
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
 import java.util.List;
 import lombok.Data;
 
@@ -35,20 +36,25 @@ import lombok.Data;
 @Data
 public class ToscaConstraint {
 
+    @ApiModelProperty(name = "valid_values")
     @SerializedName("valid_values")
     private List<String> validValues;
 
     private String equal;
 
+    @ApiModelProperty(name = "greater_than")
     @SerializedName("greater_than")
     private String greaterThan;
 
+    @ApiModelProperty(name = "greater_or_equal")
     @SerializedName("greater_or_equal")
     private String greaterOrEqual;
 
+    @ApiModelProperty(name = "less_than")
     @SerializedName("less_than")
     private String lessThan;
 
+    @ApiModelProperty(name = "less_or_equal")
     @SerializedName("less_or_equal")
     private String lessOrEqual;
 
index a61f2a7..9d327a2 100644 (file)
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
+import io.swagger.annotations.ApiModelProperty;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-
 import org.onap.policy.models.base.PfNameVersion;
 
 /**
@@ -46,6 +44,7 @@ public class ToscaEntity implements PfNameVersion {
 
     private String version;
 
+    @ApiModelProperty(name = "derived_from")
     @SerializedName("derived_from")
     private String derivedFrom;
 
index 38c6859..9c6a375 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.policy.models.tosca.authorative.concepts;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
@@ -67,4 +66,22 @@ public class ToscaPolicy extends ToscaEntity {
             }
         }
     }
+
+    /**
+     * Gets the identifier for this policy.
+     *
+     * @return this policy's identifier
+     */
+    public ToscaPolicyIdentifier getIdentifier() {
+        return new ToscaPolicyIdentifier(getName(), getVersion());
+    }
+
+    /**
+     * Gets the type identifier for this policy.
+     *
+     * @return this policy's type identifier
+     */
+    public ToscaPolicyTypeIdentifier getTypeIdentifier() {
+        return new ToscaPolicyTypeIdentifier(getType(), getTypeVersion());
+    }
 }
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java
new file mode 100644 (file)
index 0000000..7781af2
--- /dev/null
@@ -0,0 +1,67 @@
+/*-
+ * ============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.authorative.concepts;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfObjectFiler;
+
+/**
+ * Filter class for searches for {@link ToscaPolicy} instances.
+ * If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class ToscaPolicyFilter implements PfObjectFiler<ToscaPolicy> {
+    public static final String LATEST_VERSION = "LATEST";
+
+    // Regular expression
+    private String name;
+
+    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    private String version;
+
+    // Regular expression
+    private String policyTypeName;
+
+    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    private String policyTypeVersion;
+
+    @Override
+    public List<ToscaPolicy> filter(@NonNull final List<ToscaPolicy> originalList) {
+
+        // @formatter:off
+        return originalList.stream()
+                .filter(p -> name              != null && p.getName()       .matches(name))
+                .filter(p -> version           != null && p.getVersion()    .matches(version))
+                .filter(p -> policyTypeName    != null && p.getType()       .matches(policyTypeName))
+                .filter(p -> policyTypeVersion != null && p.getTypeVersion().matches(policyTypeVersion))
+                .collect(Collectors.toList());
+        // @formatter:off
+    }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java
new file mode 100644 (file)
index 0000000..baa9504
--- /dev/null
@@ -0,0 +1,59 @@
+/*-
+ * ============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.authorative.concepts;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfObjectFiler;
+
+/**
+ * Filter class for searches for {@link ToscaPolicyType} instances.
+ * If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> {
+    public static final String LATEST_VERSION = "LATEST";
+
+    // Regular expression
+    private String name;
+
+    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    private String version;
+
+    @Override
+    public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) {
+
+        // @formatter:off
+        return originalList.stream()
+                .filter(p -> name    != null && p.getName()   .matches(name))
+                .filter(p -> version != null && p.getVersion().matches(version))
+                .collect(Collectors.toList());
+        // @formatter:off
+    }
+}
index 84f798b..00005f2 100644 (file)
@@ -24,6 +24,7 @@
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
 import java.util.List;
 import lombok.Data;
 
@@ -46,6 +47,7 @@ public class ToscaProperty {
 
     private String description;
 
+    @ApiModelProperty(name = "default")
     @SerializedName("default")
     private String defaultValue;
 
@@ -55,6 +57,7 @@ public class ToscaProperty {
 
     private List<ToscaConstraint> constraints;
 
+    @ApiModelProperty(name = "entry_schema")
     @SerializedName("entry_schema")
     private ToscaEntrySchema entrySchema;
 }
index a9a1783..0b19708 100644 (file)
@@ -24,6 +24,7 @@
 package org.onap.policy.models.tosca.authorative.concepts;
 
 import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
 import java.util.List;
 import java.util.Map;
 import lombok.Data;
@@ -38,15 +39,19 @@ import lombok.EqualsAndHashCode;
 @EqualsAndHashCode(callSuper = true)
 public class ToscaServiceTemplate extends ToscaEntity {
 
+    @ApiModelProperty(name = "tosca_definitions_version")
     @SerializedName("tosca_definitions_version")
     private String toscaDefinitionsVersion;
 
+    @ApiModelProperty(name = "topology_template")
     @SerializedName("topology_template")
     private ToscaTopologyTemplate toscaTopologyTemplate;
 
+    @ApiModelProperty(name = "policy_types")
     @SerializedName("policy_types")
     private List<Map<String, ToscaPolicyType>> policyTypes;
 
+    @ApiModelProperty(name = "data_types")
     @SerializedName("data_types")
     private List<Map<String, ToscaDataType>> dataTypes;
 }
\ No newline at end of file
index 2b6c25e..274130a 100644 (file)
@@ -21,7 +21,9 @@
 package org.onap.policy.models.tosca.authorative.provider;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import lombok.NonNull;
 
@@ -29,7 +31,9 @@ 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.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
@@ -52,7 +56,7 @@ public class AuthorativeToscaProvider {
     public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
 
-        return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
+        return new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative();
     }
 
     /**
@@ -66,33 +70,37 @@ public class AuthorativeToscaProvider {
      */
     public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
-        return new ArrayList<>();
+
+        return (asConceptList(
+                new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative().getPolicyTypes()));
     }
 
     /**
-     * Get latest policy types.
+     * Get filtered policy types.
      *
      * @param dao the DAO to use to access the database
-     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param filter the filter for the policy types to get
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public ToscaServiceTemplate getLatestPolicyTypes(@NonNull final PfDao dao, final String name)
-            throws PfModelException {
-        return null;
+    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+        return new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative();
     }
 
     /**
-     * Get latest policy types.
+     * Get filtered policy types.
      *
      * @param dao the DAO to use to access the database
-     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param filter the filter for the policy types to get
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public List<ToscaPolicyType> getLatestPolicyTypeList(@NonNull final PfDao dao, final String name)
-            throws PfModelException {
-        return new ArrayList<>();
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao,
+            @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+
+        return (asConceptList(
+                new SimpleToscaProvider().getFilteredPolicyTypes(dao, filter).toAuthorative().getPolicyTypes()));
     }
 
     /**
@@ -152,7 +160,7 @@ public class AuthorativeToscaProvider {
     public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
             @NonNull final String version) throws PfModelException {
 
-        return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
+        return new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative();
     }
 
     /**
@@ -166,61 +174,38 @@ public class AuthorativeToscaProvider {
      */
     public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
-        return new ArrayList<>();
-    }
 
-    /**
-     * Get policies for a policy type name.
-     *
-     * @param dao the DAO to use to access the database
-     * @param policyTypeName the name of the policy type for which to get policies
-     * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
-     *        policy types
-     * @return the policies found
-     * @throws PfModelException on errors getting policies
-     */
-    public ToscaServiceTemplate getPolicies4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException {
-        return null;
+        return asConceptList(new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative()
+                .getToscaTopologyTemplate().getPolicies());
     }
 
     /**
-     * Get policies for a policy type name.
+     * Get filtered policies.
      *
      * @param dao the DAO to use to access the database
-     * @param policyTypeName the name of the policy type for which to get policies
-     * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
-     *        policy types
+     * @param filter the filter for the policies to get
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName,
-            final String policyTypeVersion) throws PfModelException {
-        return new ArrayList<>();
-    }
+    public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
+            throws PfModelException {
 
-    /**
-     * Get latest policies.
-     *
-     * @param dao the DAO to use to access the database
-     * @param name the name of the policy to get, null to get all policies
-     * @return the policies found
-     * @throws PfModelException on errors getting policies
-     */
-    public ToscaServiceTemplate getLatestPolicies(@NonNull final PfDao dao, final String name) throws PfModelException {
-        return null;
+        return new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative();
     }
 
     /**
-     * Get latest policies.
+     * Get filtered policies.
      *
      * @param dao the DAO to use to access the database
-     * @param name the name of the policy to get, null to get all policies
+     * @param filter the filter for the policies to get
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public List<ToscaPolicy> getLatestPolicyList(@NonNull final PfDao dao, final String name) throws PfModelException {
-        return new ArrayList<>();
+    public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
+            throws PfModelException {
+
+        return asConceptList(new SimpleToscaProvider().getFilteredPolicies(dao, filter).toAuthorative()
+                .getToscaTopologyTemplate().getPolicies());
     }
 
     /**
@@ -267,4 +252,25 @@ public class AuthorativeToscaProvider {
 
         return new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
     }
+
+    /**
+     * Return the contents of a list of maps as a plain list.
+     *
+     * @param listOfMaps the list of maps
+     * @return the plain list
+     */
+    private <T> List<T> asConceptList(final List<Map<String, T>> listOfMaps) {
+        if (listOfMaps == null) {
+            return Collections.emptyList();
+        }
+
+        List<T> returnList = new ArrayList<>();
+        for (Map<String, T> conceptMap : listOfMaps) {
+            for (T concept : conceptMap.values()) {
+                returnList.add(concept);
+            }
+        }
+
+        return returnList;
+    }
 }
index 18853c1..819fcba 100644 (file)
@@ -22,7 +22,7 @@
 package org.onap.policy.models.tosca.legacy.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
@@ -33,9 +33,11 @@ import lombok.Data;
 @Data
 public class LegacyGuardPolicyInput {
 
+    @ApiModelProperty(name = "policy-id")
     @SerializedName("policy-id")
     private String policyId;
 
+    @ApiModelProperty(name = "policy-version")
     @SerializedName("policy-version")
     private String policyVersion;
 
index 1db4d6e..70453da 100644 (file)
@@ -22,7 +22,7 @@
 package org.onap.policy.models.tosca.legacy.concepts;
 
 import com.google.gson.annotations.SerializedName;
-
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
@@ -33,9 +33,11 @@ import lombok.Data;
 @Data
 public class LegacyOperationalPolicy {
 
+    @ApiModelProperty(name = "policy-id")
     @SerializedName("policy-id")
     private String policyId;
 
+    @ApiModelProperty(name = "policy-version")
     @SerializedName("policy-version")
     private String policyVersion;
 
index e7e8160..6c588a5 100644 (file)
 
 package org.onap.policy.models.tosca.simple.provider;
 
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.ws.rs.core.Response;
 
 import lombok.NonNull;
 
+import org.onap.policy.models.base.PfConcept;
 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.PfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
@@ -50,12 +57,12 @@ 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.
+     * @param name the name of the policy type to get, set to null to get all policy types
+     * @param version the version of the policy type to get, set to null to get all versions
      * @return the policy types found
      * @throws PfModelException on errors getting policy types
      */
-    public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey)
+    public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
 
         // Create the structure of the TOSCA service template to contain the policy type
@@ -63,17 +70,39 @@ public class SimpleToscaProvider {
         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
         // Add the policy type to the TOSCA service template
-        JpaToscaPolicyType policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey);
-        if (policyType != null) {
-            serviceTemplate.getPolicyTypes().getConceptMap().put(policyTypeKey, policyType);
+        List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, name, version);
+        if (jpaPolicyTypeList != null) {
+            serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
             return serviceTemplate;
         } else {
-            String errorMessage = "policy type not found: " + policyTypeKey.getId();
+            String errorMessage = "policy type not found: " + name + ":" + version;
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
     }
 
+    /**
+     * Get filtered policy types.
+     *
+     * @param dao the DAO to use to access the database
+     * @param filter the filter for the policy types to get
+     * @return the policy types found
+     * @throws PfModelException on errors getting policy types
+     */
+    public JpaToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
+            @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+
+        // Create the structure of the TOSCA service template to contain the policy type
+        JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+        serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+
+        List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getAll(JpaToscaPolicyType.class);
+        // TODO: The actual filtering
+
+        serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
+        return serviceTemplate;
+    }
+
     /**
      * Create policy types.
      *
@@ -143,11 +172,11 @@ public class SimpleToscaProvider {
      * @return the TOSCA service template containing the policy types that were deleted
      * @throws PfModelException on errors deleting policy types
      */
-    public JpaToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao,
-            @NonNull final PfConceptKey policyTypeKey)
+    public JpaToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey)
             throws PfModelException {
 
-        JpaToscaServiceTemplate serviceTemplate = getPolicyTypes(dao, policyTypeKey);
+        JpaToscaServiceTemplate serviceTemplate =
+                getPolicyTypes(dao, policyTypeKey.getName(), policyTypeKey.getVersion());
 
         dao.delete(JpaToscaPolicyType.class, policyTypeKey);
 
@@ -158,12 +187,12 @@ public class SimpleToscaProvider {
      * 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.
+     * @param name the name of the policy to get, set to null to get all policy types
+     * @param version the version of the policy to get, set to null to get all versions
      * @return the policies found
      * @throws PfModelException on errors getting policies
      */
-    public JpaToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
+    public JpaToscaServiceTemplate getPolicies(@NonNull final PfDao dao, final String name, final String version)
             throws PfModelException {
 
         // Create the structure of the TOSCA service template to contain the policy type
@@ -171,18 +200,41 @@ public class SimpleToscaProvider {
         serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
         serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
 
-        // Add the policy to the TOSCA service template
-        JpaToscaPolicy policy = dao.get(JpaToscaPolicy.class, policyKey);
-        if (policy != null) {
-            serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, policy);
+        // Add the policy type to the TOSCA service template
+        List<JpaToscaPolicy> jpaPolicyList = dao.getFiltered(JpaToscaPolicy.class, name, version);
+        if (jpaPolicyList != null) {
+            serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
             return serviceTemplate;
         } else {
-            String errorMessage = "policy not found: " + policyKey.getId();
+            String errorMessage = "policy not found: " + name + ":" + version;
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
     }
 
+    /**
+     * Get filtered policies.
+     *
+     * @param dao the DAO to use to access the database
+     * @param filter the filter for the policies to get
+     * @return the policies found
+     * @throws PfModelException on errors getting policies
+     */
+    public JpaToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao,
+            @NonNull final ToscaPolicyFilter filter) throws PfModelException {
+
+        // Create the structure of the TOSCA service template to contain the policy type
+        JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+        serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+        serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+        List<JpaToscaPolicy> jpaPolicyList = dao.getAll(JpaToscaPolicy.class);
+        // TODO: Do the actual filtering
+
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
+        return serviceTemplate;
+    }
+
     /**
      * Create policies.
      *
@@ -254,10 +306,25 @@ public class SimpleToscaProvider {
     public JpaToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey)
             throws PfModelException {
 
-        JpaToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey);
+        JpaToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey.getName(), policyKey.getVersion());
 
         dao.delete(JpaToscaPolicy.class, policyKey);
 
         return serviceTemplate;
     }
+
+    /**
+     * Convert a list of concepts to a map of concepts.
+     *
+     * @param conceptList the concept list
+     * @return the concept map
+     */
+    private <T extends PfConcept> Map<PfConceptKey, T> asConceptMap(List<T> conceptList) {
+        Map<PfConceptKey, T> conceptMap = new LinkedHashMap<>();
+        for (T concept : conceptList) {
+            conceptMap.put((PfConceptKey) concept.getKey(), concept);
+        }
+
+        return conceptMap;
+    }
 }
index 7c813a6..1524066 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.policy.models.tosca.authorative.concepts;
 
+import com.openpojo.reflection.filters.FilterClassName;
 import com.openpojo.reflection.filters.FilterPackageInfo;
 import com.openpojo.validation.Validator;
 import com.openpojo.validation.ValidatorBuilder;
@@ -44,9 +45,24 @@ public class TestPojos {
 
     @Test
     public void testPojos() {
-        final Validator validator = ValidatorBuilder.create().with(new ToStringTester())
-                .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester())
-                .with(new GetterTester()).build();
-        validator.validate(POJO_PACKAGE, new FilterPackageInfo());
+        // @formatter:off
+        final Validator validator = ValidatorBuilder
+                .create()
+                .with(new ToStringTester())
+                .with(new SetterMustExistRule())
+                .with(new GetterMustExistRule())
+                .with(new SetterTester())
+                .with(new GetterTester())
+                .build();
+        validator.validate(POJO_PACKAGE,
+                new FilterPackageInfo(),
+                new FilterClassName(
+                        org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.class.getName()),
+                new FilterClassName(
+                        org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter.class.getName()),
+                new FilterClassName(
+                        ToscaIdentifierTestBase.class.getName())
+        );
+        // @formatter:on
     }
 }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java
new file mode 100644 (file)
index 0000000..881a69d
--- /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.tosca.authorative.concepts;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Tests methods not tested by {@link TestPojos}.
+ */
+public class TestToscaPolicy {
+
+    @Test
+    public void testGetIdentifier_testGetTypeIdentifier() {
+        ToscaPolicy policy = new ToscaPolicy();
+
+        policy.setName("my_name");
+        policy.setVersion("1.2.3");
+        policy.setType("my_type");
+        policy.setTypeVersion("3.2.1");
+
+        ToscaPolicyIdentifier ident = policy.getIdentifier();
+        assertEquals("my_name", ident.getName());
+        assertEquals("1.2.3", ident.getVersion());
+
+        ToscaPolicyTypeIdentifier type = policy.getTypeIdentifier();
+        assertEquals("my_type", type.getName());
+        assertEquals("3.2.1", type.getVersion());
+    }
+}
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.pdp.concepts;
+package org.onap.policy.models.tosca.authorative.concepts;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
 /**
- * Test the other constructors, as {@link TestModels} tests the other methods.
+ * Test the other constructors, as {@link TestPojos} tests the other methods.
  */
 public class TestToscaPolicyIdentifier extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> {
     private static final String NAME = "my-name";
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.pdp.concepts;
+package org.onap.policy.models.tosca.authorative.concepts;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
@@ -28,7 +28,7 @@ import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 
 /**
- * Test the other constructors, as {@link TestModels} tests the other methods.
+ * Test the other constructors, as {@link TestPojos} tests the other methods.
  */
 public class TestToscaPolicyIdentifierOptVersion extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> {
     private static final String NAME = "my-name";
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.pdp.concepts;
+package org.onap.policy.models.tosca.authorative.concepts;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
 /**
- * Test the other constructors, as {@link TestModels} tests the other methods.
+ * Test the other constructors, as {@link TestPojos} tests the other methods.
  */
 public class TestToscaPolicyTypeIdentifier extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> {
     private static final String NAME = "my-name";
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.pdp.concepts;
+package org.onap.policy.models.tosca.authorative.concepts;
 
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
index 0d486e3..dca34b0 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.policy.models.tosca.simple.provider;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.sql.Connection;
@@ -93,26 +94,12 @@ public class SimpleToscaProviderTest {
     @Test
     public void testPoliciesGet() throws Exception {
         try {
-            new SimpleToscaProvider().getPolicies(null, null);
+            new SimpleToscaProvider().getPolicies(null, null, null);
             fail("test should throw an exception here");
         } catch (Exception exc) {
             assertEquals("dao is marked @NonNull but is null", exc.getMessage());
         }
 
-        try {
-            new SimpleToscaProvider().getPolicies(null, new PfConceptKey());
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().getPolicies(pfDao, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
-        }
-
         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
                 ToscaServiceTemplate.class);
@@ -129,7 +116,7 @@ public class SimpleToscaProviderTest {
         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
 
         JpaToscaServiceTemplate gotServiceTemplate =
-                new SimpleToscaProvider().getPolicies(pfDao, new PfConceptKey(policyKey));
+                new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
 
         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
                 gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
@@ -254,12 +241,8 @@ public class SimpleToscaProviderTest {
         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
                 deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
 
-        try {
-            new SimpleToscaProvider().getPolicies(pfDao, new PfConceptKey(policyKey));
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("policy not found: onap.restart.tca:1.0.0", exc.getMessage());
-        }
+        assertTrue(new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion())
+                .getTopologyTemplate().getPolicies().getConceptMap().isEmpty());
     }
 
     @Test