2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.be.model.category.CategoryDefinition;
27 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
28 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
30 import javax.annotation.Resource;
31 import java.util.List;
33 import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
35 public class ServiceCategoriesMigration extends JsonModelMigration<CategoryDefinition> {
37 @Resource(name = "element-operation")
38 private IElementOperation elementOperation;
40 @Resource(name = "element-operation-migration")
41 private IElementOperation elementOperationMigration;
45 public String description() {
46 return "migrate services categories";
50 Either<List<CategoryDefinition>, ?> getElementsToMigrate() {
51 return elementOperation.getAllCategories(NodeTypeEnum.ServiceNewCategory, false).left().map(CategoriesUtils::filterOldCategories);
55 Either<CategoryDefinition, ?> getElementFromNewGraph(CategoryDefinition node) {
56 String categoryUid = UniqueIdBuilder.buildCategoryUid(node.getNormalizedName(), NodeTypeEnum.ServiceNewCategory);//in malformed graph there are some categories with different id but same normalized name. so in new graph they same id
57 return elementOperationMigration.getCategory(NodeTypeEnum.ServiceNewCategory, categoryUid);
61 boolean save(CategoryDefinition graphNode) {
62 return elementOperationMigration.createCategory(graphNode, NodeTypeEnum.ServiceNewCategory)
63 .either(savedCategory -> true,
64 err -> handleError(String.format("failed to save category %s. error: %s", graphNode.getName(), err.name())));
68 ActionStatus getNotFoundErrorStatus() {
69 return ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;