2  * Copyright 2016-2017, Nokia Corporation
 
   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.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
 
  18 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider;
 
  19 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
 
  20 import org.onap.vfccatalog.api.VnfpackageApi;
 
  21 import org.onap.vnfmdriver.api.NslcmApi;
 
  22 import org.springframework.beans.factory.annotation.Autowired;
 
  23 import org.springframework.context.annotation.Conditional;
 
  24 import org.springframework.stereotype.Component;
 
  27  * Responsible for providing access to VF-C REST APIs
 
  30 @Conditional(value = Conditions.UseForVfc.class)
 
  31 public class VfcRestApiProvider {
 
  32     static final String NSLCM_API_SERVICE_NAME = "nslcm";
 
  33     static final String NSLCM_API_VERION = "v1";
 
  34     static final String NSCATALOG_SERVICE_NAME = "catalog";
 
  35     static final String NSCATALOG_API_VERSION = "v1";
 
  36     private final MsbApiProvider msbApiProvider;
 
  39     VfcRestApiProvider(MsbApiProvider msbApiProvider) {
 
  40         this.msbApiProvider = msbApiProvider;
 
  44      * @return API to access VF-C for granting & LCN API
 
  46     public NslcmApi getNsLcmApi() {
 
  47         org.onap.vnfmdriver.ApiClient apiClient = new org.onap.vnfmdriver.ApiClient();
 
  48         String correctedUrl = fixIncorrectUrl();
 
  49         apiClient.setBasePath(correctedUrl);
 
  50         return new NslcmApi(apiClient);
 
  54      * @return API to access VF-C catalog API
 
  56     public VnfpackageApi getOnapCatalogApi() {
 
  57         org.onap.vfccatalog.ApiClient vfcApiClient = new org.onap.vfccatalog.ApiClient();
 
  58         vfcApiClient.setBasePath(msbApiProvider.getMicroServiceUrl(NSCATALOG_SERVICE_NAME, NSCATALOG_API_VERSION));
 
  59         return new VnfpackageApi(vfcApiClient);
 
  63      * The swagger schema definition is not consistent with MSB info. The MSB reports
 
  64      * the base path /restapi/nsclm/v1 (correct) and the paths defined in swagger is
 
  65      * /nsclm/v1 making all API calls /restapi/nsclm/v1/nsclm/v1 (incorrect)
 
  69     private String fixIncorrectUrl() {
 
  70         String urlInMsb = msbApiProvider.getMicroServiceUrl(NSLCM_API_SERVICE_NAME, NSLCM_API_VERION);
 
  71         //FIXME in VF-C swagger API definitions
 
  72         return urlInMsb.replaceFirst("/nslcm/v1", "");