aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstasys10 <stasys.jurgaitis@est.tech>2021-11-29 19:52:58 +0000
committerAndr� Schmid <andre.schmid@est.tech>2022-01-27 16:59:25 +0000
commit9bd18657d2048d3396d15a394b4493b283c47e4d (patch)
treee4bd0deef57d238fab57621a1b9382d9cbb5c031
parentc2fa1b7e8d43a236219d1f6ad2831de1af296cb4 (diff)
Add a display name for the category
Issue-ID: SDC-3858 Change-Id: Ic818b3b4bc4f4e91c9da0cdacb40549a3f071c68 Signed-off-by: stasys10 <stasys.jurgaitis@est.tech>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java1
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java50
-rw-r--r--catalog-be/src/test/resources/types/categoryTypes.yml10
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java1
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/category/CategoryData.java2
-rw-r--r--catalog-ui/src/app/models/category.ts1
-rw-r--r--catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts4
-rw-r--r--catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html2
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinition.java2
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinitionTest.java44
10 files changed, 96 insertions, 21 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
index 2b8b8df7ec..39ff0017ab 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
@@ -228,6 +228,7 @@ public class CategoriesImportManager {
Map<String, Object> category = (Map<String, Object>) entry.getValue();
catName = (String) category.get("name");
catDef.setName(catName);
+ catDef.setDisplayName((String) category.get("displayName"));
icons = (List<String>) category.get("icons");
catDef.setIcons(icons);
String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(catName);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
index f7d0709307..c3975b9f89 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/CategoriesImportManagerTest.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@@ -32,15 +33,16 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -48,14 +50,14 @@ import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.exception.ResponseFormat;
-public class CategoriesImportManagerTest {
+class CategoriesImportManagerTest {
@InjectMocks
static CategoriesImportManager importManager = new CategoriesImportManager();
public static final IElementOperation elementOperation = Mockito.mock(IElementOperation.class);
public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
private static SubCategoryDefinition subcategory;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws IOException {
subcategory = new SubCategoryDefinition();
subcategory.setUniqueId("123");
@@ -78,13 +80,13 @@ public class CategoriesImportManagerTest {
// when(Mockito.any(SubCategoryDefinition.class).getUniqueId()).thenReturn("123");
}
- @Before
+ @BeforeEach
public void initMocks() {
MockitoAnnotations.openMocks(this);
}
@Test
- public void importCategoriesTest() throws IOException {
+ void importCategoriesTest() throws IOException {
String ymlContent = getYmlContent();
Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
@@ -104,6 +106,40 @@ public class CategoriesImportManagerTest {
assertFalse(categoryWithServiceSubstitutionFalse.get().isUseServiceSubstitutionForNestedServices());
}
+ @Test
+ void categoriesNameAndDisplayNameTest() throws IOException {
+ final String categoryName = "Category With DisplayName And metadata";
+ final String expectedCategoryDisplayName = "Display Name For Category";
+ final String ymlContent = getYmlContent();
+ final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
+ final Map<String, List<CategoryDefinition>> categories = createCapabilityTypes.left().value();
+
+ final Optional<CategoryDefinition> categoryWithNameAndDisplayName = categories.get("services").stream().filter(category -> category.getName().equals(categoryName)).findAny();
+ final String categoryDisplayName = categoryWithNameAndDisplayName.get().getDisplayName();
+
+ assertTrue(categoryWithNameAndDisplayName.isPresent());
+ assertEquals(expectedCategoryDisplayName, categoryDisplayName);
+ }
+
+ @Test
+ void getMetadataKeysTest() throws IOException {
+ final String categoryName = "Category With DisplayName And metadata";
+ final String expectedMetadataName = "ETSI Version";
+ final String expectedEtsiVersion = "2.5.1";
+ final String ymlContent = getYmlContent();
+ final Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
+ final Map<String, List<CategoryDefinition>> categories = createCapabilityTypes.left().value();
+
+ final Optional<CategoryDefinition> categoryWithMetadata = categories.get("services").stream().filter(category -> category.getName().equals(categoryName)).findAny();
+ final List<MetadataKeyDataDefinition> categoryMetadataList = categoryWithMetadata.get().getMetadataKeys();
+ final MetadataKeyDataDefinition categoryMetadata = categoryMetadataList.get(0);
+
+ assertEquals(expectedMetadataName, categoryMetadata.getName());
+ assertEquals(expectedEtsiVersion, categoryMetadata.getValidValues().get(0));
+ assertEquals(expectedEtsiVersion, categoryMetadata.getDefaultValue());
+ assertTrue(categoryMetadata.isMandatory());
+ }
+
private String getYmlContent() throws IOException {
Path filePath = Paths.get("src/test/resources/types/categoryTypes.yml");
byte[] fileContent = Files.readAllBytes(filePath);
diff --git a/catalog-be/src/test/resources/types/categoryTypes.yml b/catalog-be/src/test/resources/types/categoryTypes.yml
index 36268b1fff..293b16062e 100644
--- a/catalog-be/src/test/resources/types/categoryTypes.yml
+++ b/catalog-be/src/test/resources/types/categoryTypes.yml
@@ -19,6 +19,16 @@ services:
name: "Category With Service Substitution False"
icons: ['network_l_4']
useServiceSubstitutionForNestedServices: false
+ Category_With_DisplayName_And_metadata:
+ name: "Category With DisplayName And metadata"
+ displayName: "Display Name For Category"
+ icons: [ 'etsi_nfv_network_service' ]
+ metadataKeys:
+ etsiVersion:
+ name: "ETSI Version"
+ validValues: [ '2.5.1' ]
+ default: '2.5.1'
+ mandatory: true
resources:
NetworkLayer23:
name: "Network Layer 2-3"
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
index 145bcbdbc0..c689298fc1 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
@@ -33,6 +33,7 @@ public enum GraphPropertiesDictionary {
HEALTH_CHECK ("healthcheckis", String.class, true, true),
// Resource
NAME ("name", String.class, false, true),
+ DISPLAY_NAME ("displayName", String.class, false, true),
TOSCA_RESOURCE_NAME ("toscaResourceName", String.class, false, true),
CATEGORY_NAME ("categoryName", String.class, false, true),
VERSION ("version", String.class, false, true),
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/category/CategoryData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/category/CategoryData.java
index 665e5c737d..cd585ab4c4 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/category/CategoryData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/category/CategoryData.java
@@ -48,6 +48,7 @@ public class CategoryData extends GraphNode {
this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
categoryDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
categoryDataDefinition.setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
+ categoryDataDefinition.setDisplayName((String) properties.get(GraphPropertiesDictionary.DISPLAY_NAME.getProperty()));
categoryDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
final Object useServiceSubstitutionForNestedServicesProperty = properties
.get(GraphPropertiesDictionary.USE_SERVICE_SUBSTITUTION_FOR_NESTED_SERVICES.getProperty());
@@ -80,6 +81,7 @@ public class CategoryData extends GraphNode {
Map<String, Object> map = new HashMap<>();
addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, categoryDataDefinition.getUniqueId());
addIfExists(map, GraphPropertiesDictionary.NAME, categoryDataDefinition.getName());
+ addIfExists(map, GraphPropertiesDictionary.DISPLAY_NAME, categoryDataDefinition.getDisplayName());
addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, categoryDataDefinition.getNormalizedName());
addIfExists(map, GraphPropertiesDictionary.MODEL, categoryDataDefinition.getModels());
addIfExists(map, GraphPropertiesDictionary.ICONS, categoryDataDefinition.getIcons());
diff --git a/catalog-ui/src/app/models/category.ts b/catalog-ui/src/app/models/category.ts
index 502020a57b..a6445cafdd 100644
--- a/catalog-ui/src/app/models/category.ts
+++ b/catalog-ui/src/app/models/category.ts
@@ -25,6 +25,7 @@
export interface ICategoryBase {
//server properties
name:string;
+ displayName:string;
normalizedName:string;
uniqueId:string;
models:Array<string>;
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 a707e563af..043f4dd859 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
@@ -767,6 +767,10 @@ export class GeneralViewModel {
}
};
+ this.$scope.getCategoryDisplayNameOrName = (mainCategory: any): string => {
+ return mainCategory.displayName ? mainCategory.displayName : mainCategory.name ;
+ }
+
this.$scope.onBaseTypeChange = (): void => {
if (!this.$scope.component.derivedFromGenericType) {
this.$scope.component.derivedFromGenericVersion = undefined;
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
index bb0cceb173..1fb8d5f10f 100644
--- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
+++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view.html
@@ -119,7 +119,7 @@
<option ng-if="component.isService()" data-ng-repeat="mainCategory in categories | orderBy:['name']"
data-ng-selected="component.selectedCategory===mainCategory.name"
value="{{mainCategory.name}}"
- data-tests-id="{{mainCategory.name}}">{{mainCategory.name}}</option>
+ data-tests-id="{{mainCategory.name}}">{{getCategoryDisplayNameOrName(mainCategory)}}</option>
</select>
<div class="input-error" data-ng-show="validateField(editForm.category)">
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinition.java
index 2a9b2e88a2..76768811f0 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinition.java
@@ -35,6 +35,7 @@ import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
public class CategoryDataDefinition extends ToscaDataDefinition {
private String name;
+ private String displayName;
private String normalizedName;
private List<String> models;
private String uniqueId;
@@ -44,6 +45,7 @@ public class CategoryDataDefinition extends ToscaDataDefinition {
public CategoryDataDefinition(CategoryDataDefinition c) {
this.name = c.name;
+ this.displayName = c.displayName;
this.normalizedName = c.normalizedName;
this.models = c.models;
this.uniqueId = c.uniqueId;
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinitionTest.java
index 2cb0261a67..0060133ac4 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/category/CategoryDataDefinitionTest.java
@@ -20,23 +20,41 @@
package org.openecomp.sdc.be.datatypes.category;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+class CategoryDataDefinitionTest {
-public class CategoryDataDefinitionTest {
-
- private CategoryDataDefinition createTestSubject() {
- return new CategoryDataDefinition();
- }
-
@Test
- public void testCopyConstructor() throws Exception {
- CategoryDataDefinition testSubject;
+ void testCategoryDataDefinition() {
+ CategoryDataDefinition categoryDataDefinitionForTest = new CategoryDataDefinition();
+ categoryDataDefinitionForTest.setName("Category name");
+ categoryDataDefinitionForTest.setDisplayName("Category displayName");
+ categoryDataDefinitionForTest.setNormalizedName("Category normalizedName");
+ List modelsList = new ArrayList();
+ modelsList.add("Category models list item");
+ categoryDataDefinitionForTest.setModels(modelsList);
+ categoryDataDefinitionForTest.setUniqueId("Category uniqueId");
+ List iconList = new ArrayList();
+ iconList.add("Category icon list item");
+ categoryDataDefinitionForTest.setIcons(iconList);
+ categoryDataDefinitionForTest.setUseServiceSubstitutionForNestedServices(true);
+ List metadataKeysList = new ArrayList();
+ metadataKeysList.add("Category metadataKeys list item");
+ categoryDataDefinitionForTest.setMetadataKeys(metadataKeysList);
+
+ CategoryDataDefinition categoryDataDefinitionActual = new CategoryDataDefinition(categoryDataDefinitionForTest);
- // default test
- testSubject = createTestSubject();
- CategoryDataDefinition categoryDataDefinition = new CategoryDataDefinition(testSubject);
+ assertEquals(categoryDataDefinitionForTest.getName(), categoryDataDefinitionActual.getName());
+ assertEquals(categoryDataDefinitionForTest.getDisplayName(), categoryDataDefinitionActual.getDisplayName());
+ assertEquals(categoryDataDefinitionForTest.getNormalizedName(), categoryDataDefinitionActual.getNormalizedName());
+ assertEquals(categoryDataDefinitionForTest.getModels(), categoryDataDefinitionActual.getModels());
+ assertEquals(categoryDataDefinitionForTest.getUniqueId(), categoryDataDefinitionActual.getUniqueId());
+ assertEquals(categoryDataDefinitionForTest.getIcons(), categoryDataDefinitionActual.getIcons());
+ assertEquals(categoryDataDefinitionForTest.isUseServiceSubstitutionForNestedServices(), categoryDataDefinitionActual.isUseServiceSubstitutionForNestedServices());
+ assertEquals(categoryDataDefinitionForTest.getMetadataKeys(), categoryDataDefinitionActual.getMetadataKeys());
}
-
}