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.viewandinspect;
24 import javax.servlet.http.HttpServletRequest;
26 import org.apache.camel.Exchange;
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.viewandinspect.entity.QueryRequest;
33 import org.restlet.data.Status;
35 public class SchemaVisualizationProcessor {
38 private static final Logger LOG =
39 LoggerFactory.getInstance().getLogger(SchemaVisualizationProcessor.class);
41 private VisualizationService visualizationService;
43 public SchemaVisualizationProcessor() throws Exception{}
45 protected String generateJsonErrorResponse(String message) {
46 return String.format("{ \"errorMessage\" : %s }", message);
49 public void setVisualizationService(VisualizationService visualizationService){
50 this.visualizationService = visualizationService;
52 public VisualizationService getVisualizationService(){
53 return visualizationService;
56 public void processVisualizationRequest(Exchange exchange) {
58 HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
59 ServletUtils.setUpMdcContext(exchange, request);
61 QueryRequest hashId = null;
62 OperationResult operationResult = null;
64 String visualizationPayload = exchange.getIn().getBody(String.class);
65 hashId = this.getVisualizationService().analyzeQueryRequestBody(visualizationPayload);
69 operationResult = this.getVisualizationService().buildVisualization(hashId);
71 if (operationResult.getResultCode() != Status.SUCCESS_OK.getCode()) {
72 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
73 LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, String
74 .format("Failed to process Visualization Schema Payload = '%s'", visualizationPayload));
79 operationResult = new OperationResult();
80 operationResult.setResult(String
81 .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
82 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
83 LOG.error(AaiUiMsgs.FAILED_TO_ANALYZE, String
84 .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
89 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
90 exchange.getOut().setBody(operationResult.getResult());