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