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.be.model.jsonjanusgraph.operations;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
25 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
26 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
27 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
28 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
29 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
30 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
31 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
32 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import org.openecomp.sdc.common.util.ValidationUtils;
36 import java.util.HashMap;
37 import java.util.List;
40 @org.springframework.stereotype.Component("category-operation")
41 public class CategoryOperation extends BaseOperation{
43 private static final Logger log = Logger.getLogger(CategoryOperation.class.getName());
51 public Either<GraphVertex, StorageOperationStatus> getCategory(String name, VertexTypeEnum type) {
53 String categoryUid = UniqueIdBuilder.buildComponentCategoryUid(name, type);
54 Map<GraphPropertyEnum, Object> props = new HashMap<>();
55 props.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(name));
56 Either<List<GraphVertex>, JanusGraphOperationStatus> either = janusGraphDao
57 .getByCriteria(type, props);
59 if (either.isRight()) {
60 JanusGraphOperationStatus janusGraphOperationStatus = either.right().value();
61 log.debug("Problem while geting category with id {}. reason - {}", categoryUid, janusGraphOperationStatus
63 if (janusGraphOperationStatus == JanusGraphOperationStatus.NOT_FOUND) {
64 return Either.right(StorageOperationStatus.CATEGORY_NOT_FOUND);
66 return Either.right(StorageOperationStatus.GENERAL_ERROR);
69 return Either.left(either.left().value().get(0));
71 return Either.right(StorageOperationStatus.GENERAL_ERROR);
80 public Either<GraphVertex, StorageOperationStatus> getSubCategoryForCategory(GraphVertex categoryV, String name ) {
81 Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = janusGraphDao.getChildrenVertices(categoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
82 if ( childrenVertecies.isRight() ){
83 log.debug("Failed to fetch children verticies for category {} error {}", categoryV.getUniqueId(), childrenVertecies.right().value());
84 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenVertecies.right().value()));
86 for ( GraphVertex childV : childrenVertecies.left().value() ){
87 if ( childV.getMetadataProperty(GraphPropertyEnum.NAME).equals(name) ){
88 return Either.left(childV);
91 return Either.right(StorageOperationStatus.NOT_FOUND);