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