a017b80fc0a8ff09e12dd887abde0f6d1784d62a
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule;
17
18 import lombok.extern.log4j.Log4j2;
19 import org.apache.commons.collections.CollectionUtils;
20 import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
21 import org.onap.usecaseui.intentanalysis.bean.models.Condition;
22 import org.onap.usecaseui.intentanalysis.bean.models.Context;
23 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
24 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
25 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService;
29 import org.onap.usecaseui.intentanalysis.service.IntentService;
30 import org.onap.usecaseui.intentanalysis.util.CommonUtil;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 @Log4j2
38 @Component
39 public class FormatIntentInputActuationModule extends ActuationModule {
40     @Autowired
41     IntentProcessService processService;
42     @Autowired
43     IntentService intentService;
44     @Override
45     public void toNextIntentHandler(Intent intent, IntentManagementFunction IntentHandler) {
46         log.info("do nothing");
47     }
48
49     @Override
50     public void directOperation() {
51     }
52
53     @Override
54     public void interactWithIntentHandle() {
55     }
56
57     @Override
58     public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
59     }
60     @Override
61     public void saveIntentToDb(Intent intent){
62         List<Context> intentContexts = intent.getIntentContexts();
63         if (CollectionUtils.isEmpty(intentContexts)) {
64             intentContexts = new ArrayList<>();
65         }
66         Context ownerInfoCon = new Context();
67         ownerInfoCon.setContextId(CommonUtil.getUUid());
68         ownerInfoCon.setContextName("ownerInfo");
69         List<Condition> conditionList = new ArrayList<>();
70         Condition condition = new Condition();
71         condition.setConditionId(CommonUtil.getUUid());
72         condition.setConditionName("ownerName");
73         condition.setOperator(OperatorType.EQUALTO);
74         condition.setConditionValue(FormatIntentInputManagementFunction.class.getSimpleName());
75         conditionList.add(condition);
76         ownerInfoCon.setContextConditions(conditionList);
77         intentContexts.add(ownerInfoCon);
78         //ownerId  intentId=parent intent id
79         Context ownerIdContext = new Context();
80         ownerIdContext.setContextId(CommonUtil.getUUid());
81         ownerIdContext.setContextName("ownerId");
82         List<Condition> idConditionList = new ArrayList<>();
83         Condition idCondition = new Condition();
84         idCondition.setConditionId(CommonUtil.getUUid());
85         idCondition.setConditionName("intentId");
86         idCondition.setOperator(OperatorType.EQUALTO);
87         idCondition.setConditionValue(intent.getIntentId());
88         idConditionList.add(idCondition);
89         ownerIdContext.setContextConditions(idConditionList);
90         intentContexts.add(ownerIdContext);
91
92         intent.setIntentContexts(intentContexts);
93         intentService.createIntent(intent);
94     }
95
96 }