Fix: Listing archived catalog resources fails randomly
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsonjanusgraph / operations / ToscaElementOperation.java
index 884f040..0bc8450 100644 (file)
@@ -37,12 +37,13 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
-import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty;
 import org.janusgraph.core.JanusGraphVertex;
 import org.openecomp.sdc.be.config.ConfigurationManager;
 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -73,13 +74,16 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
 import org.openecomp.sdc.be.utils.TypeUtils;
 import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
 import org.openecomp.sdc.common.log.wrappers.Logger;
 import org.openecomp.sdc.common.util.ValidationUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -95,6 +99,8 @@ public abstract class ToscaElementOperation extends BaseOperation {
     private static Logger log = Logger.getLogger(ToscaElementOperation.class.getName());
     @Autowired
     protected CategoryOperation categoryOperation;
+    @Autowired
+    protected ModelOperation modelOperation;
 
     public static DataTypeDefinition createDataType(final String dataTypeName) {
         final DataTypeDefinition dataType = new DataTypeDefinition();
@@ -146,6 +152,17 @@ public abstract class ToscaElementOperation extends BaseOperation {
         return Either.left(vertexG);
     }
 
+    protected GraphVertex getHighestVersionFrom(GraphVertex v) {
+        Either<GraphVertex, JanusGraphOperationStatus> childVertexE = janusGraphDao
+            .getChildVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+        GraphVertex highestVersionVertex = v;
+        while (childVertexE.isLeft()) {
+            highestVersionVertex = childVertexE.left().value();
+            childVertexE = janusGraphDao.getChildVertex(highestVersionVertex, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+        }
+        return highestVersionVertex;
+    }
+
     public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
         return getToscaElement(uniqueId, new ComponentParametersView());
     }
@@ -201,6 +218,12 @@ public abstract class ToscaElementOperation extends BaseOperation {
                 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
             }
         }
+        if (result == null) {
+            result =
+                VertexTypeEnum.TOPOLOGY_TEMPLATE.equals(previousToscaElement.getLabel())
+                    ? createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex, EdgeLabelEnum.MODEL)
+                    : createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex, EdgeLabelEnum.MODEL_ELEMENT);
+        }
         if (result == null) {
             status = janusGraphDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
             if (status != JanusGraphOperationStatus.OK) {
@@ -256,6 +279,37 @@ public abstract class ToscaElementOperation extends BaseOperation {
         return result;
     }
 
+    /**
+     * Creates the MODEL in case it exits on the previous version
+     *
+     * @param previousToscaElement      previous element version
+     * @param nextToscaElement          latest element version
+     * @param user                      user
+     * @param createdToscaElementVertex created tosca element
+     * @param edgeLabelEnum
+     * @return
+     */
+    private Either<GraphVertex, StorageOperationStatus> createModelEdge(final GraphVertex previousToscaElement,
+                                                                        final GraphVertex nextToscaElement, GraphVertex user,
+                                                                        final GraphVertex createdToscaElementVertex,
+                                                                        final EdgeLabelEnum edgeLabelEnum) {
+        Either<GraphVertex, StorageOperationStatus> result = null;
+        final Either<GraphVertex, JanusGraphOperationStatus> modelElementVertexResponse = janusGraphDao
+            .getParentVertex(previousToscaElement, edgeLabelEnum, JsonParseFlagEnum.NoParse);
+        if (modelElementVertexResponse.isLeft()) {
+            final JanusGraphOperationStatus status = janusGraphDao
+                .createEdge(modelElementVertexResponse.left().value().getVertex(), createdToscaElementVertex.getVertex(), edgeLabelEnum,
+                    new HashMap<>());
+            if (JanusGraphOperationStatus.OK != status) {
+                CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+                    FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, edgeLabelEnum,
+                    user.getUniqueId(), nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+                result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+            }
+        }
+        return result;
+    }
+
     protected JanusGraphOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
         Either<GraphVertex, JanusGraphOperationStatus> parentVertex = janusGraphDao
             .getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
@@ -339,6 +393,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_ARCHIVED));
         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.ARCHIVE_TIME, toscaElement.getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
         nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.IS_VSP_ARCHIVED, toscaElement.getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED));
