1dc435578f1dc14c0ebf5474c8924b87fedd9a19
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2019 NOKIA Intellectual Property. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.bbs.event.processor.tasks;
22
23 import org.onap.bbs.event.processor.exceptions.AaiTaskException;
24 import org.onap.bbs.event.processor.model.PnfAaiObject;
25 import org.onap.bbs.event.processor.model.ServiceInstanceAaiObject;
26 import org.onap.bbs.event.processor.utilities.AaiReactiveClient;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31 import org.springframework.util.StringUtils;
32
33 import reactor.core.publisher.Mono;
34
35 @Component
36 public class AaiClientTaskImpl implements AaiClientTask {
37
38     private static final Logger LOGGER = LoggerFactory.getLogger(AaiClientTaskImpl.class);
39     private final AaiReactiveClient reactiveClient;
40
41     @Autowired
42     public AaiClientTaskImpl(AaiReactiveClient reactiveClient) {
43         this.reactiveClient = reactiveClient;
44     }
45
46     @Override
47     public Mono<PnfAaiObject> executePnfRetrieval(String taskName, String url) {
48         if (StringUtils.isEmpty(url)) {
49             throw new AaiTaskException("Cannot invoke an A&AI client task with an invalid URL");
50         }
51         LOGGER.info("Executing task ({}) for retrieving PNF object", taskName);
52         return resolveClient().getPnfObjectDataFor(url);
53     }
54
55     @Override
56     public Mono<ServiceInstanceAaiObject> executeServiceInstanceRetrieval(String taskName, String url) {
57         if (StringUtils.isEmpty(url)) {
58             throw new AaiTaskException("Cannot invoke an A&AI client task with an invalid URL");
59         }
60         LOGGER.info("Executing task ({}) for retrieving Service Instance object", taskName);
61         return resolveClient().getServiceInstanceObjectDataFor(url);
62     }
63
64     @Override
65     public AaiReactiveClient resolveClient() {
66         return reactiveClient;
67     }
68 }