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=========================================================
20 package org.openecomp.sdc.be.model.operations.impl;
22 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
25 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
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;
33 public class OperationUtils {
35 private static final Logger logger = Logger.getLogger(OperationUtils.class.getName());
36 private final JanusGraphDao janusGraphDao;
38 public OperationUtils(JanusGraphDao janusGraphDao) {
39 this.janusGraphDao = janusGraphDao;
42 static Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> fillProperties(String uniqueId, PropertyOperation propertyOperation,
43 NodeTypeEnum nodeTypeEnum) {
44 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> findPropertiesOfNode = propertyOperation
45 .findPropertiesOfNode(nodeTypeEnum, uniqueId);
46 if (findPropertiesOfNode.isRight()) {
47 JanusGraphOperationStatus janusGraphOperationStatus = findPropertiesOfNode.right().value();
48 logger.debug("After looking for properties of vertex {}. status is {}", uniqueId, janusGraphOperationStatus);
49 if (JanusGraphOperationStatus.NOT_FOUND.equals(janusGraphOperationStatus)) {
50 return Either.right(JanusGraphOperationStatus.OK);
52 return Either.right(janusGraphOperationStatus);
55 return Either.left(findPropertiesOfNode.left().value());
59 public <T> T onJanusGraphOperationFailure(JanusGraphOperationStatus status) {
60 janusGraphDao.rollback();
61 throw new StorageException(status);