a6ac37d39db1d28d288acf4f47daf501ff654d52
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
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.resmanagement.service.listener;
18
19 import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_CUSTOMER_ID;
20 import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_SERVICE_SUBSCRIPTION_ID;
21
22 import javax.servlet.ServletContextEvent;
23 import javax.servlet.ServletContextListener;
24
25 import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
26 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
27 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
28 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
29
30 public class AaiNamespaceInitializer implements ServletContextListener {
31
32     @Override
33     public void contextDestroyed(ServletContextEvent arg0) {
34     }
35
36     @Override
37     public void contextInitialized(ServletContextEvent arg0) {
38         createCustomer();
39         createServiceSubscription();
40     }
41
42     private int createCustomer() {
43         RestfulParametes restfulParametes = new RestfulParametes();
44         restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
45         restfulParametes.setRawData("{\"global-customer-id\": \"" + VFC_CUSTOMER_ID + "\"," + "\"subscriber-name\": \""
46                 + VFC_CUSTOMER_ID + "\"," + "\"subscriber-type\": \"" + VFC_CUSTOMER_ID + "\"}");
47
48         RestfulResponse response = RestfulUtil.getRestfulResponse(
49                 "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID, restfulParametes,
50                 "put");
51         return response.getStatus();
52     }
53
54     private int createServiceSubscription() {
55         RestfulParametes restfulParametes = new RestfulParametes();
56         restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
57         restfulParametes.setRawData("{\"service-type\": \"" + VFC_SERVICE_SUBSCRIPTION_ID + "\"}");
58
59         RestfulResponse response = RestfulUtil.getRestfulResponse(
60                 "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID
61                         + "/service-subscriptions/service-subscription/" + VFC_SERVICE_SUBSCRIPTION_ID,
62                 restfulParametes, "put");
63         return response.getStatus();
64     }
65
66 }