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.onap.usecaseui.intentanalysis.service.impl.IntentServiceImpl;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Component;
25 import org.springframework.stereotype.Service;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.stream.Collectors;
31 public abstract class KnowledgeModule {
33 private IntentService intentService;
34 //Parse, decompose, orchestrate the original intent
35 public abstract IntentGoalBean intentCognition(Intent intent);
36 // in distribution, ask permission from imf
37 public abstract boolean recieveCreateIntent();
38 public abstract boolean recieveUpdateIntent();
39 public abstract boolean recieveDeleteIntent();
41 public List<String> intentResolution(Intent intent) {
42 //db contain original intent
43 List<Intent> sameNameIntentList = intentService.getIntentByName(intent.getIntentName());
44 List<String> intentIdList = new ArrayList<>();
45 if (CollectionUtils.isNotEmpty(sameNameIntentList)) {
46 //remove context.condition ownerName = formatIntentInputManagementFunction
47 List<Intent> filterIntentList = filterIntent(sameNameIntentList);
48 List<Expectation> expectationList = intent.getIntentExpectations();
49 for (Intent dbIntent : filterIntentList) {
50 String intentId = dbIntent.getIntentId();
52 for (Expectation expectation : expectationList) {//original expectations
53 //Determine if there is the same ObjectType
54 List<Expectation> sameObjTypeList = dbIntent.getIntentExpectations().stream()
55 .filter(x -> x.getExpectationObject().getObjectType().equals(expectation.getExpectationObject().getObjectType()))
56 .collect(Collectors.toList());
57 if (CollectionUtils.isNotEmpty(sameObjTypeList)) {
58 //Determine the targetName of the Expectation which hava same ObjectType
59 List<String> targetNameList = expectation.getExpectationTargets()
60 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
61 for (Expectation dbExpectation : sameObjTypeList) {
62 List<String> dbTargetNameList = dbExpectation.getExpectationTargets()
63 .stream().map(ExpectationTarget::getTargetName).collect(Collectors.toList());
64 //todo name compare need ai
65 if (dbTargetNameList.containsAll(targetNameList)) {
71 if (count == expectationList.size()) {
72 intentIdList.add(intentId);
81 public List<Intent> filterIntent(List<Intent> list) {
82 //// condition ownerName = foramtIntentInput
83 List<Intent> fiterList = new ArrayList<>();
84 for (Intent intent : list) {
85 List<Context> ownerInfo = intent.getIntentContexts().stream().filter(x ->
86 StringUtils.equalsIgnoreCase(x.getContextName(), "ownerInfo")).collect(Collectors.toList());
87 if (CollectionUtils.isNotEmpty(ownerInfo)) {
88 for (Context context : ownerInfo) {
89 List<Condition> contextConditions = context.getContextConditions();
90 boolean equals = false;
91 for (Condition condition : contextConditions) {
92 String conditionstr = "ownerName = formatIntentInputManagementFunction";
93 String concatStr = condition.getConditionName() + condition.getOperator() + condition.getConditionValue();
94 if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.trim())) {
95 fiterList.add(intent);
106 list.removeAll(fiterList);