6286e605505f5e1ecc9934dbc3e2eae1958f31d0
[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.clldeliveryIntentmgt;
17
18 import lombok.Data;
19 import lombok.EqualsAndHashCode;
20 import lombok.extern.slf4j.Slf4j;
21 import org.onap.usecaseui.intentanalysis.Thread.CreateCallable;
22 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
23 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
24 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
25 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
29 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
30 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
31 import org.onap.usecaseui.intentanalysis.service.IntentService;
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("CLLDeliveryIntentManagementFunction")
44 public class CLLDeliveryIntentManagementFunction extends IntentManagementFunction {
45     @Resource(name = "CLLDeliveryActuationModule")
46     public void setActuationModule(ActuationModule actuationModule) {
47         this.actuationModule = actuationModule;
48     }
49
50     @Resource(name = "CLLDeliveryKnowledgeModule")
51     public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
52         this.knowledgeModule = knowledgeModule;
53     }
54
55     @Resource(name = "CLLDeliveryDecisionModule")
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("cllDelivery Intent create begin time:" + LocalDateTime.now());
83             CreateCallable deliveryCallable = new CreateCallable(originalIntent, intentGoalBean, handler, applicationContext);
84             FutureTask<String> futureTask = new FutureTask<>(deliveryCallable);
85             executor.submit(futureTask);
86         } catch (Exception ex) {
87             log.error("exception is {}", ex.getMessage());
88         }
89     }
90
91     @Override
92     public void createReport(String intentId, FulfillmentInfo fulfillmentInfo) {
93         String parentIntentId = intentService.findParentByIntentId(intentId);
94         intentInterfaceService.reportInterface(cllBusinessIntentManagementFunction, parentIntentId, fulfillmentInfo);
95
96         saveFulfillmentAndObjectInstance(intentId, fulfillmentInfo);
97     }
98 }