summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2021-08-20 15:40:35 +0100
committerAndr� Schmid <andre.schmid@est.tech>2021-08-27 10:33:32 +0000
commita5e32b3d20bc078482cb08645c38ffb685c0f145 (patch)
tree133fe88578f3a3c3db3ec73315b65f45caba625a /catalog-model/src/main/java/org/openecomp
parent4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (diff)
Support querying of model by type
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3678 Change-Id: I5fd19eefe475113df501901628b2ee8669004399
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java24
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java20
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java4
5 files changed, 43 insertions, 16 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java
index 9c07c0565c..f551f252c7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java
@@ -18,6 +18,7 @@
*/
package org.openecomp.sdc.be.model;
+import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import com.googlecode.jmapper.annotations.JGlobalMap;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -31,9 +32,15 @@ public class Model {
private String name;
private String derivedFrom;
+ private ModelTypeEnum modelType;
public Model(final String name) {
this.name = name;
}
+
+ public Model(final String name, final ModelTypeEnum modelType) {
+ this.name = name;
+ this.modelType = modelType;
+ }
}
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 bd61f61a49..b2ccb6d0ac 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
@@ -1935,17 +1935,18 @@ public class ToscaOperationFacade {
return fetchServicesByCriteria(services, hasProps, hasNotProps, modelName);
}
- private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract,
- ComponentTypeEnum componentTypeEnum,
- String internalComponentType,
- VertexTypeEnum vertexType,
- String modelName) {
+ private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(final boolean isAbstract,
+ final ComponentTypeEnum componentTypeEnum,
+ final String internalComponentType,
+ final VertexTypeEnum vertexType,
+ final String modelName,
+ final boolean includeNormativeExtensionModels) {
List<Service> services = null;
Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName);
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
- .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName);
+ .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName, includeNormativeExtensionModels);
if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
@@ -2070,7 +2071,7 @@ public class ToscaOperationFacade {
private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum,
String internalComponentType) {
Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, componentTypeEnum,
- internalComponentType, null);
+ internalComponentType, null, false);
if (getToscaElementsRes.isRight()) {
return Either.right(getToscaElementsRes.right().value());
}
@@ -2214,14 +2215,15 @@ public class ToscaOperationFacade {
}
public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract,
- ComponentTypeEnum componentTypeEnum,
- String internalComponentType,
- String modelName) {
+ final ComponentTypeEnum componentTypeEnum,
+ final String internalComponentType,
+ final String modelName,
+ final boolean includeNormativeExtensionModels) {
List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
List<Component> result = new ArrayList<>();
for (VertexTypeEnum vertexType : internalVertexTypes) {
Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract,
- componentTypeEnum, internalComponentType, vertexType, modelName);
+ componentTypeEnum, internalComponentType, vertexType, modelName, includeNormativeExtensionModels);
if (listByVertexType.isRight()) {
return listByVertexType;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java
index 6622bf5bd8..68e098bd69 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java
@@ -52,5 +52,9 @@ public class ModelOperationExceptionSupplier {
var errorMsg = String.format("Failed to retrieve models. Status '%s'", janusGraphOperationStatus);
return () -> new OperationException(ActionStatus.GENERAL_ERROR, errorMsg);
}
+
+ public static Supplier<OperationException> unknownModelType(final String modelType) {
+ return () -> new OperationException(ActionStatus.UNKNOWN_MODEL_TYPE, modelType);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
index ce1f574e93..d522e10d7c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
@@ -46,6 +46,7 @@ import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.data.model.ToscaImportByModel;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
@@ -83,7 +84,7 @@ public class ModelOperation {
public Model createModel(final Model model, final boolean inTransaction) {
Model result = null;
- final var modelData = new ModelData(model.getName(), UniqueIdBuilder.buildModelUid(model.getName()));
+ final var modelData = new ModelData(model.getName(), UniqueIdBuilder.buildModelUid(model.getName()), model.getModelType());
try {
final Either<ModelData, JanusGraphOperationStatus> createNode = janusGraphGenericDao.createNode(modelData, ModelData.class);
if (createNode.isRight()) {
@@ -97,7 +98,7 @@ public class ModelOperation {
String.format("Failed to create model %s on JanusGraph with %s error", model, janusGraphOperationStatus));
}
addDerivedFromRelation(model);
- result = new Model(createNode.left().value().getName(), model.getDerivedFrom());
+ result = new Model(createNode.left().value().getName(), model.getDerivedFrom(), model.getModelType());
return result;
} finally {
if (!inTransaction) {
@@ -183,6 +184,13 @@ public class ModelOperation {
public List<Model> findAllModels() {
return findModelsByCriteria(Collections.emptyMap());
}
+
+ public List<Model> findModels(final ModelTypeEnum modelType) {
+ final Map<GraphPropertyEnum, Object> propertyCriteria = new EnumMap<>(GraphPropertyEnum.class);
+ propertyCriteria.put(GraphPropertyEnum.MODEL_TYPE, modelType.getValue());
+
+ return findModelsByCriteria(propertyCriteria);
+ }
private List<Model> findModelsByCriteria(final Map<GraphPropertyEnum, Object> propertyCriteria) {
final List<GraphVertex> modelVerticesByCriteria = findModelVerticesByCriteria(propertyCriteria);
@@ -209,7 +217,9 @@ public class ModelOperation {
private Model convertToModel(final GraphVertex modelGraphVertex) {
final String modelName = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME);
-
+ final String modelTypeProperty = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE);
+ final ModelTypeEnum modelType = StringUtils.isEmpty(modelTypeProperty) ? ModelTypeEnum.NORMATIVE : ModelTypeEnum.findByValue(modelTypeProperty).get();
+
final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> parentNode =
janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName),
GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class);
@@ -221,10 +231,10 @@ public class ModelOperation {
log.error(EcompLoggerErrorCode.DATA_ERROR, this.getClass().getName(), operationException.getMessage());
throw operationException;
}
- return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME));
+ return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), modelType);
} else {
final ModelData parentModel = parentNode.left().value().getKey();
- return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), parentModel.getName());
+ return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), parentModel.getName(), modelType);
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java
index 685d95e4ab..8c2ee302f7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java
@@ -20,6 +20,7 @@ package org.openecomp.sdc.be.ui.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
+import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -36,4 +37,7 @@ public class ModelCreateRequest {
private String name;
private String derivedFrom;
+
+ private ModelTypeEnum modelType;
+
}