aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
blob: a06d342d26e49bd7372591d03504b317c3f98dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.openecomp.sdc.be.model.operations.impl;

import fj.data.Either;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OperationUtils {

    private final TitanDao titanDao;

    private static final Logger logger = Logger.getLogger(OperationUtils.class.getName());

    public OperationUtils(TitanDao titanDao) {
        this.titanDao = titanDao;
    }

    public <T> T onTitanOperationFailure(TitanOperationStatus status) {
        titanDao.rollback();
        throw new StorageException(status);
    }

    static Either<Map<String, PropertyDefinition>, TitanOperationStatus> fillProperties(String uniqueId,
                                                                                        PropertyOperation propertyOperation,
                                                                                        NodeTypeEnum nodeTypeEnum) {

        Either<Map<String, PropertyDefinition>, TitanOperationStatus> findPropertiesOfNode =
                propertyOperation.findPropertiesOfNode(nodeTypeEnum, uniqueId);
        if (findPropertiesOfNode.isRight()) {
            TitanOperationStatus titanOperationStatus = findPropertiesOfNode.right().value();
            logger.debug("After looking for properties of vertex {}. status is {}", uniqueId, titanOperationStatus);
            if (TitanOperationStatus.NOT_FOUND.equals(titanOperationStatus)) {
                return Either.right(TitanOperationStatus.OK);
            } else {
                return Either.right(titanOperationStatus);
            }
        } else {
            return Either.left(findPropertiesOfNode.left().value());
        }
    }
}