summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java58
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java21
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java63
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java3
5 files changed, 148 insertions, 1 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java
new file mode 100644
index 0000000000..5c88101b2f
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model;
+
+import com.vdurmont.semver4j.Semver;
+import com.vdurmont.semver4j.Semver.SemverType;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+
+
+public class BaseType {
+ @Getter
+ @Setter
+ private String toscaResourceName;
+
+ private List<Semver> versions = new ArrayList<>();
+
+ public BaseType(final String toscaResourceName) {
+ this.toscaResourceName = toscaResourceName;
+ }
+
+ public BaseType(final String toscaResourceName, final List<String> versions) {
+ this.toscaResourceName = toscaResourceName;
+ versions.forEach(version -> this.versions.add(new Semver(version, SemverType.LOOSE)));
+ }
+
+ public void addVersion(final String version) {
+ versions.add(new Semver(version, SemverType.LOOSE));
+ }
+
+ public List<String> getVersions(){
+ Collections.sort(versions);
+ final List<String> versionsAsStrings = new ArrayList<>();
+ this.versions.forEach(version -> versionsAsStrings.add(version.getValue()));
+ return versionsAsStrings;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 3858912660..06e23f04ea 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -445,6 +445,27 @@ public class ToscaOperationFacade {
});
}
+ public <T extends Component> Either<T, StorageOperationStatus> getByToscaResourceNameAndVersion(final String toscaResourceName, final String version) {
+ Either<T, StorageOperationStatus> result;
+
+ Map<GraphPropertyEnum, Object> hasProperties = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> hasNotProperties = new EnumMap<>(GraphPropertyEnum.class);
+
+ hasProperties.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ hasProperties.put(GraphPropertyEnum.VERSION, version);
+ hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, JanusGraphOperationStatus> getResourceRes = janusGraphDao
+ .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll);
+ if (getResourceRes.isRight()) {
+ JanusGraphOperationStatus status = getResourceRes.right().value();
+ log.debug("failed to find resource with toscaResourceName {}, version {}. Status is {} ", toscaResourceName, version, status);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ return result;
+ }
+ return getToscaElementByOperation(getResourceRes.left().value().get(0));
+ }
+
private Map<String, Entry<JanusGraphPredicate, Object>> getVendorVersionPredicate(final String vendorRelease) {
Map<String, Entry<JanusGraphPredicate, Object>> predicateCriteria = new HashMap<>();
if (!"1.0".equals(vendorRelease)) {
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 b3f1306a04..aac14625c5 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
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.operations.api;
import fj.data.Either;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.openecomp.sdc.be.config.Configuration;
@@ -27,6 +28,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.PropertyScope;
import org.openecomp.sdc.be.model.Tag;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -83,6 +85,8 @@ public interface IElementOperation {
boolean inTransaction);
Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction);
+
+ List<BaseType> getBaseTypes(String categoryName);
Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId);
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 60ffa1b0f7..054788a519 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
@@ -21,8 +21,10 @@ package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -40,14 +42,22 @@ import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.HealingJanusGraphDao;
+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;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.category.CategoryDataDefinition;
import org.openecomp.sdc.be.datatypes.category.GroupingDataDefinition;
import org.openecomp.sdc.be.datatypes.category.SubCategoryDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PropertyScope;
import org.openecomp.sdc.be.model.Tag;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -71,10 +81,12 @@ public class ElementOperation implements IElementOperation {
private static final String UNKNOWN_CATEGORY_TYPE = "Unknown category type {}";
private static final Logger log = Logger.getLogger(ElementOperation.class.getName());
private JanusGraphGenericDao janusGraphGenericDao;
+ private HealingJanusGraphDao janusGraphDao;
- public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao) {
+ public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao, @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) {
super();
this.janusGraphGenericDao = janusGraphGenericDao;
+ this.janusGraphDao = janusGraphDao;
}
private static NodeTypeEnum getChildNodeType(NodeTypeEnum parentTypeEnum) {
@@ -367,6 +379,55 @@ public class ElementOperation implements IElementOperation {
}
}
+ @Override
+ public List<BaseType> getBaseTypes(final String categoryName){
+ final ArrayList<BaseType> baseTypes = new ArrayList<>();
+ final Map<String, String> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
+ final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName);
+ final String generalBaseType = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get("Service");
+ final String baseToscaResourceName = categorySpecificBaseType == null? generalBaseType : categorySpecificBaseType;
+
+ final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
+ .getByCriteria(VertexTypeEnum.NODE_TYPE, props, JsonParseFlagEnum.ParseAll);
+
+ if (baseTypeVertex.isLeft()) {
+ BaseType baseType = new BaseType(baseToscaResourceName);
+ baseTypes.add(baseType);
+
+ final Map<String, List<String>> typesDerivedFromBaseType = new LinkedHashMap<>();
+ baseTypeVertex.left().value().forEach(v -> {
+ baseType.addVersion((String)v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(typesDerivedFromBaseType, v);
+ });
+
+ typesDerivedFromBaseType.forEach((k,v) -> baseTypes.add(new BaseType(k, v)));
+ }
+
+ return baseTypes;
+ }
+
+ private Map<String, List<String>> addTypesDerivedFromVertex(final Map<String, List<String>> types, final GraphVertex vertex) {
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> derivedFromVertex =
+ janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll);
+ if (derivedFromVertex.isLeft()) {
+ derivedFromVertex.left().value().stream().filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name()))
+ .forEach(v -> {
+ addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), (String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(types, v);
+ });
+ }
+ return types;
+ }
+
+ private void addBaseTypeVersion(final Map<String, List<String>> baseTypes, final String baseTypeToscaResourceName, final String baseTypeVersion) {
+ List<String> versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>(): baseTypes.get(baseTypeToscaResourceName);
+ versions.add(baseTypeVersion);
+ baseTypes.put(baseTypeToscaResourceName, versions);
+ }
+
private JanusGraphOperationStatus setSubCategories(NodeTypeEnum parentNodeType, CategoryDefinition parentCategory) {
NodeTypeEnum childNodeType = getChildNodeType(parentNodeType);
if (childNodeType != null) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
index f9741fc234..92149143e6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
@@ -79,4 +79,7 @@ public class UiComponentDataTransfer {
private List<PropertyDefinition> properties;
private List<AttributeDefinition> attributes;
private Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces;
+ private String derivedFromGenericType;
+ private String derivedFromGenericVersion;
+
}