1cc69301297f866f1068f77c67e13450b28aa2c4
[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.cllBusinessIntentMgt.cllBusinessModule;
17
18
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.intentBaseService.IntentManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
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 @Component
38 public class CLLBusinessActuationModule extends ActuationModule {
39     @Autowired
40     IntentProcessService processService;
41     @Autowired
42     IntentService intentService;
43     @Autowired
44     IntentInterfaceService intentInterfaceService;
45
46
47     @Override
48     public void toNextIntentHandler(Intent intent, IntentManagementFunction IntentHandler) {
49         processService.setIntentRole(IntentHandler, null);
50         processService.intentProcess(intent);
51     }
52
53     @Override
54     public void directOperation() {
55
56     }
57
58     @Override
59     public void interactWithIntentHandle() {
60
61     }
62
63     @Override
64     public void fulfillIntent(IntentGoalBean intentGoalBean, IntentManagementFunction intentHandler) {
65         toNextIntentHandler(intentGoalBean.getIntent(),intentHandler);
66     }
67         
68     @Override
69     public void saveIntentToDb(Intent intent){  //ownerid   parent intent id
70         List<Context> intentContexts = intent.getIntentContexts();
71         if (CollectionUtils.isEmpty(intentContexts)) {
72             intentContexts = new ArrayList<>();
73         }
74         //ownerId  intentId=""  show relatioship beteween  intent
75         Context ownerIdContext = new Context();
76         ownerIdContext.setContextId(CommonUtil.getUUid());
77         ownerIdContext.setContextName("ownerId");
78         List<Condition> idConditionList = new ArrayList<>();
79         Condition idCondition = new Condition();
80         idCondition.setConditionValue(intent.getIntentId());
81         idCondition.setOperator(OperatorType.EQUALTO);
82         idCondition.setConditionName("intentId");
83         idCondition.setConditionId(CommonUtil.getUUid());
84
85         idConditionList.add(idCondition);
86         ownerIdContext.setContextConditions(idConditionList);
87
88         intentContexts.add(ownerIdContext);
89         intent.setIntentContexts(intentContexts);
90         intentService.createIntent(intent);
91     }
92 }