2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6 * Modifications Copyright (C) 2021 Samsung Technologies Co.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.cnf.rest;
24 import com.google.gson.Gson;
25 import org.onap.so.adapters.cnf.model.aai.AaiRequest;
26 import org.onap.so.adapters.cnf.model.synchronization.NotificationRequest;
27 import org.onap.so.adapters.cnf.service.aai.AaiService;
28 import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.PathVariable;
34 import org.springframework.web.bind.annotation.PostMapping;
35 import org.springframework.web.bind.annotation.RequestBody;
36 import org.springframework.web.bind.annotation.RestController;
41 public class SubscriptionNotifyController {
43 private static final Logger logger = LoggerFactory.getLogger(SubscriptionNotifyController.class);
44 private final static Gson gson = new Gson();
46 private final AaiService aaiService;
47 private final SynchronizationService synchronizationService;
49 public SubscriptionNotifyController(AaiService aaiService, SynchronizationService synchronizationService) {
50 this.aaiService = aaiService;
51 this.synchronizationService = synchronizationService;
54 @PostMapping(value = "/api/cnf-adapter/v1/instance/{instanceId}/status/notify")
55 public ResponseEntity subscriptionNotifyEndpoint(@PathVariable String instanceId,
56 @RequestBody NotificationRequest body) throws BadResponseException {
57 String subscriptionName = synchronizationService.getSubscriptionName(instanceId);
58 boolean isSubscriptionActive = synchronizationService.isSubscriptionActive(subscriptionName);
59 if (isSubscriptionActive) {
60 logger.info("AAI update- START");
61 aaiService.aaiUpdate(body.getMetadata());
68 .body(String.format("Cannot handle notification. Subscription %s not exists", subscriptionName));
72 private AaiRequest convertMetadataToAaiRequest(Map<String, Object> metadata) {
73 String json = gson.toJsonTree(metadata)
78 return gson.fromJson(json, AaiRequest.class);