2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.viewandinspect;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
31 import org.apache.camel.Exchange;
32 import org.onap.aai.cl.api.Logger;
33 import org.onap.aai.cl.eelf.LoggerFactory;
34 import org.onap.aai.restclient.client.OperationResult;
35 import org.onap.aai.sparky.logging.AaiUiMsgs;
36 import org.onap.aai.sparky.logging.util.ServletUtils;
37 import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
38 import org.onap.aai.sparky.viewandinspect.services.VisualizationService;
39 import org.restlet.data.Status;
41 public class SchemaVisualizationProcessor {
44 private static final Logger LOG =
45 LoggerFactory.getInstance().getLogger(SchemaVisualizationProcessor.class);
47 private VisualizationService visualizationService;
49 public SchemaVisualizationProcessor()throws Exception{}
51 protected String generateJsonErrorResponse(String message) {
52 return String.format("{ \"errorMessage\" : %s }", message);
55 public void setVisualizationService(VisualizationService visualizationService){
56 this.visualizationService = visualizationService;
58 public VisualizationService getVisualizationService(){
59 return visualizationService;
62 public void processVisualizationRequest(Exchange exchange) {
64 HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
65 ServletUtils.setUpMdcContext(exchange, request);
67 QueryRequest hashId = null;
68 OperationResult operationResult = null;
70 String visualizationPayload = exchange.getIn().getBody(String.class);
71 hashId = this.getVisualizationService().analyzeQueryRequestBody(visualizationPayload);
75 operationResult = this.getVisualizationService().buildVisualizationUsingGenericQuery(hashId);
77 if (operationResult.getResultCode() != Status.SUCCESS_OK.getCode()) {
78 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
79 LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, String
80 .format("Failed to process Visualization Schema Payload = '%s'", visualizationPayload));
85 operationResult = new OperationResult();
86 operationResult.setResult(String
87 .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
88 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
89 LOG.error(AaiUiMsgs.FAILED_TO_ANALYZE, String
90 .format("Failed to analyze Visualization Schema Payload = '%s'", visualizationPayload));
95 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, operationResult.getResultCode());
96 exchange.getOut().setBody(operationResult.getResult());