aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java
blob: e48d21cb77b9c5b3755972021ff9e0ff87c150e2 (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
package org.openecomp.sdc.be.components.impl.utils;

import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;

@Component
public class ExceptionUtils {

    private final TitanDao titanDao;

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

    public <T> T rollBackAndThrow(ActionStatus actionStatus, String ... params) {
         titanDao.rollback();
         throw new ComponentException(actionStatus, params);
     }

    public <T> T rollBackAndThrow(ResponseFormat responseFormat) {
        titanDao.rollback();
        throw new ComponentException(responseFormat);
    }

    public <T> T rollBackAndThrow(StorageOperationStatus status, String ... params) {
        titanDao.rollback();
        throw new StorageException(status, params);
    }

    public <T> T rollBackAndThrow(TitanOperationStatus status, String ... params) {
        titanDao.rollback();
        throw new StorageException(status, params);
    }




}