2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.sparky.personalization;
23 import javax.servlet.http.HttpServletRequest;
25 import org.apache.camel.Exchange;
26 import org.json.JSONObject;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aai.restclient.client.OperationResult;
30 import org.onap.aai.sparky.logging.AaiUiMsgs;
31 import org.onap.aai.sparky.logging.util.ServletUtils;
32 import org.onap.aai.sparky.personalization.config.PersonalizationConfig;
34 public class PersonalizationServiceProvider {
36 private static final String EMPTY_RESPONSE = "{}";
38 private static final Logger LOG =
39 LoggerFactory.getInstance().getLogger(PersonalizationServiceProvider.class);
41 PersonalizationConfig personalizationConfig;
44 public PersonalizationServiceProvider(PersonalizationConfig personalizationConfig) {
45 this.personalizationConfig = personalizationConfig;
49 public void getPersonalizedValues(Exchange exchange) {
51 HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
52 ServletUtils.setUpMdcContext(exchange, request);
54 OperationResult personalizedValuesResult = new OperationResult();
57 personalizedValuesResult.setResultCode(200);
58 JSONObject personalizedValuesResponse = new JSONObject();
59 personalizedValuesResponse.put("topLeftHeader", personalizationConfig.getTopLeftHeader());
60 personalizedValuesResponse.put("htmlDocumentTitle",
61 personalizationConfig.getHtmlDocumentTitle());
62 personalizedValuesResult.setResult(personalizedValuesResponse.toString());
64 } catch (Exception exc) {
65 personalizedValuesResult.setResultCode(500);
66 personalizedValuesResult.setResult(EMPTY_RESPONSE);
67 LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST,
68 "Exception thrown during personalization processing: " + exc.getLocalizedMessage());
71 exchange.getOut().setBody(personalizedValuesResult.getResult());