From 0d38c9a8ed4701b860901f67049920e9b1ca72f2 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 5 Jan 2021 13:44:34 +0000 Subject: Enable updating of categories Signed-off-by: MichaelMorris Issue-ID: SDC-3432 Change-Id: Iea0264db40f9d13462182cf0a37ffdd0278f6a1f --- .../be/model/operations/api/IElementOperation.java | 8 +++ .../be/model/operations/impl/ElementOperation.java | 78 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) (limited to 'catalog-model') 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 33877add47..38d5fcf6c8 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 @@ -60,6 +60,10 @@ public interface IElementOperation { Either createCategory(CategoryDefinition category, NodeTypeEnum nodeType); Either createCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction); + + Either updateCategory(CategoryDefinition category, NodeTypeEnum nodeType); + + Either updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction); Either deleteCategory(NodeTypeEnum nodeType, String categoryId); @@ -70,6 +74,10 @@ public interface IElementOperation { Either createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType); Either createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction); + + Either updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType); + + Either updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction); Either, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction); 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 9d0c7b1075..b536f166c3 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 @@ -141,6 +141,41 @@ public class ElementOperation implements IElementOperation { } } } + + @Override + public Either updateCategory(CategoryDefinition category, NodeTypeEnum nodeType) { + return updateCategory(category, nodeType, false); + } + + @Override + public Either updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) { + Either result = null; + category.setUniqueId(UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeType)); + CategoryData categoryData = new CategoryData(nodeType, category); + + try { + Either updatedNode = janusGraphGenericDao + .updateNode(categoryData, CategoryData.class); + if (updatedNode.isRight()) { + JanusGraphOperationStatus value = updatedNode.right().value(); + ActionStatus actionStatus = ActionStatus.GENERAL_ERROR; + log.debug("Problem while creating category, reason {}", value); + result = Either.right(actionStatus); + return result; + } + CategoryDefinition created = new CategoryDefinition(updatedNode.left().value().getCategoryDataDefinition()); + result = Either.left(created); + return result; + } finally { + if (!inTransaction) { + if (result != null && result.isLeft()) { + janusGraphGenericDao.commit(); + } else { + janusGraphGenericDao.rollback(); + } + } + } + } @Override public Either createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) { @@ -170,9 +205,10 @@ public class ElementOperation implements IElementOperation { CategoryDataDefinition categoryDataDefinition = categoryNode.left().value().getCategoryDataDefinition(); subCategory.setUniqueId(UniqueIdBuilder.buildSubCategoryUid(categoryDataDefinition.getUniqueId(), subCategory.getNormalizedName())); SubCategoryData subCategoryData = new SubCategoryData(nodeType, subCategory); - + Either subCategoryNode = janusGraphGenericDao .createNode(subCategoryData, SubCategoryData.class); + if (subCategoryNode.isRight()) { JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value(); log.debug("Problem while creating category, reason {}", janusGraphOperationStatus); @@ -182,7 +218,7 @@ public class ElementOperation implements IElementOperation { result = Either.right(actionStatus); return result; } - + Either relation = janusGraphGenericDao .createRelation(categoryNode.left().value(), subCategoryNode.left().value(), GraphEdgeLabels.SUB_CATEGORY, null); if (relation.isRight()) { @@ -190,6 +226,7 @@ public class ElementOperation implements IElementOperation { result = Either.right(actionStatus); return result; } + SubCategoryDefinition subCategoryCreated = new SubCategoryDefinition(subCategoryNode.left().value().getSubCategoryDataDefinition()); result = Either.left(subCategoryCreated); return result; @@ -203,6 +240,43 @@ public class ElementOperation implements IElementOperation { } } } + + @Override + public Either updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) { + return updateSubCategory(subCategoryId, subCategory, nodeType, false); + } + + @Override + public Either updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) { + + Either result = null; + try { + subCategory.setUniqueId(subCategoryId); + SubCategoryData subCategoryData = new SubCategoryData(nodeType, subCategory); + + Either subCategoryNode = janusGraphGenericDao + .updateNode(subCategoryData, SubCategoryData.class); + + if (subCategoryNode.isRight()) { + JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value(); + log.debug("Problem while updating sub category, reason {}", janusGraphOperationStatus); + result = Either.right(ActionStatus.GENERAL_ERROR); + return result; + } + + SubCategoryDefinition subCategoryUpdated = new SubCategoryDefinition(subCategoryNode.left().value().getSubCategoryDataDefinition()); + result = Either.left(subCategoryUpdated); + return result; + } finally { + if (!inTransaction) { + if (result != null && result.isLeft()) { + janusGraphGenericDao.commit(); + } else { + janusGraphGenericDao.rollback(); + } + } + } + } @Override public Either createGrouping(String subCategoryId, GroupingDefinition grouping, NodeTypeEnum nodeType) { -- cgit 1.2.3-korg