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;
18 import lombok.extern.slf4j.Slf4j;
19 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
20 import org.onap.usecaseui.intentanalysis.bean.models.IntentManagementFunctionRegInfo;
21 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
22 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
23 import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService;
24 import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.stereotype.Service;
29 import java.util.List;
30 import java.util.Optional;
31 import java.util.stream.Collectors;
34 public class IntentHandleService {
36 private IntentProcessService processService;
38 private ImfRegInfoService imfRegInfoService;
40 private ApplicationContext applicationContext;
43 * Process the original intent and find the corresponding IntentManagementFunction
47 public void handleOriginalIntent(Intent intent) {
48 IntentManagementFunction intentOwner = getOriginalIMF(intent);
49 handleIntent(intent, intentOwner);
52 public void handleIntent(Intent intent, IntentManagementFunction intentOwner) {
53 processService.setIntentRole(intentOwner, null);
54 processService.intentProcess(intent);
57 public IntentManagementFunction selectIntentManagementFunction(Intent intent) {
58 //select the IntentManagementFunctionRegInfo Based on the IMFRegistry information.
59 //Only internalFunction support.
60 //and based on the IntentManagementFunctionRegInfo, get the right IntentManagementFunction bean.
61 //if no IntentManagementFunction selected, that means this intent is not supported by this system.
65 public IntentManagementFunctionRegInfo selectIntentManagementFunctionRegInfo(Intent intent) {
66 //select the IntentManagementFunctionRegInfo Based on the IMFRegistry information.
67 //Both internalFunction and externalFunction support.
68 //This is used to get he IntentManagementFunction for a subIntent decomposition.
72 public IntentManagementFunction getOriginalIMF(Intent intent) {
73 //select IntentManagementFunction based on intent name
74 String intentName = intent.getIntentName();
75 List<IntentManagementFunctionRegInfo> imfRegInfoList = imfRegInfoService.getImfRegInfoList();
76 List<IntentManagementFunctionRegInfo> list = imfRegInfoList.stream().filter(x -> x.getSupportArea().contains(intentName)).collect(Collectors.toList());
77 if (!Optional.ofNullable(list).isPresent()) {
78 String msg = String.format("Intent name %s doesn't exist IntentManagementFunction in database.", intent.getIntentName());
80 throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
82 return (IntentManagementFunction) applicationContext.getBean(list.get(0).getHandleName());