+ private Map<Pair<String, String>, List<ToscaPolicy>> constructDeployedPolicyMap(\r
+ List<PdpGroup> pdpGroups, String policyId) throws PfModelException {\r
+\r
+ Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicyMap = new HashMap<>();\r
+ for (PdpGroup pdpGroup : pdpGroups) {\r
+ List<ToscaPolicyIdentifier> policyIdentifiers = new ArrayList<>();\r
+ for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {\r
+ for (ToscaPolicyIdentifier policyIdentifier : pdpSubGroup.getPolicies()) {\r
+ if (policyId.equalsIgnoreCase(policyIdentifier.getName())) {\r
+ policyIdentifiers.add(policyIdentifier);\r
+ }\r
+ }\r
+ }\r
+ List<ToscaPolicy> deployedPolicies = new ArrayList<>();\r
+ if (!policyIdentifiers.isEmpty()) {\r
+ for (ToscaPolicyIdentifier policyIdentifier : policyIdentifiers) {\r
+ deployedPolicies.addAll(\r
+ modelsProvider.getPolicyList(policyIdentifier.getName(), policyIdentifier.getVersion()));\r
+ }\r
+ }\r
+ if (!deployedPolicies.isEmpty()) {\r
+ deployedPolicyMap.put(Pair.of(pdpGroup.getName(), pdpGroup.getVersion()), deployedPolicies);\r
+ }\r
+ }\r
+ return deployedPolicyMap;\r
+ }\r
+\r
+ /**\r
+ * Constructs returned message for not found resource.\r
+ *\r
+ * @param policyTypeId the ID of policy type\r
+ * @param policyTypeVersion the version of policy type\r
+ * @param policyId the ID of policy\r
+ * @param policyVersion the version of policy\r
+ *\r
+ * @return constructed message\r
+ */\r
+ private String constructResourceNotFoundMessage(String policyTypeId, String policyTypeVersion,\r
+ String policyId, String policyVersion) {\r
+\r
+ return "policy with ID " + policyId + ":" + policyVersion\r
+ + " and type " + policyTypeId + ":" + policyTypeVersion + " does not exist";\r
+ }\r
+\r
+ /**\r
+ * Constructs returned message for not found policy deployment.\r
+ *\r
+ * @param policyTypeId the ID of policy type\r
+ * @param policyTypeVersion the version of policy type\r
+ * @param policyId the ID of policy\r
+ * @param policyVersion the version of policy\r
+ *\r
+ * @return constructed message\r
+ */\r
+ private String constructDeploymentNotFoundMessage(String policyTypeId, String policyTypeVersion,\r
+ String policyId) {\r
+\r
+ return "could not find policy with ID " + policyId + " and type "\r
+ + policyTypeId + ":" + policyTypeVersion + " deployed in any pdp group";\r
+ }\r
+\r
+ /**\r
+ * Checks if service template contains any policy.\r
+ *\r
+ * @param serviceTemplate the service template to check against\r
+ *\r
+ * @return boolean whether service template contains any policy\r
+ */\r
+ private boolean hasPolicy(ToscaServiceTemplate serviceTemplate) {\r
+\r
+ if (serviceTemplate.getToscaTopologyTemplate().getPolicies() == null) {\r
+ return false;\r
+ } else if (serviceTemplate.getToscaTopologyTemplate().getPolicies().isEmpty()) {\r
+ return false;\r
+ } else if (serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty()) {\r
+ return false;\r
+ } else {\r
+ return true;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Checks if service template contains any policy type.\r
+ *\r
+ * @param serviceTemplate the service template to check against\r
+ *\r
+ * @return boolean whether service template contains any policy type\r
+ */\r
+ private boolean hasPolicyType(ToscaServiceTemplate serviceTemplate) {\r
+\r
+ if (serviceTemplate.getPolicyTypes() == null) {\r
+ return false;\r
+ } else if (serviceTemplate.getPolicyTypes().isEmpty()) {\r
+ return false;\r
+ } else if (serviceTemplate.getPolicyTypes().get(0).isEmpty()) {\r
+ return false;\r
+ } else {\r
+ return true;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Closes the connection to database.\r
+ *\r
+ * @throws PfModelException the PfModel parsing exception\r
+ */\r
+ @Override\r
+ public void close() throws PfModelException {\r
+\r
+ modelsProvider.close();\r