+        nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.MODEL, toscaElement.getMetadataValue(JsonPresentationFields.MODEL));
         toscaElement.getMetadata().entrySet().stream().filter(e -> e.getValue() != null)
             .forEach(e -> nodeTypeVertex.setJsonMetadataField(e.getKey(), e.getValue()));
         nodeTypeVertex.setUniqueId(toscaElement.getUniqueId());
@@ -420,6 +475,30 @@ public abstract class ToscaElementOperation extends BaseOperation {
         return StorageOperationStatus.OK;
     }
 
+    protected StorageOperationStatus associateComponentToModel(final GraphVertex nodeTypeVertex, final ToscaElement nodeType,
+                                                               final EdgeLabelEnum edgeLabelEnum) {
+        Object metadataValue = nodeType.getMetadataValue(JsonPresentationFields.MODEL);
+        if (metadataValue == null || StringUtils.isEmpty((String) metadataValue)) {
+            return StorageOperationStatus.OK;
+        }
+        final String model = ((String) metadataValue);
+        final JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(getModelVertex(model), nodeTypeVertex, edgeLabelEnum, new HashMap<>());
+        if (createEdge != JanusGraphOperationStatus.OK) {
+            log.trace("Failed to associate resource {} to model {}", nodeType.getUniqueId(), model);
+            return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
+        }
+        return StorageOperationStatus.OK;
+    }
+
+    private GraphVertex getModelVertex(final String modelName) {
+        log.debug("getModelVertex: fetching model {}", modelName);
+        final Optional<GraphVertex> modelVertexByNameOptional = modelOperation.findModelVertexByName(modelName);
+        if (modelVertexByNameOptional.isEmpty()) {
+            throw ModelOperationExceptionSupplier.invalidModel(modelName).get();
+        }
+        return modelVertexByNameOptional.get();
+    }
+
     protected Either<GraphVertex, StorageOperationStatus> getResourceCategoryVertex(String elementId, String subcategoryName, String categoryName) {
         Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
         if (category.isRight()) {
@@ -946,8 +1025,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
     protected JanusGraphOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
         List<CategoryDefinition> categories = new ArrayList<>();
         SubCategoryDefinition subcategory;
-        Either<Vertex, JanusGraphOperationStatus> childVertex = janusGraphDao
-            .getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+        Either<Vertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY);
         if (childVertex.isRight()) {
             log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(),
                 childVertex.right().value());
@@ -966,8 +1044,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
             .fromJson((String) subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeSubcat)
             : Collections.emptyList();
         subcategory.setMetadataKeys(metadataKeys);
-        Either<Vertex, JanusGraphOperationStatus> parentVertex = janusGraphDao
-            .getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
+        Either<Vertex, JanusGraphOperationStatus> parentVertex = janusGraphDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY);
         Vertex categoryV = parentVertex.left().value();
         String categoryNormalizedName = (String) categoryV.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value();
         catalogComponent.setCategoryNormalizedName(categoryNormalizedName);
@@ -983,8 +1060,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
 
     protected JanusGraphOperationStatus setServiceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
         List<CategoryDefinition> categories = new ArrayList<>();
-        Either<Vertex, JanusGraphOperationStatus> childVertex = janusGraphDao
-            .getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
+        Either<Vertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY);
         if (childVertex.isRight()) {
             log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(),
                 childVertex.right().value());
