2 * Copyright (c) 2018 Orange
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.nbi.apis.hub.service;
18 import org.aspectj.lang.JoinPoint;
19 import org.aspectj.lang.annotation.AfterReturning;
20 import org.aspectj.lang.annotation.Aspect;
21 import org.onap.nbi.apis.hub.model.Event;
22 import org.onap.nbi.apis.hub.model.EventType;
23 import org.onap.nbi.apis.hub.repository.SubscriberRepository;
24 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
25 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
26 import org.onap.nbi.apis.serviceorder.model.StateType;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Configurable;
29 import org.springframework.stereotype.Component;
34 public class NotificationAspect {
37 private SubscriberRepository subscriberRepository;
40 private NotifierService notifier;
42 @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
43 ".createServiceOrder(..))", returning = "serviceOrderCreated")
44 public void whenCreateServiceOrder(ServiceOrder serviceOrderCreated) {
45 if(StateType.ACKNOWLEDGED.equals(serviceOrderCreated.getState())) {
46 processEvent(EventFactory.getEvent(EventType.SERVICE_ORDER_CREATION, serviceOrderCreated, null));
50 @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
51 ".updateOrderState(..))", returning = "serviceOrderUpdated")
52 public void whenUpdateServiceOrderState(ServiceOrder serviceOrderUpdated) {
53 if(StateType.COMPLETED.equals(serviceOrderUpdated.getState())||
54 StateType.FAILED.equals(serviceOrderUpdated.getState())) {
55 processEvent(EventFactory.getEvent(EventType.SERVICE_ORDER_STATE_CHANGE, serviceOrderUpdated, null));
59 @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
60 ".updateOrderItemState(..))")
61 public void whenUpdateServiceOrderItemState(JoinPoint joinPoint) {
62 Object[] signatureArgs = joinPoint.getArgs();
64 if(signatureArgs != null && signatureArgs.length == 3) {
65 ServiceOrder serviceOrder = (ServiceOrder) signatureArgs[0];
66 ServiceOrderItem serviceOrderItem = (ServiceOrderItem) signatureArgs[1];
67 StateType serviceOrderItemState = (StateType) signatureArgs[2];
69 processEvent(EventFactory.getEvent(EventType.SERVICE_ORDER_ITEM_STATE_CHANGE, serviceOrder,
75 * Retreive subscribers that match an event and fire notification
79 private void processEvent(Event event) {
81 .findSubscribersUsingEvent(event)
82 .forEach(sub -> notifier.run(sub, event));