2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.operations.impl;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
25 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27 import org.openecomp.sdc.be.model.PropertyDefinition;
28 import org.openecomp.sdc.be.model.operations.StorageException;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.springframework.stereotype.Component;
35 public class OperationUtils {
37 private final JanusGraphDao janusGraphDao;
39 private static final Logger logger = Logger.getLogger(OperationUtils.class.getName());
41 public OperationUtils(JanusGraphDao janusGraphDao) {
42 this.janusGraphDao = janusGraphDao;
45 public <T> T onJanusGraphOperationFailure(JanusGraphOperationStatus status) {
46 janusGraphDao.rollback();
47 throw new StorageException(status);
50 static Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> fillProperties(String uniqueId,
51 PropertyOperation propertyOperation,
52 NodeTypeEnum nodeTypeEnum) {
54 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> findPropertiesOfNode =
55 propertyOperation.findPropertiesOfNode(nodeTypeEnum, uniqueId);
56 if (findPropertiesOfNode.isRight()) {
57 JanusGraphOperationStatus janusGraphOperationStatus = findPropertiesOfNode.right().value();
58 logger.debug("After looking for properties of vertex {}. status is {}", uniqueId,
59 janusGraphOperationStatus);
60 if (JanusGraphOperationStatus.NOT_FOUND.equals(janusGraphOperationStatus)) {
61 return Either.right(JanusGraphOperationStatus.OK);
63 return Either.right(janusGraphOperationStatus);
66 return Either.left(findPropertiesOfNode.left().value());