Add BARE and REFERENCED mode to policy fetches
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / provider / PolicyProvider.java
index 35d0e80..4ba3322 100644 (file)
@@ -23,6 +23,7 @@
 \r
 package org.onap.policy.api.main.rest.provider;\r
 \r
+import org.onap.policy.api.main.rest.PolicyFetchMode;\r
 import org.onap.policy.models.base.PfModelException;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
@@ -48,15 +49,16 @@ public class PolicyProvider extends CommonModelProvider {
      * @param policyTypeVersion the version of policy type\r
      * @param policyId the ID of policy\r
      * @param policyVersion the version of policy\r
+     * @param mode the fetch mode for policies\r
      *\r
      * @return the ToscaServiceTemplate object\r
      *\r
      * @throws PfModelException the PfModel parsing exception\r
      */\r
-    public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion, String policyId,\r
-            String policyVersion) throws PfModelException {\r
+    public ToscaServiceTemplate fetchPolicies(final String policyTypeId, final String policyTypeVersion,\r
+        final String policyId, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {\r
 \r
-        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
+        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
     }\r
 \r
     /**\r
@@ -65,15 +67,15 @@ public class PolicyProvider extends CommonModelProvider {
      * @param policyTypeId the ID of policy type\r
      * @param policyTypeVersion the version of policy type\r
      * @param policyId the ID of the policy\r
-     *\r
+     * @param mode the fetch mode for policies\r
      * @return the ToscaServiceTemplate object\r
      *\r
      * @throws PfModelException the PfModel parsing exception\r
      */\r
-    public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion, String policyId)\r
-            throws PfModelException {\r
+    public ToscaServiceTemplate fetchLatestPolicies(final String policyTypeId, final String policyTypeVersion,\r
+        final String policyId, final PolicyFetchMode mode) throws PfModelException {\r
 \r
-        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);\r
+        return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION, mode);\r
     }\r
 \r
     /**\r
@@ -88,7 +90,7 @@ public class PolicyProvider extends CommonModelProvider {
      * @throws PfModelException the PfModel parsing exception\r
      */\r
     public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion, ToscaServiceTemplate body)\r
-            throws PfModelException {\r
+        throws PfModelException {\r
 \r
         return modelsProvider.createPolicies(body);\r
     }\r
@@ -119,7 +121,7 @@ public class PolicyProvider extends CommonModelProvider {
      * @throws PfModelException the PfModel parsing exception\r
      */\r
     public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion, String policyId,\r
-            String policyVersion) throws PfModelException {\r
+        String policyVersion) throws PfModelException {\r
 \r
         return modelsProvider.deletePolicy(policyId, policyVersion);\r
     }\r
@@ -131,16 +133,25 @@ public class PolicyProvider extends CommonModelProvider {
      * @param policyTypeVersion the version of the policy type\r
      * @param policyName the name of the policy\r
      * @param policyVersion the version of the policy\r
+     * @param mode the fetch mode for policies\r
      *\r
      * @return the TOSCA service template containing the specified version of the policy\r
      *\r
      * @throws PfModelException the PfModel parsing exception\r
      */\r
-    private ToscaServiceTemplate getFilteredPolicies(String policyTypeName, String policyTypeVersion, String policyName,\r
-            String policyVersion) throws PfModelException {\r
+    private ToscaServiceTemplate getFilteredPolicies(final String policyTypeName, final String policyTypeVersion,\r
+        final String policyName, final String policyVersion, final PolicyFetchMode mode) throws PfModelException {\r
 \r
         ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder().name(policyName).version(policyVersion)\r
-                .type(policyTypeName).typeVersion(policyTypeVersion).build();\r
-        return modelsProvider.getFilteredPolicies(policyFilter);\r
+            .type(policyTypeName).typeVersion(policyTypeVersion).build();\r
+\r
+        ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);\r
+\r
+        if (mode == null || PolicyFetchMode.BARE.equals(mode)) {\r
+            serviceTemplate.setPolicyTypes(null);\r
+            serviceTemplate.setDataTypes(null);\r
+        }\r
+\r
+        return serviceTemplate;\r
     }\r
 }\r