2e4dd999c333b418a37f590f7927c60d9228aad6
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / catalog / impl / CatalogMgmrImpl.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl;
18
19 import java.io.IOException;
20 import java.util.HashMap;
21
22 import org.apache.http.client.ClientProtocolException;
23 import org.apache.http.impl.client.HttpClientBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
30 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
31 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
32 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VnfPackageInfo;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.http.MediaType;
35 import org.springframework.stereotype.Component;
36 import org.springframework.web.bind.annotation.RequestMethod;
37
38 import com.google.gson.Gson;
39
40 @Component
41 public class CatalogMgmrImpl implements CatalogMgmrInf{
42         private static final Logger logger = LoggerFactory.getLogger(CatalogMgmrImpl.class);
43         
44         private Gson gson = new Gson();
45         
46         @Autowired 
47         private AdaptorEnv adaptorEnv;
48         
49         @Autowired
50         HttpClientProcessorInf httpClientProcessor;
51         
52         public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws ClientProtocolException, IOException {
53                 
54                 String url=adaptorEnv.getCatalogApiUriFront() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId);
55                 HashMap<String, String> map = new HashMap<String, String>();
56                 
57                 String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret());
58                 
59                 String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent();
60                 
61                 logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
62                 
63                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
64                 
65                 return resp.getPackageInfo();
66         }
67
68         public void setAdaptorEnv(AdaptorEnv env) {
69                 this.adaptorEnv = env;
70         }
71
72         
73 }