From 3d79660270cc259688e0ba20150286c1680c7559 Mon Sep 17 00:00:00 2001 From: imamSidero Date: Mon, 24 Oct 2022 17:20:46 +0100 Subject: Add default baseType to the substitution type Enabling default baseType in substitution type to be selected Issue-ID: SDC-4229 Signed-off-by: Imam hussain Change-Id: I869ede4c4e030adc3c4418c28ed787b4c10248dd --- .../sdc/be/components/impl/ElementBusinessLogic.java | 10 ++++++++++ .../org/openecomp/sdc/be/servlets/ElementServlet.java | 1 + .../java/org/openecomp/sdc/ElementOperationMock.java | 5 +++++ .../sdc/be/model/operations/api/IElementOperation.java | 2 ++ .../sdc/be/model/operations/impl/ElementOperation.java | 12 ++++++++++++ catalog-ui/src/app/models/base-types.ts | 1 + .../workspace/tabs/general/general-view-model.ts | 16 +++++++++++----- .../openecomp/sdc/be/config/CategoryBaseTypeConfig.java | 1 + 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java index caea46aae8..176cdedc35 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java @@ -1303,4 +1303,14 @@ public class ElementBusinessLogic extends BaseBusinessLogic { public boolean isBaseTypeRequired(final String categoryName) { return elementOperation.isBaseTypeRequired(categoryName); } + + /** + * Fetches default baseType from the template. + * + * @param categoryName the category name + * @return defaultBaseType mapped to the corresponding category name. + */ + public String getDefaultBaseType(final String categoryName) { + return elementOperation.getDefaultBaseType(categoryName); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java index e949b13d1c..5e4085cf33 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java @@ -217,6 +217,7 @@ public class ElementServlet extends BeGenericServlet { final Map baseTypesMap = new HashMap<>(); baseTypesMap.put("baseTypes", either.left().value()); baseTypesMap.put("required", elementBL.isBaseTypeRequired(categoryName)); + baseTypesMap.put("defaultBaseType",elementBL.getDefaultBaseType(categoryName)); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), baseTypesMap); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java index 1416707835..d9e6e8ec0d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java @@ -292,4 +292,9 @@ public class ElementOperationMock implements IElementOperation { return true; } + @Override + public String getDefaultBaseType(String categoryName) { + return ""; + } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java index ebc563268e..e942ee1fde 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java @@ -96,6 +96,8 @@ public interface IElementOperation { */ boolean isBaseTypeRequired(String categoryName); + String getDefaultBaseType(String categoryName); + Either getCategory(NodeTypeEnum nodeType, String categoryId); Either getSubCategoryUniqueForType(NodeTypeEnum nodeType, String normalizedName); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java index 127d778f73..bf74a264f8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java @@ -426,6 +426,18 @@ public class ElementOperation implements IElementOperation { private Configuration getConfiguration() { return ConfigurationManager.getConfigurationManager().getConfiguration(); } + @Override + public String getDefaultBaseType(final String categoryName) { + final Map categoriesSpecificBaseTypeMap = getConfiguration().getServiceBaseNodeTypes(); + if (MapUtils.isEmpty(categoriesSpecificBaseTypeMap)) { + return null; + } + final CategoryBaseTypeConfig categoryBaseTypeConfig = categoriesSpecificBaseTypeMap.get(categoryName); + if (categoryBaseTypeConfig == null) { + return null; + } + return categoryBaseTypeConfig.getDefaultBaseType(); + } @Override public boolean isBaseTypeRequired(final String categoryName) { diff --git a/catalog-ui/src/app/models/base-types.ts b/catalog-ui/src/app/models/base-types.ts index 526355e0f8..69aafa357c 100644 --- a/catalog-ui/src/app/models/base-types.ts +++ b/catalog-ui/src/app/models/base-types.ts @@ -21,6 +21,7 @@ interface ListBaseTypesResponse { baseTypes: BaseTypeResponse[]; required: boolean; + defaultBaseType: string; } interface BaseTypeResponse { diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index 77c93301b2..2d029cd332 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -910,13 +910,19 @@ export class GeneralViewModel { this.$scope.isBaseTypeRequired = baseTypeResponseList.required; this.$scope.baseTypes = []; this.$scope.baseTypeVersions = []; + let defaultBaseType = baseTypeResponseList.defaultBaseType; baseTypeResponseList.baseTypes.forEach(baseType => this.$scope.baseTypes.push(baseType.toscaResourceName)); - if (this.$scope.isBaseTypeRequired) { - const baseType = baseTypeResponseList.baseTypes[0]; - baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); - if(!this.$scope.component.derivedFromGenericType) { - this.$scope.component.derivedFromGenericType = baseType.toscaResourceName; + if (this.$scope.isBaseTypeRequired || defaultBaseType != null) { + let baseType = baseTypeResponseList.baseTypes[0]; + if(defaultBaseType != null){ + baseTypeResponseList.baseTypes.forEach(baseTypeObj => { + if(baseTypeObj.toscaResourceName == defaultBaseType) { + baseType = baseTypeObj; + } + }); } + baseType.versions.reverse().forEach(version => this.$scope.baseTypeVersions.push(version)); + this.$scope.component.derivedFromGenericType = baseType.toscaResourceName; this.$scope.component.derivedFromGenericVersion = this.$scope.baseTypeVersions[0]; this.$scope.showBaseTypeVersions = true; return diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/CategoryBaseTypeConfig.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/CategoryBaseTypeConfig.java index 5885455779..17f3a8cf73 100644 --- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/CategoryBaseTypeConfig.java +++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/CategoryBaseTypeConfig.java @@ -33,5 +33,6 @@ public class CategoryBaseTypeConfig { private boolean required; private List baseTypes; + private String defaultBaseType; } -- cgit 1.2.3-korg