- /**\r
- * Validates whether specified policy type can be deleted based on the rule that policy type parameterized by at\r
- * least one policies cannot be deleted.\r
- *\r
- * @param policyTypeId the ID of policy type\r
- * @param policyTypeVersion the version of policy type\r
- *\r
- * @throws PfModelException the PfModel parsing exception\r
- */\r
- private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion) throws PfModelException {\r
-\r
- ToscaPolicyFilter policyFilter =\r
- ToscaPolicyFilter.builder().type(policyTypeId).typeVersion(policyTypeVersion).build();\r
- List<ToscaPolicy> policies = modelsProvider.getFilteredPolicyList(policyFilter);\r
- if (!policies.isEmpty()) {\r
- throw new PfModelException(Response.Status.CONFLICT,\r
- constructDeletePolicyTypeViolationMessage(policyTypeId, policyTypeVersion, policies));\r
- }\r
- }\r
-\r
- /**\r
- * Validates that each policy type has a version specified in the payload.\r
- *\r
- * @param body the TOSCA service template payload to check against\r
- *\r
- * @throws PfModelException the PfModel parsing exception\r
- */\r
- private void validatePolicyTypeVersionExist(ToscaServiceTemplate body) throws PfModelException {\r
-\r
- List<String> invalidPolicyTypeNames = new ArrayList<>();\r
- for (Entry<String, ToscaPolicyType> policyType : body.getPolicyTypes().entrySet()) {\r
- if (!"tosca.policies.Root".equals(policyType.getValue().getDerivedFrom())\r
- && policyType.getValue().getVersion() == null) {\r
- invalidPolicyTypeNames.add(policyType.getKey());\r
- }\r
- }\r
-\r
- if (!invalidPolicyTypeNames.isEmpty()) {\r
- String errorMsg = "mandatory 'version' field is missing in policy types: "\r
- + String.join(", ", invalidPolicyTypeNames);\r
- throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMsg);\r
- }\r
- }\r
-\r