2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Samsung. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vevnfm.service;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import org.onap.aai.domain.yang.EsrSystemInfo;
25 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
26 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
27 import org.onap.so.adapters.etsi.sol003.adapter.lcm.extclients.vnfm.model.LccnSubscriptionRequest;
28 import org.onap.so.rest.service.HttpRestServiceProvider;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.stereotype.Service;
35 import lombok.ToString;
38 public class SubscribeSender {
40 public static final String SLASH = "/";
42 private static final Logger logger = LoggerFactory.getLogger(SubscribeSender.class);
44 private final String vnfmSubscription;
45 private final HttpRestServiceProvider restProvider;
48 public SubscribeSender(final ConfigProperties configProperties, final HttpRestServiceProvider restProvider) {
49 this.vnfmSubscription = configProperties.getVnfmSubscription();
50 this.restProvider = restProvider;
53 public String send(final EsrSystemInfo info, final LccnSubscriptionRequest request) throws VeVnfmException {
54 final ResponseEntity<SubscribeToManoResponse> response =
55 restProvider.postHttpRequest(request, getUrl(info), SubscribeToManoResponse.class);
57 final HttpStatus statusCode = response.getStatusCode();
58 final SubscribeToManoResponse body = response.getBody();
60 logger.info("The VNFM replied with the code {} and the body {}", statusCode, body);
62 if (HttpStatus.CREATED != statusCode) {
63 throw new VeVnfmException("The status code was different than " + HttpStatus.CREATED);
69 public boolean check(final EsrSystemInfo info, final String id) {
70 final ResponseEntity<SubscribeToManoResponse> response =
71 restProvider.getHttpResponse(getUrl(info) + SLASH + id, SubscribeToManoResponse.class);
72 return response.getBody() != null && response.getBody().id.equals(id);
75 private String getUrl(final EsrSystemInfo info) {
76 return info.getServiceUrl() + vnfmSubscription;
80 static class SubscribeToManoResponse {
83 @JsonProperty("callbackUri")