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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.util.upgrade;
43 import javax.servlet.http.*;
45 import org.onap.portalsdk.analytics.controller.*;
46 import org.onap.portalsdk.analytics.error.*;
47 import org.onap.portalsdk.analytics.model.*;
48 import org.onap.portalsdk.analytics.model.base.*;
49 import org.onap.portalsdk.analytics.model.definition.*;
50 import org.onap.portalsdk.analytics.model.runtime.*;
51 import org.onap.portalsdk.analytics.system.*;
52 import org.onap.portalsdk.analytics.util.*;
53 import org.onap.portalsdk.analytics.view.*;
54 import org.onap.portalsdk.analytics.xmlobj.*;
56 public class SystemUpgrade extends org.onap.portalsdk.analytics.RaptorObject {
57 private static final String upgradeFromVersion = "1.x";
58 private static final String upgradeToVersion = "2.0";
60 /* This script upgrades the Raptor database to a newer version
61 Make sure you execute the "upgrade_v0_to_v1_0_before_java.sql" before running this
62 and "upgrade_v0_to_v1_0_after_java.sql" afterwards
64 URL example: http://localhost:8082/databank/dispatcher?action=raptor&r_action=system_upgrade
66 public static String upgradeDB(HttpServletRequest request) {
67 request.setAttribute("system_message", "System upgrade disabled");
68 return "raptor/blank.jsp";
71 if(upgradeFromVersion.equals("1.x")&&upgradeToVersion.equals("2.0"))
72 upgrateFromV1ToV2_0(request);
74 throw new RuntimeException("Invalid version");
76 return "raptor/blank.jsp";
77 } catch(Exception e) {
78 return (new ErrorHandler()).processFatalError(request, e);
82 private static void upgrateFromV1ToV2_0(HttpServletRequest request) throws Exception {
83 StringBuffer log = new StringBuffer();
84 log.append("Starting upgrade...<br>\n");
86 DataSet ds = DbUtils.executeQuery("SELECT cr.rep_id, cr.sched_mailto_user_ids FROM cr_report cr");
87 for(int i=0; i<ds.getRowCount(); i++) {
88 String repId = ds.getString(i, 0);
89 log.append("<li>Processing report ["+repId+"]: ");
91 Connection connection = DbUtils.startTransaction();
92 String emailIds = nvls(ds.getString(i, 1));
93 if(emailIds.length()>0)
95 log.append("Converting emails ");
96 StringTokenizer st = new StringTokenizer(emailIds, ",");
97 while(st.hasMoreTokens()) {
98 String userId = nvls(st.nextToken());
100 if(userId.length()>0)
101 DbUtils.executeUpdate(connection, "INSERT INTO cr_report_schedule_users (rep_id, user_id) VALUES ("+repId+", "+userId+")");
102 log.append("-success, ");
104 log.append(" <font color=green>COMPLETED</font>; ");
105 } catch(Exception e) {
106 log.append("-<font color=red>FAILED</font>; ");
109 String reportXML = ReportLoader.loadCustomReportXML(repId);
110 ReportDefinition rdef = ReportDefinition.unmarshal(reportXML, repId, request);
111 ReportWrapper rw = new ReportWrapper(rdef.cloneCustomReport(), repId, null, null, null, null, null, null, false);
113 for(Iterator iter=rw.getAllColumns().iterator(); iter.hasNext(); ) {
114 DataColumnType col = (DataColumnType) iter.next();
115 String drillDownURL = nvls(col.getDrillDownURL());
116 if(drillDownURL.startsWith("dispatcher?action=custrep.run&c_master=")) {
117 drillDownURL = AppUtils.getReportExecuteActionURL()+drillDownURL.substring("dispatcher?action=custrep.run&c_master=".length());
118 log.append("Drill-down processed; ");
119 col.setDrillDownURL(drillDownURL);
123 reportXML = rw.marshal();
125 /*PrintWriter xmlOut = new PrintWriter(new BufferedWriter(new FileWriter(new File(AppUtils.getTempFolderPath()+AppUtils.getUserID(request)))));
126 xmlOut.println(reportXML);
130 ReportLoader.updateCustomReportRec(connection, rw, reportXML);
131 DbUtils.commitTransaction(connection);
132 log.append("<font color=green>REPORT UPDATED</font></li>\n");
133 } catch(Exception e) {
134 log.append("<font color=red>REPORT UPDATE FAILED</font></li>\n");
135 DbUtils.rollbackTransaction(connection);
137 DbUtils.clearConnection(connection);
141 log.append("<br>\nSystem upgrade successfully completed...<br>\n");
142 request.setAttribute("system_message", log.toString());
143 } // upgrateFromV1ToV2_0