Include custom data types from VSP in csar imports
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / operations / impl / ModelOperation.java
index d522e10..87ab3fc 100644 (file)
@@ -176,6 +176,25 @@ public class ModelOperation {
         toscaModelImportCassandraDao.importAll(modelId, toscaImportByModelList);
     }
 
+    /**
+     * Find all the model default imports, with the option to include the default imports from the parent model.
+     *
+     * @param modelId       the model id
+     * @param includeParent a flag to include the parent model imports.
+     * @return the list of model default imports, or an empty list if no imports were found.
+     */
+    public List<ToscaImportByModel> findAllModelImports(final String modelId, final boolean includeParent) {
+        final List<ToscaImportByModel> toscaImportByModelList = toscaModelImportCassandraDao.findAllByModel(modelId);
+        if (includeParent) {
+            findModelByName(modelId).ifPresent(model -> {
+                if (model.getDerivedFrom() != null) {
+                    toscaImportByModelList.addAll(toscaModelImportCassandraDao.findAllByModel(model.getDerivedFrom()));
+                }
+            });
+        }
+        return toscaImportByModelList;
+    }
+
     /**
      * Finds all the models.
      *