2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software 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.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.system.fusion.web;
40 import java.util.HashMap;
41 import java.util.TreeMap;
42 import java.util.regex.Matcher;
43 import java.util.regex.Pattern;
45 import javax.servlet.ServletContext;
46 import javax.servlet.http.HttpServletRequest;
48 import org.onap.portalsdk.analytics.model.ReportHandler;
49 import org.onap.portalsdk.analytics.model.ReportLoader;
50 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
51 import org.onap.portalsdk.analytics.model.runtime.DashboardRunJSON;
52 import org.onap.portalsdk.analytics.system.Globals;
53 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
54 import org.onap.portalsdk.core.controller.RestrictedBaseController;
55 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.springframework.web.bind.annotation.PathVariable;
57 import org.springframework.web.bind.annotation.RequestMapping;
58 import org.springframework.web.bind.annotation.RequestMethod;
59 import org.springframework.web.bind.annotation.ResponseBody;
60 import org.springframework.web.bind.annotation.RestController;
63 * For dashboard reports.
67 public class RaptorDashboardController extends RestrictedBaseController {
69 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RaptorDashboardController.class);
71 @RequestMapping(value = { "raptor/dashboard/run/{parameter}" }, method = RequestMethod.GET, produces = "application/json")
73 public DashboardRunJSON dashboardRun(@PathVariable("parameter") String reportId, HttpServletRequest request) {
74 ServletContext servletContext = request.getSession().getServletContext();
75 if (!Globals.isSystemInitialized()) {
76 Globals.initializeSystem(servletContext);
78 DashboardRunJSON dashboardRunJSON = new DashboardRunJSON();
79 dashboardRunJSON.setReportId(reportId);
81 ReportHandler rh1 = new ReportHandler();
82 if (reportId != null) {
83 String reportXML = ReportLoader.loadCustomReportXML(reportId);
84 CustomReportType crType = ReportWrapper.unmarshalCR(reportXML);
85 dashboardRunJSON.setDashboardLayoutJSON(crType.getDashboardLayoutJSON());
87 String strHTML = crType.getDashboardLayoutHTML();
88 dashboardRunJSON.setReportsFromDashBoardHTML(getListOfReportsFromDashBoardHTML(strHTML));
90 reportXML = ReportLoader.loadCustomReportXML(((String)dashboardRunJSON.getReportsFromDashBoardHTML().get("1")).substring(1));
91 crType = ReportWrapper.unmarshalCR(reportXML);
92 dashboardRunJSON.setFormFieldList(crType.getFormFieldList());
93 dashboardRunJSON.setFormFieldGroupsJSON(crType.getFormFieldGroupsJSON());
95 } catch (Exception ex) {
96 logger.error(EELFLoggerDelegate.errorLogger, "getManifest failed", ex);
97 dashboardRunJSON.setErrorMessage(ex.toString());
99 return dashboardRunJSON;
102 private TreeMap getListOfReportsFromDashBoardHTML(String htmlString) {
103 String sourcestring = htmlString;
104 Pattern re = Pattern.compile("\\[(.*?)\\]");
105 Matcher m = re.matcher(sourcestring);
106 HashMap hashReports = new HashMap();
109 for (int groupIdx = 0; groupIdx < m.groupCount(); groupIdx++) {
110 String str = m.group(groupIdx);
111 hashReports.put(new String(Integer.toString(mIdx + 1)),
112 (str.substring(1).toLowerCase().startsWith("chart") ? "c" : "d")
113 + str.substring(str.indexOf("#") + 1, str.length() - 1));
117 return new TreeMap(hashReports);