2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.intentanalysis.intentBaseService;
19 import lombok.extern.log4j.Log4j2;
20 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
21 import org.onap.usecaseui.intentanalysis.bean.models.Condition;
22 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
23 import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget;
24 import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
25 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
26 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
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.service.FulfillmentInfoService;
31 import org.onap.usecaseui.intentanalysis.service.IntentReportService;
32 import org.onap.usecaseui.intentanalysis.service.ObjectInstanceService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.Configuration;
35 import org.springframework.stereotype.Component;
36 import org.springframework.util.CollectionUtils;
38 import javax.annotation.Resource;
39 import java.util.List;
40 import java.util.concurrent.ScheduledThreadPoolExecutor;
41 import java.util.concurrent.TimeUnit;
42 import java.util.stream.Collectors;
44 import static org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType.CREATE;
50 public class IntentManagementFunction {
51 protected ActuationModule actuationModule;
52 protected DecisionModule decisionModule;
53 protected KnowledgeModule knowledgeModule;
56 private FulfillmentInfoService fulfillmentInfoService;
59 private ObjectInstanceService objectInstanceService;
62 private IntentReportService intentReportService;
64 @Resource(name = "intentReportExecutor")
65 private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
67 public void receiveIntentAsOwner(IntentGoalBean intentGoalBean){};
68 public void receiveIntentAsHandler(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler){};
69 public void createReport(String intentId, FulfillmentInfo fulfillmentInfo){};
71 protected void saveFulfillmentAndObjectInstance(String intentId, FulfillmentInfo fulfillmentInfo) {
72 // save fulfillmentInfo and objectInstance
73 fulfillmentInfoService.saveFulfillmentInfo(intentId, fulfillmentInfo);
74 objectInstanceService.saveObjectInstances(intentId, fulfillmentInfo);
77 protected void generationIntentReport(IntentGoalBean intentGoalBean) {
78 if (CREATE != intentGoalBean.getIntentGoalType()) {
81 Intent intent = intentGoalBean.getIntent();
82 List<Expectation> intentExpectations = intent.getIntentExpectations();
83 List<Expectation> report = intentExpectations.stream()
84 .filter(expectation -> ExpectationType.REPORT.equals(expectation.getExpectationType()))
85 .collect(Collectors.toList());
86 if (CollectionUtils.isEmpty(report)) {
87 log.info("No expectation of type report is entered");
90 List<ExpectationTarget> expectationTargets = report.get(0).getExpectationTargets();
91 if (CollectionUtils.isEmpty(expectationTargets)) {
92 log.error("The expectation target is empty,expectationId is {}", report.get(0).getExpectationId());
95 ExpectationTarget expectationTarget = expectationTargets.get(0);
96 List<Condition> targetConditions = expectationTarget.getTargetConditions();
97 if (CollectionUtils.isEmpty(targetConditions)) {
98 log.error("The target condition is empty,expectationId is {}", report.get(0).getExpectationId());
101 Condition condition = targetConditions.get(0);
103 int conditionValue = Integer.parseInt(condition.getConditionValue());
104 log.info("Start executing scheduled intent report generation task ");
105 scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> intentReportService.saveIntentReportByIntentId(intent.getIntentId()), 2, conditionValue, TimeUnit.SECONDS);
106 } catch (Exception e) {
107 log.error("The exception is {}", e.getMessage());