- /**\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
- protected boolean hasPolicy(ToscaServiceTemplate serviceTemplate) {\r
-\r
- return hasData(serviceTemplate.getToscaTopologyTemplate().getPolicies());\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
- protected boolean hasPolicyType(ToscaServiceTemplate serviceTemplate) {\r
-\r
- return hasData(serviceTemplate.getPolicyTypes());\r
- }\r
-\r
- /**\r
- * Checks if the first element of a list of maps contains data.\r
- *\r
- * @param listOfMapsToCheck list of maps to be examined\r
- * @return {@code true} if the list contains data, {@code false} otherwise\r
- */\r
- protected <T> boolean hasData(List<Map<String, T>> listOfMapsToCheck) {\r
-\r
- return (listOfMapsToCheck != null && !listOfMapsToCheck.isEmpty() && !listOfMapsToCheck.get(0).isEmpty());\r
- }\r
-\r
-\r
- /**\r
- * Checks if a maps contains data.\r
- *\r
- * @param mapToCheck map to be examined\r
- * @return {@code true} if the list contains data, {@code false} otherwise\r
- */\r
- protected <T> boolean hasData(Map<String, T> mapToCheck) {\r
-\r
- // We don't allow a null or empty map as well as a map entry with a valid key but null value\r
- return (mapToCheck != null && !mapToCheck.isEmpty() && !mapToCheck.containsValue(null));\r
- }\r
-\r
- /**\r
- * Validates that some text represents a number.\r
- *\r
- * @param text text to be validated\r
- * @param errorMsg error message included in the exception, if the text is not a valid\r
- * number\r
- * @throws PfModelException if the text is not a valid number\r
- */\r
- protected void validNumber(String text, String errorMsg) throws PfModelException {\r
- try {\r
- Integer.parseInt(text);\r
-\r
- } catch (NumberFormatException exc) {\r
- throw new PfModelException(Response.Status.BAD_REQUEST, errorMsg, exc);\r
- }\r
- }\r
-\r
- /**\r
- * Constructs returned message for policy delete rule violation.\r
- *\r
- * @param policyId the ID of policy\r
- * @param policyVersion the version of policy\r
- * @param pdpGroups the list of pdp groups\r
- *\r
- * @return the constructed message\r
- */\r
- protected String constructDeletePolicyViolationMessage(String policyId, String policyVersion,\r
- List<PdpGroup> pdpGroups) {\r
-\r
- List<String> pdpGroupNameVersionList = new ArrayList<>(pdpGroups.size());\r
- for (PdpGroup pdpGroup : pdpGroups) {\r
- pdpGroupNameVersionList.add(pdpGroup.getName() + ":" + pdpGroup.getVersion());\r
- }\r
- String deployedPdpGroups = String.join(",", pdpGroupNameVersionList);\r
- return "policy with ID " + policyId + ":" + policyVersion\r
- + " cannot be deleted as it is deployed in pdp groups " + deployedPdpGroups;\r
- }\r
-\r
- /**\r
- * Constructs returned message for policy type delete rule violation.\r
- *\r
- * @param policyTypeId the ID of policy type\r
- * @param policyTypeVersion the version of policy type\r
- * @param policies the list of policies that parameterizes specified policy type\r
- *\r
- * @return the constructed message\r
- */\r
- protected String constructDeletePolicyTypeViolationMessage(String policyTypeId, String policyTypeVersion,\r
- List<ToscaPolicy> policies) {\r
-\r
- List<String> policyNameVersionList = new ArrayList<>(policies.size());\r
- for (ToscaPolicy policy : policies) {\r
- policyNameVersionList.add(policy.getName() + ":" + policy.getVersion());\r
- }\r
- String parameterizedPolicies = String.join(",", policyNameVersionList);\r
- return "policy type with ID " + policyTypeId + ":" + policyTypeVersion\r
- + " cannot be deleted as it is parameterized by policies " + parameterizedPolicies;\r
- }\r
-\r