e2865bf773a7cb1d9ae589a4f7d807dcf5f89acb
[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.cllassuranceIntentmgt;
17
18 import lombok.Data;
19 import lombok.extern.slf4j.Slf4j;
20 import org.onap.usecaseui.intentanalysis.Thread.CreateCallable;
21 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
22 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
23 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
24 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
25 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
30 import org.onap.usecaseui.intentanalysis.service.IntentService;
31 import org.springframework.beans.BeanUtils;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.ApplicationContext;
34 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
35 import org.springframework.stereotype.Component;
36
37 import javax.annotation.Resource;
38 import java.time.LocalDateTime;
39 import java.util.concurrent.FutureTask;
40
41 @Slf4j
42 @Data
43 @Component("CLLAssuranceIntentManagementFunction")
44 public class CLLAssuranceIntentManagementFunction extends IntentManagementFunction {
45     @Resource(name = "CLLAssuranceActuationModule")
46     public void setActuationModule(ActuationModule actuationModule) {
47         this.actuationModule = actuationModule;
48     }
49
50     @Resource(name = "CLLAssuranceKnowledgeModule")
51     public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
52         this.knowledgeModule = knowledgeModule;
53     }
54
55     @Resource(name = "CLLAssuranceDecisionModule")
56     public void setDecisionModule(DecisionModule decisionModule) {
57         this.decisionModule = decisionModule;
58     }
59
60     @Autowired
61     ApplicationContext applicationContext;
62     @Resource(name = "intentTaskExecutor")
63     ThreadPoolTaskExecutor executor;
64
65     @Autowired
66     private CLLBusinessIntentManagementFunction cllBusinessIntentManagementFunction;
67
68     @Autowired
69     private IntentInterfaceService intentInterfaceService;
70
71     @Autowired
72     private IntentService intentService;
73
74     @Override
75     public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
76     }
77
78     @Override
79     public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
80         //ask  knowledgeModole of handler imf for permision and operate
81         try {
82             log.debug("cllAssurance Intent {} begin time:{}", intentGoalBean.getIntentGoalType(), LocalDateTime.now());
83             log.debug(Thread.currentThread().getName());
84             CreateCallable assuranceCallable = new CreateCallable(originalIntent, intentGoalBean, handler, applicationContext);
85             FutureTask<String> futureTask = new FutureTask<>(assuranceCallable);
86             executor.submit(futureTask);
87             log.info(futureTask.get());
88         } catch (Exception ex) {
89             log.error("exception is {}", ex.getMessage());
90         }
91
92     }
93
94     @Override
95     public void createReport(String intentId, FulfillmentInfo fulfillmentInfo) {
96         //get parent intentId
97         String parentIntentId = intentService.findParentByIntentId(intentId);
98         // todo
99         FulfillmentInfo newInfo = new FulfillmentInfo();
100         BeanUtils.copyProperties(fulfillmentInfo, newInfo);
101
102         intentInterfaceService.reportInterface(cllBusinessIntentManagementFunction, parentIntentId, newInfo);
103
104         saveFulfillmentAndObjectInstance(intentId, fulfillmentInfo);
105     }
106 }