summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java236
1 files changed, 82 insertions, 154 deletions
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 248a1d0460..ea42c6d76b 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
@@ -29,7 +29,7 @@ import java.util.Map;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.config.Configuration.DeploymentArtifactTypeConfig;
+import org.openecomp.sdc.be.config.Configuration.ArtifactTypeConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
@@ -55,8 +55,10 @@ import org.openecomp.sdc.be.resources.data.TagData;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.openecomp.sdc.be.resources.data.category.GroupingData;
import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
+import org.openecomp.sdc.common.util.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.thinkaurelius.titan.core.TitanGraph;
@@ -68,11 +70,11 @@ import fj.data.Either;
@Component("element-operation")
public class ElementOperation implements IElementOperation {
- @javax.annotation.Resource
private TitanGenericDao titanGenericDao;
- public ElementOperation() {
+ public ElementOperation(@Qualifier("titan-generic-dao") TitanGenericDao titanGenericDao) {
super();
+ this.titanGenericDao = titanGenericDao;
}
private static Logger log = LoggerFactory.getLogger(ElementOperation.class.getName());
@@ -107,15 +109,13 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType,
- boolean inTransaction) {
+ public Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) {
Either<CategoryDefinition, ActionStatus> result = null;
category.setUniqueId(UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeType));
CategoryData categoryData = new CategoryData(nodeType, category);
try {
- Either<CategoryData, TitanOperationStatus> createNode = titanGenericDao.createNode(categoryData,
- CategoryData.class);
+ Either<CategoryData, TitanOperationStatus> createNode = titanGenericDao.createNode(categoryData, CategoryData.class);
if (createNode.isRight()) {
TitanOperationStatus value = createNode.right().value();
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
@@ -141,21 +141,18 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId,
- SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
+ public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
return createSubCategory(categoryId, subCategory, nodeType, false);
}
@Override
- public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId,
- SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
+ public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
Either<SubCategoryDefinition, ActionStatus> result = null;
try {
// create edge from category to sub-category
- Either<CategoryData, TitanOperationStatus> categoryNode = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
+ Either<CategoryData, TitanOperationStatus> categoryNode = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
if (categoryNode.isRight()) {
TitanOperationStatus titanOperationStatus = categoryNode.right().value();
@@ -168,12 +165,10 @@ public class ElementOperation implements IElementOperation {
}
CategoryDataDefinition categoryDataDefinition = categoryNode.left().value().getCategoryDataDefinition();
- subCategory.setUniqueId(UniqueIdBuilder.buildSubCategoryUid(categoryDataDefinition.getUniqueId(),
- subCategory.getNormalizedName()));
+ subCategory.setUniqueId(UniqueIdBuilder.buildSubCategoryUid(categoryDataDefinition.getUniqueId(), subCategory.getNormalizedName()));
SubCategoryData subCategoryData = new SubCategoryData(nodeType, subCategory);
- Either<SubCategoryData, TitanOperationStatus> subCategoryNode = titanGenericDao.createNode(subCategoryData,
- SubCategoryData.class);
+ Either<SubCategoryData, TitanOperationStatus> subCategoryNode = titanGenericDao.createNode(subCategoryData, SubCategoryData.class);
if (subCategoryNode.isRight()) {
TitanOperationStatus titanOperationStatus = subCategoryNode.right().value();
log.debug("Problem while creating category, reason {}", titanOperationStatus);
@@ -184,15 +179,13 @@ public class ElementOperation implements IElementOperation {
return result;
}
- Either<GraphRelation, TitanOperationStatus> relation = titanGenericDao.createRelation(
- categoryNode.left().value(), subCategoryNode.left().value(), GraphEdgeLabels.SUB_CATEGORY, null);
+ Either<GraphRelation, TitanOperationStatus> relation = titanGenericDao.createRelation(categoryNode.left().value(), subCategoryNode.left().value(), GraphEdgeLabels.SUB_CATEGORY, null);
if (relation.isRight()) {
log.debug("Problem while create relation between category and sub-category ", relation.right().value());
result = Either.right(actionStatus);
return result;
}
- SubCategoryDefinition subCategoryCreated = new SubCategoryDefinition(
- subCategoryNode.left().value().getSubCategoryDataDefinition());
+ SubCategoryDefinition subCategoryCreated = new SubCategoryDefinition(subCategoryNode.left().value().getSubCategoryDataDefinition());
result = Either.left(subCategoryCreated);
return result;
} finally {
@@ -207,15 +200,13 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<GroupingDefinition, ActionStatus> createGrouping(String subCategoryId, GroupingDefinition grouping,
- NodeTypeEnum nodeType) {
+ public Either<GroupingDefinition, ActionStatus> createGrouping(String subCategoryId, GroupingDefinition grouping, NodeTypeEnum nodeType) {
Either<GroupingDefinition, ActionStatus> result = null;
try {
// create edge from sub-category to grouping
- Either<SubCategoryData, TitanOperationStatus> subCategoryNode = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
+ Either<SubCategoryData, TitanOperationStatus> subCategoryNode = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
if (subCategoryNode.isRight()) {
TitanOperationStatus titanOperationStatus = subCategoryNode.right().value();
@@ -228,12 +219,10 @@ public class ElementOperation implements IElementOperation {
}
SubCategoryDataDefinition subCatData = subCategoryNode.left().value().getSubCategoryDataDefinition();
- grouping.setUniqueId(
- UniqueIdBuilder.buildGroupingUid(subCatData.getUniqueId(), grouping.getNormalizedName()));
+ grouping.setUniqueId(UniqueIdBuilder.buildGroupingUid(subCatData.getUniqueId(), grouping.getNormalizedName()));
GroupingData groupingData = new GroupingData(nodeType, grouping);
- Either<GroupingData, TitanOperationStatus> groupingNode = titanGenericDao.createNode(groupingData,
- GroupingData.class);
+ Either<GroupingData, TitanOperationStatus> groupingNode = titanGenericDao.createNode(groupingData, GroupingData.class);
if (groupingNode.isRight()) {
TitanOperationStatus titanOperationStatus = groupingNode.right().value();
log.debug("Problem while creating grouping, reason {}", titanOperationStatus);
@@ -244,15 +233,13 @@ public class ElementOperation implements IElementOperation {
return result;
}
- Either<GraphRelation, TitanOperationStatus> relation = titanGenericDao.createRelation(
- subCategoryNode.left().value(), groupingNode.left().value(), GraphEdgeLabels.GROUPING, null);
+ Either<GraphRelation, TitanOperationStatus> relation = titanGenericDao.createRelation(subCategoryNode.left().value(), groupingNode.left().value(), GraphEdgeLabels.GROUPING, null);
if (relation.isRight()) {
log.debug("Problem while create relation between sub-category and grouping", relation.right().value());
result = Either.right(actionStatus);
return result;
}
- GroupingDefinition groupingCreated = new GroupingDefinition(
- groupingNode.left().value().getGroupingDataDefinition());
+ GroupingDefinition groupingCreated = new GroupingDefinition(groupingNode.left().value().getGroupingDataDefinition());
result = Either.left(groupingCreated);
return result;
} finally {
@@ -265,17 +252,14 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType,
- boolean inTransaction) {
+ public Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction) {
try {
- if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory
- && nodeType != NodeTypeEnum.ProductCategory) {
+ if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory && nodeType != NodeTypeEnum.ProductCategory) {
log.debug("Unknown category type {}", nodeType.name());
return Either.right(ActionStatus.GENERAL_ERROR);
}
- Either<List<org.openecomp.sdc.be.resources.data.category.CategoryData>, TitanOperationStatus> either = titanGenericDao
- .getAll(nodeType, org.openecomp.sdc.be.resources.data.category.CategoryData.class);
+ Either<List<org.openecomp.sdc.be.resources.data.category.CategoryData>, TitanOperationStatus> either = titanGenericDao.getAll(nodeType, org.openecomp.sdc.be.resources.data.category.CategoryData.class);
if (either.isRight() && (either.right().value() != TitanOperationStatus.NOT_FOUND)) {
log.debug("Problem while get all categories. reason - {}", either.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
@@ -291,8 +275,7 @@ public class ElementOperation implements IElementOperation {
log.trace("Found category {}, category type {}", categoryName, nodeType);
TitanOperationStatus setSubCategories = setSubCategories(nodeType, categoryDefinition);
if (setSubCategories != TitanOperationStatus.OK) {
- log.debug("Failed to set sub-categories for category {}, category type {}, error {}",
- categoryName, nodeType, setSubCategories);
+ log.debug("Failed to set sub-categories for category {}, category type {}, error {}", categoryName, nodeType, setSubCategories);
return Either.right(ActionStatus.GENERAL_ERROR);
}
categoryList.add(categoryDefinition);
@@ -311,14 +294,12 @@ public class ElementOperation implements IElementOperation {
if (childNodeType != null) {
String categoryName = parentCategory.getName();
log.trace("Getting sub-categories for category {}, category type {}", categoryName, parentNodeType);
- Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao
- .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentCategory.getUniqueId(),
- GraphEdgeLabels.SUB_CATEGORY, childNodeType, SubCategoryData.class);
+ Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentCategory.getUniqueId(), GraphEdgeLabels.SUB_CATEGORY,
+ childNodeType, SubCategoryData.class);
if (parentNode.isRight()) {
TitanOperationStatus titanOperationStatus = parentNode.right().value();
if (titanOperationStatus == TitanOperationStatus.NOT_FOUND) {
- log.trace("Didn't find subcategories for category {}, category type {}", categoryName,
- parentNodeType);
+ log.trace("Didn't find subcategories for category {}, category type {}", categoryName, parentNodeType);
titanOperationStatus = TitanOperationStatus.OK;
}
return titanOperationStatus;
@@ -326,16 +307,13 @@ public class ElementOperation implements IElementOperation {
List<ImmutablePair<SubCategoryData, GraphEdge>> subsCategoriesData = parentNode.left().value();
List<SubCategoryDefinition> subCategoriesDefinitions = new ArrayList<>();
for (ImmutablePair<SubCategoryData, GraphEdge> subCatPair : subsCategoriesData) {
- SubCategoryDataDefinition subCategoryDataDefinition = subCatPair.getLeft()
- .getSubCategoryDataDefinition();
+ SubCategoryDataDefinition subCategoryDataDefinition = subCatPair.getLeft().getSubCategoryDataDefinition();
SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(subCategoryDataDefinition);
- log.trace("Found sub-category {} for category {}, category type {}",
- subCategoryDataDefinition.getName(), categoryName, parentNodeType);
+ log.trace("Found sub-category {} for category {}, category type {}", subCategoryDataDefinition.getName(), categoryName, parentNodeType);
TitanOperationStatus setGroupings = setGroupings(childNodeType, subCategoryDefinition);
if (setGroupings != TitanOperationStatus.OK) {
- log.debug("Failed to set groupings for sub-category {}, sub-category type {}, error {}",
- subCategoryDataDefinition.getName(), childNodeType, setGroupings);
+ log.debug("Failed to set groupings for sub-category {}, sub-category type {}, error {}", subCategoryDataDefinition.getName(), childNodeType, setGroupings);
return TitanOperationStatus.GENERAL_ERROR;
}
subCategoriesDefinitions.add(subCategoryDefinition);
@@ -350,14 +328,12 @@ public class ElementOperation implements IElementOperation {
if (childNodeType != null) {
String subCategoryName = parentSubCategory.getName();
log.trace("Getting groupings for subcategory {}, subcategory type {}", subCategoryName, parentNodeType);
- Either<List<ImmutablePair<GroupingData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao
- .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentSubCategory.getUniqueId(),
- GraphEdgeLabels.GROUPING, childNodeType, GroupingData.class);
+ Either<List<ImmutablePair<GroupingData, GraphEdge>>, TitanOperationStatus> parentNode = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentSubCategory.getUniqueId(), GraphEdgeLabels.GROUPING,
+ childNodeType, GroupingData.class);
if (parentNode.isRight()) {
TitanOperationStatus titanOperationStatus = parentNode.right().value();
if (titanOperationStatus == TitanOperationStatus.NOT_FOUND) {
- log.trace("Didn't find groupings for subcategory {}, subcategory type {}", subCategoryName,
- parentNodeType);
+ log.trace("Didn't find groupings for subcategory {}, subcategory type {}", subCategoryName, parentNodeType);
titanOperationStatus = TitanOperationStatus.OK;
}
return titanOperationStatus;
@@ -366,8 +342,7 @@ public class ElementOperation implements IElementOperation {
List<GroupingDefinition> groupingDefinitions = new ArrayList<>();
for (ImmutablePair<GroupingData, GraphEdge> groupPair : groupingData) {
GroupingDataDefinition groupingDataDefinition = groupPair.getLeft().getGroupingDataDefinition();
- log.trace("Found grouping {} for sub-category {}, sub-category type {}",
- groupingDataDefinition.getName(), subCategoryName, parentNodeType);
+ log.trace("Found grouping {} for sub-category {}, sub-category type {}", groupingDataDefinition.getName(), subCategoryName, parentNodeType);
groupingDefinitions.add(new GroupingDefinition(groupingDataDefinition));
}
parentSubCategory.setGroupings(groupingDefinitions);
@@ -396,14 +371,12 @@ public class ElementOperation implements IElementOperation {
@Override
public Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId) {
try {
- if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory
- && nodeType != NodeTypeEnum.ProductCategory) {
+ if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory && nodeType != NodeTypeEnum.ProductCategory) {
log.debug("Unknown category type {}", nodeType.name());
return Either.right(ActionStatus.GENERAL_ERROR);
}
- Either<CategoryData, TitanOperationStatus> categoryDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
+ Either<CategoryData, TitanOperationStatus> categoryDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
if (categoryDataEither.isRight()) {
TitanOperationStatus titanOperationStatus = categoryDataEither.right().value();
log.debug("Problem while get category by id {}. reason {}", categoryId, titanOperationStatus);
@@ -412,8 +385,7 @@ public class ElementOperation implements IElementOperation {
}
return Either.right(ActionStatus.GENERAL_ERROR);
}
- CategoryDataDefinition categoryDataDefinition = categoryDataEither.left().value()
- .getCategoryDataDefinition();
+ CategoryDataDefinition categoryDataDefinition = categoryDataEither.left().value().getCategoryDataDefinition();
return Either.left(new CategoryDefinition(categoryDataDefinition));
} finally {
titanGenericDao.commit();
@@ -428,8 +400,7 @@ public class ElementOperation implements IElementOperation {
return Either.right(ActionStatus.GENERAL_ERROR);
}
- Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
+ Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
if (subCategoryDataEither.isRight()) {
TitanOperationStatus titanOperationStatus = subCategoryDataEither.right().value();
log.debug("Problem while get sub-category by id {}. reason {}", subCategoryId, titanOperationStatus);
@@ -438,8 +409,7 @@ public class ElementOperation implements IElementOperation {
}
return Either.right(ActionStatus.GENERAL_ERROR);
}
- SubCategoryDataDefinition subCategoryDataDefinition = subCategoryDataEither.left().value()
- .getSubCategoryDataDefinition();
+ SubCategoryDataDefinition subCategoryDataDefinition = subCategoryDataEither.left().value().getSubCategoryDataDefinition();
return Either.left(new SubCategoryDefinition(subCategoryDataDefinition));
} finally {
titanGenericDao.commit();
@@ -450,14 +420,12 @@ public class ElementOperation implements IElementOperation {
public Either<CategoryDefinition, ActionStatus> deleteCategory(NodeTypeEnum nodeType, String categoryId) {
Either<CategoryDefinition, ActionStatus> result = null;
try {
- if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory
- && nodeType != NodeTypeEnum.ProductCategory) {
+ if (nodeType != NodeTypeEnum.ResourceNewCategory && nodeType != NodeTypeEnum.ServiceNewCategory && nodeType != NodeTypeEnum.ProductCategory) {
log.debug("Unknown category type {}", nodeType.name());
result = Either.right(ActionStatus.GENERAL_ERROR);
return result;
}
- Either<CategoryData, TitanOperationStatus> categoryDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
+ Either<CategoryData, TitanOperationStatus> categoryDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId, CategoryData.class);
if (categoryDataEither.isRight()) {
log.debug("Failed to retrieve category for id {} ", categoryId);
result = Either.right(ActionStatus.GENERAL_ERROR);
@@ -473,8 +441,7 @@ public class ElementOperation implements IElementOperation {
TitanGraph tGraph = graph.left().value();
- Iterable<TitanVertex> verticesArtifact = tGraph.query()
- .has(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId).vertices();
+ Iterable<TitanVertex> verticesArtifact = tGraph.query().has(UniqueIdBuilder.getKeyByNodeType(nodeType), categoryId).vertices();
Iterator<TitanVertex> iterator = verticesArtifact.iterator();
if (!iterator.hasNext()) {
log.debug("No category node for id = {}", categoryId);
@@ -483,8 +450,7 @@ public class ElementOperation implements IElementOperation {
}
Vertex artifactV = iterator.next();
artifactV.remove();
- CategoryDefinition deleted = new CategoryDefinition(
- categoryDataEither.left().value().getCategoryDataDefinition());
+ CategoryDefinition deleted = new CategoryDefinition(categoryDataEither.left().value().getCategoryDataDefinition());
result = Either.left(deleted);
return result;
} finally {
@@ -505,8 +471,7 @@ public class ElementOperation implements IElementOperation {
result = Either.right(ActionStatus.GENERAL_ERROR);
return result;
}
- Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
+ Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
if (subCategoryDataEither.isRight()) {
log.debug("Failed to retrieve sub-category for id {}", subCategoryId);
result = Either.right(ActionStatus.GENERAL_ERROR);
@@ -522,8 +487,7 @@ public class ElementOperation implements IElementOperation {
TitanGraph tGraph = graph.left().value();
- Iterable<TitanVertex> verticesArtifact = tGraph.query()
- .has(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId).vertices();
+ Iterable<TitanVertex> verticesArtifact = tGraph.query().has(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId).vertices();
Iterator<TitanVertex> iterator = verticesArtifact.iterator();
if (!iterator.hasNext()) {
log.debug("No sub-category node for id {}", subCategoryId);
@@ -533,8 +497,7 @@ public class ElementOperation implements IElementOperation {
Vertex artifactV = iterator.next();
artifactV.remove();
;
- SubCategoryDefinition deleted = new SubCategoryDefinition(
- subCategoryDataEither.left().value().getSubCategoryDataDefinition());
+ SubCategoryDefinition deleted = new SubCategoryDefinition(subCategoryDataEither.left().value().getSubCategoryDataDefinition());
result = Either.left(deleted);
return result;
} finally {
@@ -556,8 +519,7 @@ public class ElementOperation implements IElementOperation {
result = Either.right(ActionStatus.GENERAL_ERROR);
return result;
}
- Either<GroupingData, TitanOperationStatus> groupingDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId, GroupingData.class);
+ Either<GroupingData, TitanOperationStatus> groupingDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId, GroupingData.class);
if (groupingDataEither.isRight()) {
log.debug("Failed to retrieve grouping for id {}", groupingId);
result = Either.right(ActionStatus.GENERAL_ERROR);
@@ -573,8 +535,7 @@ public class ElementOperation implements IElementOperation {
TitanGraph tGraph = graph.left().value();
- Iterable<TitanVertex> verticesArtifact = tGraph.query()
- .has(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId).vertices();
+ Iterable<TitanVertex> verticesArtifact = tGraph.query().has(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId).vertices();
Iterator<TitanVertex> iterator = verticesArtifact.iterator();
if (!iterator.hasNext()) {
log.debug("No grouping node for id {}", groupingId);
@@ -584,8 +545,7 @@ public class ElementOperation implements IElementOperation {
Vertex artifactV = iterator.next();
artifactV.remove();
;
- GroupingDefinition deleted = new GroupingDefinition(
- groupingDataEither.left().value().getGroupingDataDefinition());
+ GroupingDefinition deleted = new GroupingDefinition(groupingDataEither.left().value().getGroupingDataDefinition());
result = Either.left(deleted);
return result;
} finally {
@@ -603,25 +563,21 @@ public class ElementOperation implements IElementOperation {
Map<String, Object> properties = new HashMap<>();
properties.put(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty(), normalizedName);
try {
- Either<List<CategoryData>, TitanOperationStatus> categoryEither = titanGenericDao.getByCriteria(nodeType,
- properties, CategoryData.class);
+ Either<List<CategoryData>, TitanOperationStatus> categoryEither = titanGenericDao.getByCriteria(nodeType, properties, CategoryData.class);
if (categoryEither.isRight() && categoryEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get categories, nodeType {}, normalizedName {}, error {}", nodeType,
- normalizedName, categoryEither.right().value());
+ log.debug("Failed to get categories, nodeType {}, normalizedName {}, error {}", nodeType, normalizedName, categoryEither.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
}
List<CategoryData> categoryList = (categoryEither.isLeft() ? categoryEither.left().value() : null);
if (categoryList != null && categoryList.size() > 0) {
log.debug("Found category for nodeType {} with normalizedName {}", nodeType, normalizedName);
if (categoryList.size() > 1) {
- log.debug("Found more than 1 unique categories for nodeType {} with normalizedName", nodeType,
- normalizedName);
+ log.debug("Found more than 1 unique categories for nodeType {} with normalizedName", nodeType, normalizedName);
return Either.right(ActionStatus.GENERAL_ERROR);
}
return Either.left(false);
} else {
- log.debug("Category for nodeType {} with normalizedName {} doesn't exist in graph", nodeType,
- normalizedName);
+ log.debug("Category for nodeType {} with normalizedName {} doesn't exist in graph", nodeType, normalizedName);
return Either.left(true);
}
} finally {
@@ -630,21 +586,16 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<Boolean, ActionStatus> isSubCategoryUniqueForCategory(NodeTypeEnum nodeType,
- String subCategoryNormName, String parentCategoryId) {
+ public Either<Boolean, ActionStatus> isSubCategoryUniqueForCategory(NodeTypeEnum nodeType, String subCategoryNormName, String parentCategoryId) {
String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(parentCategoryId, subCategoryNormName);
try {
- Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
- if (subCategoryDataEither.isRight()
- && subCategoryDataEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get sub-category with id {}, error {}", subCategoryId,
- subCategoryDataEither.right().value());
+ Either<SubCategoryData, TitanOperationStatus> subCategoryDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), subCategoryId, SubCategoryData.class);
+ if (subCategoryDataEither.isRight() && subCategoryDataEither.right().value() != TitanOperationStatus.NOT_FOUND) {
+ log.debug("Failed to get sub-category with id {}, error {}", subCategoryId, subCategoryDataEither.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
}
- SubCategoryData subCategoryData = (subCategoryDataEither.isLeft() ? subCategoryDataEither.left().value()
- : null);
+ SubCategoryData subCategoryData = (subCategoryDataEither.isLeft() ? subCategoryDataEither.left().value() : null);
if (subCategoryData != null) {
log.debug("Found sub-category with id {}", subCategoryId);
return Either.left(false);
@@ -658,16 +609,13 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<Boolean, ActionStatus> isGroupingUniqueForSubCategory(NodeTypeEnum nodeType, String groupingNormName,
- String parentSubCategoryId) {
+ public Either<Boolean, ActionStatus> isGroupingUniqueForSubCategory(NodeTypeEnum nodeType, String groupingNormName, String parentSubCategoryId) {
String groupingId = UniqueIdBuilder.buildGroupingUid(parentSubCategoryId, groupingNormName);
try {
- Either<GroupingData, TitanOperationStatus> groupingDataEither = titanGenericDao
- .getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId, GroupingData.class);
+ Either<GroupingData, TitanOperationStatus> groupingDataEither = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(nodeType), groupingId, GroupingData.class);
if (groupingDataEither.isRight() && groupingDataEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get grouping with id {}, error {}", groupingId,
- groupingDataEither.right().value());
+ log.debug("Failed to get grouping with id {}, error {}", groupingId, groupingDataEither.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
}
GroupingData groupingData = (groupingDataEither.isLeft() ? groupingDataEither.left().value() : null);
@@ -684,29 +632,23 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<SubCategoryDefinition, ActionStatus> getSubCategoryUniqueForType(NodeTypeEnum nodeType,
- String normalizedName) {
+ public Either<SubCategoryDefinition, ActionStatus> getSubCategoryUniqueForType(NodeTypeEnum nodeType, String normalizedName) {
Map<String, Object> properties = new HashMap<>();
properties.put(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty(), normalizedName);
try {
- Either<List<SubCategoryData>, TitanOperationStatus> subCategoryEither = titanGenericDao
- .getByCriteria(nodeType, properties, SubCategoryData.class);
+ Either<List<SubCategoryData>, TitanOperationStatus> subCategoryEither = titanGenericDao.getByCriteria(nodeType, properties, SubCategoryData.class);
if (subCategoryEither.isRight() && subCategoryEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get sub-categories, nodeType {}, normalizedName {}, error {}", nodeType,
- normalizedName, subCategoryEither.right().value());
+ log.debug("Failed to get sub-categories, nodeType {}, normalizedName {}, error {}", nodeType, normalizedName, subCategoryEither.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
}
- List<SubCategoryData> subCategoryList = (subCategoryEither.isLeft() ? subCategoryEither.left().value()
- : null);
+ List<SubCategoryData> subCategoryList = (subCategoryEither.isLeft() ? subCategoryEither.left().value() : null);
if (subCategoryList != null && subCategoryList.size() > 0) {
log.debug("Found sub-category for nodeType {} with normalizedName {}", nodeType, normalizedName);
SubCategoryData subCategoryData = subCategoryList.get(0);
- SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(
- subCategoryData.getSubCategoryDataDefinition());
+ SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(subCategoryData.getSubCategoryDataDefinition());
return Either.left(subCategoryDefinition);
} else {
- log.debug("Sub-category for nodeType {} with normalizedName {} doesn't exist in graph", nodeType,
- normalizedName);
+ log.debug("Sub-category for nodeType {} with normalizedName {} doesn't exist in graph", nodeType, normalizedName);
return Either.left(null);
}
} finally {
@@ -715,28 +657,23 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public Either<GroupingDefinition, ActionStatus> getGroupingUniqueForType(NodeTypeEnum nodeType,
- String groupingNormalizedName) {
+ public Either<GroupingDefinition, ActionStatus> getGroupingUniqueForType(NodeTypeEnum nodeType, String groupingNormalizedName) {
Map<String, Object> properties = new HashMap<>();
properties.put(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty(), groupingNormalizedName);
try {
- Either<List<GroupingData>, TitanOperationStatus> groupingEither = titanGenericDao.getByCriteria(nodeType,
- properties, GroupingData.class);
+ Either<List<GroupingData>, TitanOperationStatus> groupingEither = titanGenericDao.getByCriteria(nodeType, properties, GroupingData.class);
if (groupingEither.isRight() && groupingEither.right().value() != TitanOperationStatus.NOT_FOUND) {
- log.debug("Failed to get grouping, nodeType {}, normalizedName {}, error {}", nodeType,
- groupingNormalizedName, groupingEither.right().value());
+ log.debug("Failed to get grouping, nodeType {}, normalizedName {}, error {}", nodeType, groupingNormalizedName, groupingEither.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
}
List<GroupingData> groupingList = (groupingEither.isLeft() ? groupingEither.left().value() : null);
if (groupingList != null && groupingList.size() > 0) {
log.debug("Found grouping for nodeType {} with normalizedName {}", nodeType, groupingNormalizedName);
GroupingData groupingData = groupingList.get(0);
- GroupingDefinition groupingDefinition = new GroupingDefinition(
- groupingData.getGroupingDataDefinition());
+ GroupingDefinition groupingDefinition = new GroupingDefinition(groupingData.getGroupingDataDefinition());
return Either.left(groupingDefinition);
} else {
- log.debug("Grouping for nodeType {} with normalizedName {} doesn't exist in graph", nodeType,
- groupingNormalizedName);
+ log.debug("Grouping for nodeType {} with normalizedName {} doesn't exist in graph", nodeType, groupingNormalizedName);
return Either.left(null);
}
} finally {
@@ -751,8 +688,7 @@ public class ElementOperation implements IElementOperation {
@Override
public Either<List<Tag>, ActionStatus> getAllTags() {
try {
- Either<List<TagData>, TitanOperationStatus> either = titanGenericDao.getAll(NodeTypeEnum.Tag,
- TagData.class);
+ Either<List<TagData>, TitanOperationStatus> either = titanGenericDao.getAll(NodeTypeEnum.Tag, TagData.class);
if (either.isRight()) {
log.debug("Problem while get all tags. reason - {}", either.right().value());
return Either.right(ActionStatus.GENERAL_ERROR);
@@ -766,8 +702,7 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public <T extends GraphNode> Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> getCategoryData(
- String name, NodeTypeEnum type, Class<T> clazz) {
+ public <T extends GraphNode> Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> getCategoryData(String name, NodeTypeEnum type, Class<T> clazz) {
if (name != null) {
String categoryUid = null;
if (type == NodeTypeEnum.ResourceCategory) {
@@ -779,8 +714,7 @@ public class ElementOperation implements IElementOperation {
} else {
categoryUid = UniqueIdBuilder.buildServiceCategoryUid(name, type);
}
- Either<T, TitanOperationStatus> either = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(type),
- categoryUid, clazz);
+ Either<T, TitanOperationStatus> either = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(type), categoryUid, clazz);
if (either.isRight()) {
TitanOperationStatus titanOperationStatus = either.right().value();
@@ -827,8 +761,7 @@ public class ElementOperation implements IElementOperation {
public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes() {
List<ArtifactType> artifactTypes = new ArrayList<ArtifactType>();
- List<String> artifactTypesList = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getArtifactTypes();
+ List<String> artifactTypesList = ConfigurationManager.getConfigurationManager().getConfiguration().getArtifactTypes();
for (String artifactType : artifactTypesList) {
ArtifactType artifactT = new ArtifactType();
artifactT.setName(artifactType);
@@ -841,12 +774,9 @@ public class ElementOperation implements IElementOperation {
public Either<Map<String, Object>, ActionStatus> getAllDeploymentArtifactTypes() {
Map<String, Object> artifactTypes = new HashMap<String, Object>();
- Map<String, DeploymentArtifactTypeConfig> artifactResourceTypes = ConfigurationManager.getConfigurationManager()
- .getConfiguration().getResourceDeploymentArtifacts();
- Map<String, DeploymentArtifactTypeConfig> artifactServiceTypes = ConfigurationManager.getConfigurationManager()
- .getConfiguration().getServiceDeploymentArtifacts();
- Map<String, DeploymentArtifactTypeConfig> artifactResourceInstanceTypes = ConfigurationManager
- .getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts();
+ Map<String, ArtifactTypeConfig> artifactResourceTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+ Map<String, ArtifactTypeConfig> artifactServiceTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceDeploymentArtifacts();
+ Map<String, ArtifactTypeConfig> artifactResourceInstanceTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts();
artifactTypes.put("resourceDeploymentArtifacts", artifactResourceTypes);
artifactTypes.put("serviceDeploymentArtifacts", artifactServiceTypes);
@@ -858,8 +788,7 @@ public class ElementOperation implements IElementOperation {
@Override
public Either<Integer, ActionStatus> getDefaultHeatTimeout() {
- return Either.left(ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDefaultHeatArtifactTimeoutMinutes());
+ return Either.left(ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultHeatArtifactTimeoutMinutes());
}
@Override
@@ -876,12 +805,11 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public <T extends GraphNode> Either<CategoryData, StorageOperationStatus> getNewCategoryData(String name,
- NodeTypeEnum type, Class<T> clazz) {
+ public <T extends GraphNode> Either<CategoryData, StorageOperationStatus> getNewCategoryData(String name, NodeTypeEnum type, Class<T> clazz) {
if (name != null) {
String categoryUid = UniqueIdBuilder.buildServiceCategoryUid(name, type);
Map props = new HashMap<>();
- props.put(GraphPropertiesDictionary.NAME.getProperty(), name);
+ props.put(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty(), ValidationUtils.normalizeCategoryName4Uniqueness(name));
Either<List<T>, TitanOperationStatus> either = titanGenericDao.getByCriteria(type, props, clazz);
if (either.isRight()) {