instantiate and terminate servce
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / service / lcm / impl / DefaultCustomerService.java
1 /**
2  * Copyright 2016-2017 ZTE 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 package org.onap.usecaseui.server.service.lcm.impl;
17
18 import org.onap.usecaseui.server.service.lcm.CustomerService;
19 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
20 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
21 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
22 import org.onap.usecaseui.server.util.RestfulServices;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
26 import org.springframework.stereotype.Service;
27
28 import java.io.IOException;
29 import java.util.List;
30
31 @Service("CustomerService")
32 @org.springframework.context.annotation.Configuration
33 @EnableAspectJAutoProxy
34 public class DefaultCustomerService implements CustomerService {
35
36     private static final Logger logger = LoggerFactory.getLogger(DefaultCustomerService.class);
37
38     private AAIService aaiService;
39
40     public DefaultCustomerService() {
41         this(RestfulServices.create(AAIService.class));
42     }
43
44     public DefaultCustomerService(AAIService aaiService) {
45         this.aaiService = aaiService;
46     }
47
48     @Override
49     public List<AAICustomer> listCustomer() {
50         try {
51             return this.aaiService.listCustomer().execute().body();
52         } catch (IOException e) {
53             logger.error("list customers occur exception");
54             throw new AAIException("AAI is not available.", e);
55         }
56     }
57 }