045a75bc2c4cd96553fb1f079aff93ee2e1de958
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.intentanalysis.eventAndPublish.listener;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.onap.usecaseui.intentanalysis.bean.models.Context;
20 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
21 import org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord;
22 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
23 import org.onap.usecaseui.intentanalysis.eventAndPublish.event.IntentCreateEvent;
24 import org.onap.usecaseui.intentanalysis.intentBaseService.intentEventRecord.IntentEventRecordService;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.context.event.EventListener;
27 import org.springframework.stereotype.Component;
28
29 import java.util.List;
30 import java.util.stream.Collectors;
31
32 @Component
33 public class IntentEventListener {
34     @Autowired
35     private IntentEventRecordService intentEventRecordService;
36
37     @EventListener
38     public void listenIntentCreateEvent(IntentCreateEvent intentCreateEvent){
39         String intentStatus = intentCreateEvent.getIntentStatus();//create status
40         IntentGoalBean intentGoalBean = intentCreateEvent.getIntentGoalBean();//current operate intent
41         Intent currentIntent = intentGoalBean.getIntent();
42         List<Context> owner_info = currentIntent.getIntentContexts().stream().filter(x ->
43                 StringUtils.equals(x.getContextName(), "owner info")).collect(Collectors.toList());
44         List<Context> handler_info = currentIntent.getIntentContexts().stream().filter(x ->
45                 StringUtils.equals(x.getContextName(), "handler info")).collect(Collectors.toList());
46         String owner = owner_info.get(0).getContextConditions().get(0).getConditionValue();
47         String handler = handler_info.get(0).getContextConditions().get(0).getConditionValue();
48
49         IntentEventRecord intentEventRecord = new IntentEventRecord();
50         intentEventRecord.setIntentId(currentIntent.getIntentId());
51         intentEventRecord.setIntentName(currentIntent.getIntentName());
52         intentEventRecord.setIntentStatus(intentStatus);
53         intentEventRecord.setOperateType(intentGoalBean.getIntentGoalType().name());
54         intentEventRecordService.createIntentEventRecord(intentEventRecord);
55     }
56 }