2 * Copyright (C) 2023 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.service.impl;
18 import lombok.extern.slf4j.Slf4j;
19 import org.apache.commons.lang.StringUtils;
20 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
21 import org.onap.usecaseui.intentanalysis.bean.models.*;
22 import org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.CLLAssuranceIntentManagementFunction;
23 import org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.CLLDeliveryIntentManagementFunction;
24 import org.onap.usecaseui.intentanalysis.common.ResponseConsts;
25 import org.onap.usecaseui.intentanalysis.exception.CommonException;
26 import org.onap.usecaseui.intentanalysis.exception.DataBaseException;
27 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
28 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
29 import org.onap.usecaseui.intentanalysis.mapper.*;
30 import org.onap.usecaseui.intentanalysis.service.ComponentNotificationService;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.ApplicationContext;
33 import org.springframework.stereotype.Service;
34 import org.springframework.transaction.annotation.Transactional;
35 import org.springframework.util.CollectionUtils;
37 import java.util.List;
41 public class ComponentNotificationServiceImpl implements ComponentNotificationService {
44 private ExpectationObjectMapper expectationObjectMapper;
47 private ExpectationMapper expectationMapper;
50 private ApplicationContext applicationContext;
53 private IntentInterfaceService intentInterfaceService;
56 * Generate a new FulfillmentInfo based on third-party FulfillmentOperation
57 * and save it in the database
59 * @param eventModel param
62 @Transactional(rollbackFor = DataBaseException.class)
63 public void callBack(FulfillmentOperation eventModel) {
64 if (eventModel == null) {
65 String msg = "The obtained fulfillmentInfo is null";
66 throw new CommonException(msg, ResponseConsts.EMPTY_PARAM);
68 String operation = eventModel.getOperation();
69 List<String> objectInstances = eventModel.getObjectInstances();
70 if (CollectionUtils.isEmpty(objectInstances) || StringUtils.isEmpty(operation)) {
71 String msg = "The obtained objectInstances or operation are empty";
72 throw new CommonException(msg, ResponseConsts.EMPTY_PARAM);
74 log.info("Get objectInstances is {}", objectInstances);
75 List<String> expectationIds = expectationObjectMapper.getExpectationIdByObjectInstance(objectInstances.get(0));
76 if (CollectionUtils.isEmpty(expectationIds)) {
77 String msg = "Get expectationId is null from database";
81 log.info("ExpectationId is {}", expectationIds);
82 String intentId = null;
83 ExpectationType expectationType = getExpectationType(operation);
84 for (String expectationId : expectationIds) {
85 intentId = expectationMapper.getIntentIdByExpectationId(expectationId, expectationType);
86 if (StringUtils.isNotEmpty(intentId)) {
91 if (StringUtils.isEmpty(intentId)) {
92 String msg = "Get intentId is null from database";
94 throw new DataBaseException(msg, ResponseConsts.RET_QUERY_DATA_EMPTY);
97 IntentManagementFunction function;
98 if (expectationType == ExpectationType.ASSURANCE) {
99 function = (IntentManagementFunction) applicationContext.getBean(CLLAssuranceIntentManagementFunction.class.getSimpleName());
101 function = (IntentManagementFunction) applicationContext.getBean(CLLDeliveryIntentManagementFunction.class.getSimpleName());
103 intentInterfaceService.reportInterface(function, intentId, eventModel);
106 private ExpectationType getExpectationType(String operation) {
107 if (operation.contains("Assurance")) {
108 return ExpectationType.ASSURANCE;
110 return ExpectationType.DELIVERY;