aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/DecisionModule.java
blob: 8c1c5eb7184d2f7d6603bd5695f2939015576d1c (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.onap.usecaseui.intentanalysis.bean.enums.IntentGenerateType;
import org.onap.usecaseui.intentanalysis.bean.models.*;
import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
import org.onap.usecaseui.intentanalysis.util.CommonUtil;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;

@Slf4j
public abstract class DecisionModule {
    // find intentManageFunction
    public abstract IntentManagementFunction exploreIntentHandlers(IntentGoalBean intentGoalBean);

    public Intent intentObjectDefine(Intent originIntent, Intent intent) {
        log.debug("definition create process start to define intent:" + intent.getIntentName());
        Intent newIntent = new Intent();
        newIntent.setIntentId(CommonUtil.getUUid());
        newIntent.setIntentName(intent.getIntentName());
        newIntent.setIntentGenerateType(IntentGenerateType.SYSTEMGENARATE);

        List<Expectation> originalExpectationList = intent.getIntentExpectations();
        List<Expectation> newExpectationList = new ArrayList<>();
        for (Expectation exp:originalExpectationList) {
            Expectation expectation = new Expectation();
            BeanUtils.copyProperties(exp,expectation);
            newExpectationList.add(expectation);
        }
        List<Expectation> newIdExpectationList = getNewExpectationList(newExpectationList);
        newIntent.setIntentExpectations(newIdExpectationList);
        return newIntent;
    }

    public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationCreateProcess(IntentGoalBean intentGoalBean);

    public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationUpdateProcess(IntentGoalBean intentGoalBean);

    public abstract LinkedHashMap<IntentGoalBean, IntentManagementFunction> investigationDeleteProcess(IntentGoalBean intentGoalBean);

    /**
     * build new Intent with uuid
     *
     * @param originalExpectationList
     * @return
     */
    public List<Expectation> getNewExpectationList(List<Expectation> originalExpectationList) {
        if (CollectionUtils.isEmpty(originalExpectationList)) {
            return Collections.emptyList();
        }
        List<Expectation> newExpectations = new ArrayList<>();
        for (Expectation expectation : originalExpectationList) {
            expectation.setExpectationId(CommonUtil.getUUid());
            //ExpectationObject
            ExpectationObject expectationObject = expectation.getExpectationObject();
            ExpectationObject newExpectationObject = getNewExpectationObject(expectationObject);
            expectation.setExpectationObject(newExpectationObject);
            //ExpectationTarget
            List<ExpectationTarget> expectationTargets = expectation.getExpectationTargets();
            List<ExpectationTarget> newExpTargetList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(expectationTargets)) {
                for (ExpectationTarget expectationTarget : expectationTargets) {
                    ExpectationTarget expTarget =new ExpectationTarget();
                    BeanUtils.copyProperties(expectationTarget,expTarget);
                    expTarget.setTargetId(CommonUtil.getUUid());
                    //targetContexts
                    List<Context> targetContexts = expectationTarget.getTargetContexts();
                    if (CollectionUtils.isNotEmpty(targetContexts)) {
                        List<Context> newTargetContexts = new ArrayList<>();
                        for (Context context : targetContexts) {
                            Context con=new Context();
                            BeanUtils.copyProperties(context,con);
                            Context newContext = getNewContext(con);
                            newTargetContexts.add(newContext);
                        }
                        expTarget.setTargetContexts(newTargetContexts);
                    }
                    //targetConditions
                    List<Condition> targetConditions = expectationTarget.getTargetConditions();
                    if (CollectionUtils.isNotEmpty(targetConditions)) {
                        List<Condition> newTargetConditions = new ArrayList<>();
                        for (Condition condition : targetConditions) {
                            Condition con =new Condition();
                            BeanUtils.copyProperties(condition,con);
                            Condition newCondition = getNewCondition(con);
                            newTargetConditions.add(newCondition);
                        }
                        expTarget.setTargetConditions(newTargetConditions);
                    }
                    newExpTargetList.add(expTarget);
                }
                expectation.setExpectationTargets(newExpTargetList);
            }
            //expectationContexts
            List<Context> expectationContexts = expectation.getExpectationContexts();
            if (CollectionUtils.isNotEmpty(expectationContexts)) {
                List<Context> newEexpectationContexts = new ArrayList<>();
                for (Context context : expectationContexts) {
                    Context newContext = getNewContext(context);
                    newEexpectationContexts.add(newContext);
                }
                expectation.setExpectationContexts(newEexpectationContexts);
            }
            newExpectations.add(expectation);
        }
        return newExpectations;
    }

    public ExpectationObject getNewExpectationObject(ExpectationObject expectationObject) {
        if (null != expectationObject) {
            List<Context> objectContexts = expectationObject.getObjectContexts();
            if (CollectionUtils.isNotEmpty(objectContexts)) {
                List<Context> newObjectContexts = new ArrayList<>();
                for (Context context : objectContexts) {
                    Context newContext = getNewContext(context);
                    newObjectContexts.add(newContext);
                }
                expectationObject.setObjectContexts(newObjectContexts);
                return expectationObject;
            }
        }
        return expectationObject;
    }

    public Condition getNewCondition(Condition condition) {
        condition.setConditionId(CommonUtil.getUUid());
        List<Condition> conditionList = condition.getConditionList();
        if (CollectionUtils.isEmpty(conditionList)) {
            return condition;
        } else {
            for (Condition subCondition : conditionList) {
                getNewCondition(subCondition);
            }
        }
        return condition;
    }

    public Context getNewContext(Context context) {
        context.setContextId(CommonUtil.getUUid());
        List<Condition> contextConditions = context.getContextConditions();
        if (CollectionUtils.isNotEmpty(contextConditions)) {
            List<Condition> newConditionList = new ArrayList<>();
            for (Condition condition : contextConditions) {
                Condition con =new Condition();
                BeanUtils.copyProperties(condition,con);
                newConditionList.add(getNewCondition(con));
            }
            context.setContextConditions(newConditionList);
        }
        return context;
    }
}