4e358cb6793d0af525357cf9a4d248120fe22320
[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.extern.slf4j.Slf4j;
20 import org.onap.usecaseui.intentanalysis.Thread.CreateCallable;
21 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
22 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
25 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
26 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.context.ApplicationContext;
29 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
30 import org.springframework.stereotype.Component;
31
32 import javax.annotation.Resource;
33 import java.time.LocalDateTime;
34 import java.util.concurrent.FutureTask;
35
36 @Slf4j
37 @Data
38 @Component("CLLDeliveryIntentManagementFunction")
39 public class CLLDeliveryIntentManagementFunction extends IntentManagementFunction {
40     @Resource(name = "CLLDeliveryActuationModule")
41     public void setActuationModule(ActuationModule actuationModule) {
42         this.actuationModule = actuationModule;
43     }
44
45     @Resource(name = "CLLDeliveryKnowledgeModule")
46     public void setKnowledgeModule(KnowledgeModule knowledgeModule) {
47         this.knowledgeModule = knowledgeModule;
48     }
49
50     @Resource(name = "CLLDeliveryDecisionModule")
51     public void setDecisionModule(DecisionModule decisionModule) {
52         this.decisionModule = decisionModule;
53     }
54
55     @Autowired
56     ApplicationContext applicationContext;
57     @Resource(name = "intentTaskExecutor")
58     ThreadPoolTaskExecutor executor;
59
60     @Override
61     public void receiveIntentAsOwner(IntentGoalBean intentGoalBean) {
62     }
63
64     @Override
65     public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler) {
66         //ask  knowledgeModole of handler imf for permision and operate
67         try {
68             log.debug("cllDelivery Intent create begin time:" + LocalDateTime.now());
69             CreateCallable createCallable = new CreateCallable(originalIntent, intentGoalBean, handler, applicationContext);
70             FutureTask<String> futureTask = new FutureTask<>(createCallable);
71             executor.submit(futureTask);
72         } catch (Exception ex) {
73             ex.printStackTrace();
74         }
75     }
76 }