From 6ecc7c3e150f86528d36cdbaa94912b965619a70 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Mon, 30 Aug 2021 15:18:40 +0100 Subject: Filter categories by model name Issue-ID: SDC-3706 Signed-off-by: aribeiro Change-Id: I457151f09ce0ed2edfa09340e9e08a126e114002 --- .../operations/TopologyTemplateOperation.java | 4 ++- .../operations/ToscaElementOperation.java | 3 ++ .../impl/ToscaElementLifecycleOperationTest.java | 37 ++++++++++++++-------- .../operations/impl/util/OperationTestsUtil.java | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java index 61b11b3168..b45dae9c68 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java @@ -609,7 +609,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation { private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) { String categoryName = topologyTemplate.getCategories().get(0).getName(); - Either category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY); + Either category = categoryOperation.getCategory(categoryName, + VertexTypeEnum.SERVICE_CATEGORY); if (category.isRight()) { log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId()); return StorageOperationStatus.CATEGORY_NOT_FOUND; @@ -1176,6 +1177,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation { }.getType(); List iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat); category.setIcons(iconsfromJsonCat); + category.setModels((getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.MODEL.getProperty()), listTypeCat))); final Type metadataKeysTypeCat = new TypeToken>() { }.getType(); final List metadataKeysfromJsonCat = getGson() diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java index 1037935ab5..2ff3b49a00 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java @@ -1060,6 +1060,9 @@ public abstract class ToscaElementOperation extends BaseOperation { CategoryDefinition category = new CategoryDefinition(); category.setUniqueId((String) categoryV.property(GraphPropertyEnum.UNIQUE_ID.getProperty()).value()); category.setNormalizedName(categoryNormalizedName); + category.setModels(categoryV.property(GraphPropertyEnum.MODEL.getProperty()).isPresent() ? getGson() + .fromJson((String) categoryV.property(GraphPropertyEnum.MODEL.getProperty()).value(), new TypeToken>() { + }.getType()) : Collections.emptyList()); category.setName((String) categoryV.property(GraphPropertyEnum.NAME.getProperty()).value()); category.setUseServiceSubstitutionForNestedServices( (Boolean) categoryV.property(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES.getProperty()).orElse(false)); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java index b4f61563c1..4817f7a1c4 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java @@ -20,16 +20,33 @@ package org.openecomp.sdc.be.model.operations.impl; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import fj.data.Either; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import org.apache.tinkerpop.gremlin.structure.io.IoCore; -import org.junit.*; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestName; import org.junit.runner.RunWith; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; @@ -60,16 +77,6 @@ import org.openecomp.sdc.common.util.ValidationUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") public class ToscaElementLifecycleOperationTest extends ModelTestBase { @@ -304,6 +311,7 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { metadataProperties.put(GraphPropertyEnum.NAME, categoryName); metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]"); + metadataProperties.put(GraphPropertyEnum.MODEL, "[]"); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); @@ -340,6 +348,7 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { metadataProperties.put(GraphPropertyEnum.NAME, categoryName); metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]"); + metadataProperties.put(GraphPropertyEnum.MODEL, "[]"); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/util/OperationTestsUtil.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/util/OperationTestsUtil.java index 71dc5d9517..597ac1065f 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/util/OperationTestsUtil.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/util/OperationTestsUtil.java @@ -42,7 +42,7 @@ public class OperationTestsUtil { categoryData.getCategoryDataDefinition() .setNormalizedName(ValidationUtils.normalizeCategoryName4Uniqueness(category)); categoryData.getCategoryDataDefinition().setUniqueId(UniqueIdBuilder.buildCategoryUid( - ValidationUtils.normalizeCategoryName4Uniqueness(category), NodeTypeEnum.ServiceNewCategory)); + ValidationUtils.normalizeCategoryName4Uniqueness(category), NodeTypeEnum.ServiceNewCategory)); janusGraphDao.deleteNode(categoryData, CategoryData.class); Either createNode = janusGraphDao.createNode(categoryData, CategoryData.class); return (String) createNode.left().value().getUniqueId(); -- cgit 1.2.3-korg