+ /**
+ * Check if node templates have been specified correctly.
+ */
+ public static String checkNodeTemplateExist(final JpaToscaServiceTemplate serviceTemplate) {
+ if (serviceTemplate.getTopologyTemplate().getNodeTemplates() == null) {
+ return "node templates not present on the service template";
+ }
+
+ if (serviceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().isEmpty()) {
+ return "no parameters present on the node templates";
+ }
+ return null;
+ }
+
+ /**
+ * getLatestPolicyTypeVersion Find all the ancestors of an entity type.
+ *
+ * @param entityTypes the set of entity types that exist
+ * @param entityType the entity type for which to get the parents
+ * @param result the result of the ancestor search with any warnings or errors
+ * @return the entity set containing the ancestors of the incoming entity
+ */
+ public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors(
+ @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ @NonNull JpaToscaEntityType<?> entityType, @NonNull final BeanValidationResult result) {
+
+ PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom();
+ if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) {
+ return CollectionUtils.emptyCollection();
+ }
+
+ if (entityType.getKey().equals(parentEntityTypeKey)) {
+ result.addResult("entity type", entityType.getKey().getId(),
+ ValidationStatus.INVALID, "ancestor of itself");
+ throw new PfModelRuntimeException(Response.Status.CONFLICT, result.getResult());
+ }
+
+ @SuppressWarnings("unchecked")
+ Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes
+ .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
+ Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet);
+ if (ancestorEntitySet.isEmpty()) {
+ result.addResult("parent", parentEntityTypeKey.getId(), ValidationStatus.INVALID, Validated.NOT_FOUND);
+ } else {
+ for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) {
+ ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result));
+ }
+ }
+ return ancestorEntitySetToReturn;
+ }
+
+ /**
+ * Get the entity tree from a concept container for a given entity key.
+ *
+ * @param entityTypes the concept container containing entity types
+ * @param entityName the name of the entity
+ * @param entityVersion the version of the entity
+ */
+ public static void getEntityTree(
+ @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ final String entityName, final String entityVersion) {
+
+ var result = new BeanValidationResult("entity", entityName);
+
+ @SuppressWarnings("unchecked")
+ Set<JpaToscaEntityType<?>> filteredEntitySet =
+ (Set<JpaToscaEntityType<?>>) entityTypes.getAllNamesAndVersions(entityName, entityVersion);
+ Set<JpaToscaEntityType<?>> filteredEntitySetToReturn = new HashSet<>(filteredEntitySet);
+ for (JpaToscaEntityType<?> filteredEntityType : filteredEntitySet) {
+ filteredEntitySetToReturn
+ .addAll(ToscaUtils.getEntityTypeAncestors(entityTypes, filteredEntityType, result));
+ }
+
+ if (!result.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.getResult());
+ }
+
+ entityTypes.getConceptMap().entrySet()
+ .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));