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;
31 //Parse, decompose, orchestrate the original intent
32 public abstract IntentGoalBean intentCognition(Intent intent);
33 // in distribution, ask permission from imf
34 public abstract boolean recieveCreateIntent();
35 public abstract boolean recieveUpdateIntent();
36 public abstract boolean recieveDeleteIntent();
38 public List<String> intentResolution(Intent intent) {
39 //db contain original intent
40 List<Intent> sameNameIntentList = intentService.getIntentByName(intent.getIntentName());
41 List<String> intentIdList = new ArrayList<>();
42 if (CollectionUtils.isNotEmpty(sameNameIntentList)) {
43 //remove context.condition ownerName = formatIntentInputManagementFunction
44 List<Intent> filterIntentList = filterIntent(sameNameIntentList);
45 List<Expectation> expectationList = intent.getIntentExpectations();
46 for (Intent dbIntent : filterIntentList) {
47 String intentId = dbIntent.getIntentId();
49 for (Expectation expectation : expectationList) {//original expectations
50 //Determine if there is the same ObjectType
51 List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream()
52 .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType()))
53 .collect(Collectors.toList());
54 if (CollectionUtils.isNotEmpty(sameObjTypeList)) {
55 //Determine the targetName of the Expectation which hava same ObjectType
56 List<String> targetNameList = expectation.getExpectationTargets()
57 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
58 for (Expectation dbExpectation : sameObjTypeList) {
59 List<String> dbTargetNameList = dbExpectation.getExpectationTargets()
60 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
61 //todo name compare need ai
62 if (dbTargetNameList.containsAll(targetNameList)) {
68 if (count == expectationList.size()) {
69 intentIdList.add(intentId);
78 public List<Intent> filterIntent(List<Intent> list) {
79 //// condition ownerName = foramtIntentInput
80 List<Intent> fiterList = new ArrayList<>();
81 for (Intent intent : list) {
82 List<Context> ownerInfo = intent.getIntentContexts().stream().filter(x ->
83 StringUtils.equalsIgnoreCase(x.getContextName(), "ownerInfo")).collect(Collectors.toList());
84 if (CollectionUtils.isNotEmpty(ownerInfo)) {
85 for (Context context : ownerInfo) {
86 List<Condition> contextConditions = context.getContextConditions();
87 boolean equals = false;
88 for (Condition condition : contextConditions) {
89 String conditionstr = "ownerName equal to formatIntentInputManagementFunction";
90 String concatStr = condition.getConditionName() + condition.getOperator().name() + condition.getConditionValue();
91 if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.replaceAll(" ",""))) {
92 fiterList.add(intent);
103 list.removeAll(fiterList);