43a6247bcbd1fabb34121b5109a7ac2ce6cd14fa
[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 import org.apache.commons.collections.CollectionUtils;
19 import org.onap.usecaseui.intentanalysis.bean.enums.DetectionGoalType;
20 import org.onap.usecaseui.intentanalysis.bean.models.DetectionGoalBean;
21 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
22 import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget;
23 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
25 import org.onap.usecaseui.intentanalysis.service.IntentService;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.stream.Collectors;
34
35 @Service
36 public class CLLBusinessKnowledgeModule implements KnowledgeModule {
37     private static Logger LOGGER = LoggerFactory.getLogger(CLLBusinessKnowledgeModule.class);
38
39     @Autowired
40     IntentService intentService;
41
42     @Override
43     public Intent intentCognition(Intent intent) {
44         List<String> intendIdList = intentResolution(intent);
45         getSystemStatus();
46         determineDetectionGoal(intent, intendIdList);
47         return null;
48     }
49
50     /**
51      * find similar intents in DB
52      *
53      * @param intent
54      */
55
56     public List<String> intentResolution(Intent intent) {
57         //dc contain original intent
58         String intentName = intent.getIntentName();
59         List<Intent> intentList = intentService.getIntentList();
60         List<Intent> sameNameIntentList = intentList.stream().filter(x -> x.getIntentName()
61                 .contains(intentName)).collect(Collectors.toList());
62         List<String> intentIdList = new ArrayList<>();
63         if (CollectionUtils.isNotEmpty(sameNameIntentList)) {
64             List<Expectation> expectationList = intent.getIntentExpectations();
65             for (Intent dbIntent : sameNameIntentList) {
66                 String intentId = dbIntent.getIntentId();
67                 int count = 0;
68                 for (Expectation expectation : expectationList) {//original expectations
69                     //Determine if there is the same ObjectType
70                     List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream()
71                             .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType()))
72                             .collect(Collectors.toList());
73                     if (CollectionUtils.isNotEmpty(sameObjTypeList)) {
74                         //Determine the targetName of the Expectation which hava same ObjectType
75                         List<String> targetNameList = expectation.getExpectationTargets()
76                                 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
77                         for (Expectation dbExpectation : sameObjTypeList) {
78                             List<String> dbTargetNameList = dbExpectation.getExpectationTargets()
79                                     .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
80                             //todo name compare need ai
81                             if (dbTargetNameList.containsAll(targetNameList)) {
82                                 count++;
83                                 break;
84                             }
85                         }
86                     }
87                     if (count == expectationList.size()) {
88                         intentIdList.add(intentId);
89                         break;
90                     }
91                 }
92             }
93         }
94         return intentIdList;
95     }
96
97     void intentReportResolution() {
98     }
99
100     /**
101      * query the implementation of intent requirements in the system
102      */
103     void getSystemStatus() {
104     }
105
106
107     void interactWithIntentOwner() {
108     }
109
110     /**
111      * Determine add, delete, modify according to theobject,target and context of the expectation
112      */
113     DetectionGoalBean determineDetectionGoal(Intent intent, List<String> intentIdList) {
114         int size = intentIdList.size();
115         if (size == 0) {
116             return new DetectionGoalBean(intent, DetectionGoalType.ADD);
117         } else {
118             return new DetectionGoalBean(intent, DetectionGoalType.UPDATE);
119         }
120     }
121
122 }