Adding interfaces in documentation
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / subscription / SubscriptionServiceProcessor.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.onap.aai.sparky.subscription;
26
27 import javax.servlet.http.HttpServletRequest;
28
29 import org.apache.camel.Exchange;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.restclient.client.OperationResult;
33 import org.onap.aai.sparky.logging.AaiUiMsgs;
34 import org.onap.aai.sparky.logging.util.ServletUtils;
35 import org.onap.aai.sparky.subscription.services.SubscriptionService;
36
37 public class SubscriptionServiceProcessor {
38
39   private static final String EMPTY_RESPONSE = "{}";
40
41   private static final Logger LOG =
42       LoggerFactory.getInstance().getLogger(SubscriptionServiceProcessor.class);
43
44   SubscriptionService subService;
45
46
47   public SubscriptionServiceProcessor(SubscriptionService subscriptionService) {
48     this.subService = subscriptionService;
49   }
50
51
52   public void getSubscription(Exchange exchange) {
53     
54     HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
55     ServletUtils.setUpMdcContext(exchange, request);
56
57     OperationResult subscriptionResult = null;
58
59     try {
60
61       subscriptionResult = subService.buildSubscriptionPayload();
62       
63     } catch (Exception exc) {
64       subscriptionResult = new OperationResult();
65       subscriptionResult.setResult(EMPTY_RESPONSE);
66       LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST,
67           "Exception thrown during subscription processing: " + exc.getLocalizedMessage());
68     }
69
70     exchange.getOut().setBody(subscriptionResult.getResult());
71     
72
73   }
74 }