diff options
author | MichaelMorris <michael.morris@est.tech> | 2021-01-05 13:44:34 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-01-13 15:58:58 +0000 |
commit | 0d38c9a8ed4701b860901f67049920e9b1ca72f2 (patch) | |
tree | 9141b24822cc82031bfc5ddb897339fe87376f7d /catalog-be | |
parent | 9fd77517c4b56b19b375772bd22ca435aee5c1dd (diff) |
Enable updating of categories
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3432
Change-Id: Iea0264db40f9d13462182cf0a37ffdd0278f6a1f
Diffstat (limited to 'catalog-be')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java | 36 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java | 24 |
2 files changed, 37 insertions, 23 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java index d49284eab0..84b23fe3c7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java @@ -154,19 +154,14 @@ public class CategoriesImportManager { private Either<SubCategoryDefinition, ResponseFormat> createSubCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition newcategory, SubCategoryDefinition subcategory, NodeTypeEnum nodeTypeSubCategory) { log.debug("createSubCategorieDeo: creating subcategory {}", subcategory); Either<SubCategoryDefinition, ActionStatus> createdSubCategory = elementOperation.createSubCategory(newcategory.getUniqueId(), subcategory, nodeTypeSubCategory); + if (createdSubCategory.isRight() && ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY == createdSubCategory.right().value()) { + log.debug(" create subcategory for {} category {} subcategory {} already exists, updating", entry.getKey(), newcategory.getName(), subcategory.getName()); + String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName()); + createdSubCategory = elementOperation.updateSubCategory(subCategoryId, subcategory, nodeTypeSubCategory); + } if (createdSubCategory.isRight()) { - if (ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY == createdSubCategory.right().value()) { - log.debug(" create subcategory for {} category {} subcategory {} already exists retrieving", entry.getKey(), newcategory.getName(), subcategory.getName()); - String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName()); - createdSubCategory = elementOperation.getSubCategory(nodeTypeSubCategory, subCategoryId); - if (createdSubCategory.isRight()) { - log.debug("failed to get sub category that exists subCategoryId: {} type: {}", subCategoryId, nodeTypeSubCategory); - return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value())); - } - } else { - log.debug("Failed to create subcategory for {} category: {} subcategory: {} error {}", entry.getKey(), newcategory.getName(), subcategory.getName(), createdSubCategory.right().value()); - return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value())); - } + log.debug("Failed to create subcategory for {} category: {} subcategory: {} error {}", entry.getKey(), newcategory.getName(), subcategory.getName(), createdSubCategory.right().value()); + return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value())); } else { log.debug("createSubCategorieDeo: create subcategory was successful {}", createdSubCategory.left().value()); } @@ -176,19 +171,14 @@ public class CategoriesImportManager { private Either<CategoryDefinition, ResponseFormat> createCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition category, NodeTypeEnum nodeTypeCategory) { log.debug("createCategorieDeo: creating category {}", category); Either<CategoryDefinition, ActionStatus> createdCategory = elementOperation.createCategory(category, nodeTypeCategory); + if (createdCategory.isRight() && ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS == createdCategory.right().value()) { + log.debug("createCategorieDeo: already exists, updating {}", category); + createdCategory = elementOperation.updateCategory(category, nodeTypeCategory); + } + if (createdCategory.isRight()) { log.debug("Failed to create category for {} {} error {}", entry.getKey(), category.getName(), createdCategory.right().value()); - if (ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS != createdCategory.right().value()) { - return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value())); - } else { - log.debug("createCategorieDeo: category exists {} retriving.", category); - String categoryId = UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeTypeCategory); - createdCategory = elementOperation.getCategory(nodeTypeCategory, categoryId); - if (createdCategory.isRight()) { - log.debug("failed to get category that exists categoryId: {} type: {}", categoryId, nodeTypeCategory); - return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value())); - } - } + return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value())); } else { log.debug("createCategorieDeo: create category was successful {}", createdCategory.left().value()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java index 48a317bcf0..f9605c1aed 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java @@ -132,6 +132,12 @@ public class ElementOperationMock implements IElementOperation { // TODO Auto-generated method stub return null; } + + @Override + public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType) { + // TODO Auto-generated method stub + return null; + } @Override public Either<CategoryDefinition, ActionStatus> deleteCategory(NodeTypeEnum nodeType, String categoryId) { @@ -150,6 +156,12 @@ public class ElementOperationMock implements IElementOperation { // TODO Auto-generated method stub return null; } + + @Override + public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) { + // TODO Auto-generated method stub + return null; + } @Override public Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction) { @@ -249,11 +261,23 @@ public class ElementOperationMock implements IElementOperation { // TODO Auto-generated method stub return null; } + + @Override + public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) { + // TODO Auto-generated method stub + return null; + } @Override public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) { // TODO Auto-generated method stub return null; } + + @Override + public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) { + // TODO Auto-generated method stub + return null; + } } |