+
+ /**
+ * Validate that all data types referenced in policy types exist.
+ *
+ * @param result the validation result object to use for the validation result
+ * @return the validation result object
+ */
+ private PfValidationResult validateReferencedDataTypes(final PfValidationResult result) {
+ if (policyTypes == null) {
+ return result;
+ }
+
+ if (dataTypes != null) {
+ for (JpaToscaDataType dataType : dataTypes.getAll(null)) {
+ validateReferencedDataTypesExists(dataType.getKey(), dataType.getReferencedDataTypes(), result);
+ }
+ }
+
+ for (JpaToscaPolicyType policyType : policyTypes.getAll(null)) {
+ validateReferencedDataTypesExists(policyType.getKey(), policyType.getReferencedDataTypes(), result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate that the referenced data types exist for a collection of data type keys.
+ *
+ * @param referencingEntityKey the key of the referencing entity
+ * @param dataTypeKeyCollection the data type key collection
+ * @param result the result of the validation
+ */
+ private void validateReferencedDataTypesExists(final PfConceptKey referencingEntityKey,
+ final Collection<PfConceptKey> dataTypeKeyCollection, final PfValidationResult result) {
+ for (PfConceptKey dataTypeKey : dataTypeKeyCollection) {
+ if (dataTypes == null || dataTypes.get(dataTypeKey) == null) {
+ result.addValidationMessage(new PfValidationMessage(referencingEntityKey, this.getClass(),
+ ValidationResult.INVALID, "referenced data type " + dataTypeKey.getId() + " not found"));
+ }
+ }
+ }
+
+ /**
+ * Validate that all policy types referenced in policies exist.
+ *
+ * @param result the validation result object to use for the validation result
+ * @return the validation result object
+ */
+ private PfValidationResult validatePolicyTypesInPolicies(PfValidationResult result) {
+ if (topologyTemplate == null || topologyTemplate.getPolicies() == null
+ || topologyTemplate.getPolicies().getConceptMap().isEmpty()) {
+ return result;
+ }
+
+ if (policyTypes == null || policyTypes.getConceptMap().isEmpty()) {
+ result.addValidationMessage(new PfValidationMessage(this.getKey(), this.getClass(),
+ ValidationResult.INVALID,
+ "no policy types are defined on the service template for the policies in the topology template"));
+ return result;
+ }
+
+ for (JpaToscaPolicy policy : topologyTemplate.getPolicies().getAll(null)) {
+ if (policyTypes.get(policy.getType()) == null) {
+ result.addValidationMessage(
+ new PfValidationMessage(policy.getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy type " + policy.getType().getId() + " referenced in policy not found"));
+ }
+ }
+
+ return result;
+ }