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.
17 package org.onap.nbi.apis.hub.service;
19 import org.aspectj.lang.JoinPoint;
20 import org.aspectj.lang.annotation.AfterReturning;
21 import org.aspectj.lang.annotation.Aspect;
22 import org.onap.nbi.apis.hub.model.Event;
23 import org.onap.nbi.apis.hub.model.EventType;
24 import org.onap.nbi.apis.hub.repository.SubscriberRepository;
25 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
26 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
27 import org.onap.nbi.apis.serviceorder.model.StateType;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.annotation.Configurable;
30 import org.springframework.stereotype.Component;
35 public class NotificationAspect {
38 private SubscriberRepository subscriberRepository;
41 private NotifierService notifier;
44 value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService"
45 + ".createServiceOrder(..))",
46 returning = "serviceOrderCreated")
47 public void whenCreateServiceOrder(ServiceOrder serviceOrderCreated) {
48 if (StateType.ACKNOWLEDGED.equals(serviceOrderCreated.getState())) {
49 processEvent(EventFactory.getEvent(EventType.SERVICE_ORDER_CREATION, serviceOrderCreated, null));
54 value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" + ".updateOrderState(..))",
55 returning = "serviceOrderUpdated")
56 public void whenUpdateServiceOrderState(ServiceOrder serviceOrderUpdated) {
57 if (StateType.COMPLETED.equals(serviceOrderUpdated.getState())
58 || StateType.FAILED.equals(serviceOrderUpdated.getState())) {
59 processEvent(EventFactory.getEvent(EventType.SERVICE_ORDER_STATE_CHANGE, serviceOrderUpdated, null));
64 value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService"
65 + ".updateOrderItemState(..))")
66 public void whenUpdateServiceOrderItemState(JoinPoint joinPoint) {
67 Object[] signatureArgs = joinPoint.getArgs();
69 if (signatureArgs != null && signatureArgs.length == 3) {
70 ServiceOrder serviceOrder = (ServiceOrder) signatureArgs[0];
71 ServiceOrderItem serviceOrderItem = (ServiceOrderItem) signatureArgs[1];
72 StateType serviceOrderItemState = (StateType) signatureArgs[2];
75 EventFactory.getEvent(EventType.SERVICE_ORDER_ITEM_STATE_CHANGE, serviceOrder, serviceOrderItem));
80 * Retreive subscribers that match an event and fire notification
85 private void processEvent(Event event) {
86 subscriberRepository.findSubscribersUsingEvent(event).forEach(sub -> notifier.run(sub, event));