@@ -996,6 +1072,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<List<String>>() {
+            }.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));
@@ -1004,6 +1083,10 @@ public abstract class ToscaElementOperation extends BaseOperation {
         List<MetadataKeyDataDefinition> metadataKeys = categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson()
             .fromJson((String) categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeCat) : Collections.emptyList();
         category.setMetadataKeys(metadataKeys);
+        VertexProperty<Object> property = categoryV.property(GraphPropertyEnum.NOT_APPLICABLE_METADATA_KEYS.getProperty());
+        category.setNotApplicableMetadataKeys(
+            property.isPresent() ? getGson().fromJson((String) property.value(), new TypeToken<List<String>>() {
+            }.getType()) : Collections.emptyList());
         categories.add(category);
         catalogComponent.setCategories(categories);
         return JanusGraphOperationStatus.OK;
@@ -1165,9 +1248,13 @@ public abstract class ToscaElementOperation extends BaseOperation {
     }
 
     private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) {
-        Map<String, Object> getConfig = (Map<String, Object>) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts()
-            .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny().get().getValue();
-        artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName"));
+        Optional<Entry<String, Object>> oConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts()
+            .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny();
+        if (oConfig.isPresent()) {
+            artifactInfo.setArtifactName(componentType + "-" + componentName + ((Map<String, Object>) oConfig.get().getValue()).get("artifactName"));
+        } else {
+            artifactInfo.setArtifactName(componentType + "-" + componentName);
+        }
     }
 
     protected <T extends ToscaElement> StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) {
@@ -1255,13 +1342,19 @@ public abstract class ToscaElementOperation extends BaseOperation {
         StopWatch stopWatch = new StopWatch();
         stopWatch.start();
         Map<String, CatalogComponent> existInCatalog = new HashMap<>();
-        Either<Iterator<Vertex>, JanusGraphOperationStatus> verticesEither = janusGraphDao.getCatalogOrArchiveVerticies(isCatalog);
+        Either<Iterator<Vertex>, JanusGraphOperationStatus> verticesEither = janusGraphDao.getCatalogOrArchiveVertices(isCatalog);
         if (verticesEither.isRight()) {
             return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(verticesEither.right().value()));
         }
         Iterator<Vertex> vertices = verticesEither.left().value();
         while (vertices.hasNext()) {
-            handleCatalogComponent(existInCatalog, vertices.next(), excludeTypes);
+            Vertex vertex = vertices.next();
+            VertexProperty<?> vertexProperty = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
+            if(!(vertexProperty instanceof EmptyVertexProperty)) {
+                handleCatalogComponent(existInCatalog, vertex, excludeTypes);
+            } else {
+                logVertex(vertex);
+            }
         }
         stopWatch.stop();
         String timeToFetchElements = stopWatch.prettyPrint();
@@ -1269,67 +1362,81 @@ public abstract class ToscaElementOperation extends BaseOperation {
         return Either.left(existInCatalog.values().stream().collect(Collectors.toList()));
     }
 
+    private void logVertex(Vertex vertex) {
+        StringBuilder sb = new StringBuilder();
+        vertex.keys().forEach(key -> {
+            Object value = vertex.property(key);
+            sb.append("[").append(key).append(": ").append(value).append("] ");
+        });
+        log.warn(EcompLoggerErrorCode.DATA_ERROR, "catalog-model", "Vertex has no metadata property: ", sb.toString());
+    }
+
     private void handleCatalogComponent(Map<String, CatalogComponent> existInCatalog, Vertex vertex, List<ResourceTypeEnum> excludeTypes) {
         VertexProperty<Object> property = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
         String json = (String) property.value();
         Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
         String uniqueId = (String) metadatObj.get(JsonPresentationFields.UNIQUE_ID.getPresentation());
         Boolean isDeleted = (Boolean) metadatObj.get(JsonPresentationFields.IS_DELETED.getPresentation());
-        if (isAddToCatalog(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) {
-            CatalogComponent catalogComponent = new CatalogComponent();
-            catalogComponent.setUniqueId(uniqueId);
-            catalogComponent
-                .setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation())));
-            catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation()));
-            catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
-            catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
-            catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
-            Object lastUpdateDate = metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation());
-            catalogComponent.setLastUpdateDate((lastUpdateDate != null ? (Long) lastUpdateDate : 0L));
-            catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation()));
-            catalogComponent.setDescription((String) metadatObj.get(JsonPresentationFields.DESCRIPTION.getPresentation()));
-            catalogComponent.setSystemName((String) metadatObj.get(JsonPresentationFields.SYSTEM_NAME.getPresentation()));
-            catalogComponent.setUuid((String) metadatObj.get(JsonPresentationFields.UUID.getPresentation()));
-            catalogComponent.setInvariantUUID((String) metadatObj.get(JsonPresentationFields.INVARIANT_UUID.getPresentation()));
-            catalogComponent.setIsHighestVersion((Boolean) metadatObj.get(JsonPresentationFields.HIGHEST_VERSION.getPresentation()));
-            Iterator<Edge> edges = vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name());
-            if (edges.hasNext()) {
-                catalogComponent
-                    .setLastUpdaterUserId((String) edges.next().outVertex().property(GraphPropertiesDictionary.USERID.getProperty()).value());
-            }
-            Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
-            if (resourceType != null) {
-                catalogComponent.setResourceType((String) resourceType);
-            }
-            if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
-                setServiceCategoryFromGraphV(vertex, catalogComponent);
-            } else {
-                setResourceCategoryFromGraphV(vertex, catalogComponent);
-            }
-            List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
-            if (tags != null) {
-                catalogComponent.setTags(tags);
-            }
+        if (isNotExcluded(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) {
+            CatalogComponent catalogComponent = createCatalogComponent(vertex, metadatObj, uniqueId);
             existInCatalog.put(uniqueId, catalogComponent);
         }
     }
 
