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.intentModule;
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.bean.models.*;
21 import org.onap.usecaseui.intentanalysis.service.IntentService;
22 import org.springframework.beans.factory.annotation.Autowired;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.stream.Collectors;
28 public abstract class KnowledgeModule {
30 private IntentService intentService;
32 //Parse, decompose, orchestrate the original intent
33 public abstract IntentGoalBean intentCognition(Intent intent);
35 // in distribution, ask permission from imf
36 public abstract boolean recieveCreateIntent();
38 public abstract boolean recieveUpdateIntent();
40 public abstract boolean recieveDeleteIntent();
42 public List<String> intentResolution(Intent intent) {
43 //db contain original intent
44 List<Intent> sameNameIntentList = intentService.getIntentByName(intent.getIntentName());
45 List<String> intentIdList = new ArrayList<>();
46 if (CollectionUtils.isNotEmpty(sameNameIntentList)) {
47 //remove context.condition ownerName = formatIntentInputManagementFunction
48 List<Intent> filterIntentList = filterIntent(sameNameIntentList);
49 List<Expectation> expectationList = intent.getIntentExpectations();
50 for (Intent dbIntent : filterIntentList) {
51 String intentId = dbIntent.getIntentId();
53 for (Expectation expectation : expectationList) { //original expectations
54 //Determine if there is the same ObjectType
55 List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream()
56 .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType()))
57 .collect(Collectors.toList());
58 if (CollectionUtils.isNotEmpty(sameObjTypeList)) {
59 //Determine the targetName of the Expectation which hava same ObjectType
60 List<String> targetNameList = expectation.getExpectationTargets()
61 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
62 for (Expectation dbExpectation : sameObjTypeList) {
63 List<String> dbTargetNameList = dbExpectation.getExpectationTargets()
64 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
65 //todo name compare need ai
66 if (dbTargetNameList.containsAll(targetNameList)) {
72 if (count == expectationList.size()) {
73 intentIdList.add(intentId);
82 public List<Intent> filterIntent(List<Intent> list) {
83 List<Intent> fiterList = new ArrayList<>();
84 for (Intent intent : list) {
85 //filter the intent which save first time in controller
86 List<Context> ownerIdContextList = intent.getIntentContexts().stream().filter(x ->
87 StringUtils.equalsIgnoreCase(x.getContextName(), "ownerId")).collect(Collectors.toList());
88 if (CollectionUtils.isEmpty(ownerIdContextList)) {
89 fiterList.add(intent);
92 // condition ownerName = foramtIntentInput
93 List<Context> ownerInfo = intent.getIntentContexts().stream().filter(x ->
94 StringUtils.equalsIgnoreCase(x.getContextName(), "ownerInfo")).collect(Collectors.toList());
95 if (CollectionUtils.isNotEmpty(ownerInfo)) {
96 for (Context context : ownerInfo) {
97 List<Condition> contextConditions = context.getContextConditions();
98 boolean equals = false;
99 for (Condition condition : contextConditions) {
100 String conditionstr = "ownerName equal to formatIntentInputManagementFunction";
101 String concatStr = condition.getConditionName() + condition.getOperator().name() + condition.getConditionValue();
102 if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.replaceAll(" ", ""))) {
103 fiterList.add(intent);
108 if (equals == true) {
114 list.removeAll(fiterList);