-    private boolean isAddToCatalog(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
+    private CatalogComponent createCatalogComponent(Vertex vertex, Map<String, Object> metadatObj, String uniqueId) {
+        CatalogComponent catalogComponent = new CatalogComponent();
+        catalogComponent.setUniqueId(uniqueId);
+        catalogComponent.setModel((String) metadatObj.get(JsonPresentationFields.MODEL.getPresentation()));
+        catalogComponent
+            .setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation())));
+        catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation()));
+        catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
+        catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
+        catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
+        Object lastUpdateDate = metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation());
+        catalogComponent.setLastUpdateDate((lastUpdateDate != null ? (Long) lastUpdateDate : 0L));
+        catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation()));
+        catalogComponent.setDescription((String) metadatObj.get(JsonPresentationFields.DESCRIPTION.getPresentation()));
+        catalogComponent.setTenant((String) metadatObj.get(JsonPresentationFields.TENANT.getPresentation()));
+        catalogComponent.setSystemName((String) metadatObj.get(JsonPresentationFields.SYSTEM_NAME.getPresentation()));
+        catalogComponent.setUuid((String) metadatObj.get(JsonPresentationFields.UUID.getPresentation()));
+        catalogComponent.setInvariantUUID((String) metadatObj.get(JsonPresentationFields.INVARIANT_UUID.getPresentation()));
+        catalogComponent.setIsHighestVersion((Boolean) metadatObj.get(JsonPresentationFields.HIGHEST_VERSION.getPresentation()));
+        Iterator<Edge> edges = vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name());
+        if (edges.hasNext()) {
+            catalogComponent
+                .setLastUpdaterUserId((String) edges.next().outVertex().property(GraphPropertiesDictionary.USERID.getProperty()).value());
+        }
+        Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
+        if (resourceType != null) {
+            catalogComponent.setResourceType((String) resourceType);
+        }
+        if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
+            setServiceCategoryFromGraphV(vertex, catalogComponent);
+        } else {
+            setResourceCategoryFromGraphV(vertex, catalogComponent);
+        }
+        List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
+        if (tags != null) {
+            catalogComponent.setTags(tags);
+        }
+        return catalogComponent;
+    }
+
+    private boolean isNotExcluded(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
         boolean isAddToCatalog = true;
         Object resourceTypeStr = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
-        if (resourceTypeStr != null) {
+        if (resourceTypeStr != null && excludeTypes != null) {
             ResourceTypeEnum resourceType = ResourceTypeEnum.getType((String) resourceTypeStr);
-            if (!CollectionUtils.isEmpty(excludeTypes)) {
-                Optional<ResourceTypeEnum> op = excludeTypes.stream().filter(rt -> rt == resourceType).findAny();
-                if (op.isPresent()) {
-                    isAddToCatalog = false;
-                }
-            }
+            return !excludeTypes.stream()
+                .filter(type -> type == resourceType)
+                .findAny()
+                .isPresent();
         }
         return isAddToCatalog;
     }
 
-    public Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType,
+    private Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType,
                                                                                            List<ResourceTypeEnum> excludeTypes,
                                                                                            JsonParseFlagEnum parseFlag) {
         Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
@@ -1346,7 +1453,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
     }
 
     // highest + (certified && !highest)
-    public Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType,
+    private Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType,
                                                                                                           List<ResourceTypeEnum> excludeTypes) {
         long startFetchAllStates = System.currentTimeMillis();
         Either<List<GraphVertex>, JanusGraphOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes,