summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/upgrade/SystemUpgrade.java
blob: 9a427003054fda9355c8437a502b99190ceae847 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * ============LICENSE_START==========================================
 * ONAP Portal SDK
 * ===================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 *
 * Unless otherwise specified, all software contained herein is licensed
 * under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Unless otherwise specified, all documentation contained herein is licensed
 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
 * you may not use this documentation except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             https://creativecommons.org/licenses/by/4.0/
 *
 * Unless required by applicable law or agreed to in writing, documentation
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ============LICENSE_END============================================
 *
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 */
package org.onap.portalsdk.analytics.util.upgrade;
 
import java.sql.Connection;
import java.util.Iterator;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.onap.portalsdk.analytics.model.ReportLoader;
import org.onap.portalsdk.analytics.model.base.ReportWrapper;
import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
import org.onap.portalsdk.analytics.system.AppUtils;
import org.onap.portalsdk.analytics.system.DbUtils;
import org.onap.portalsdk.analytics.util.DataSet;
import org.onap.portalsdk.analytics.xmlobj.DataColumnType;

public class SystemUpgrade extends org.onap.portalsdk.analytics.RaptorObject {
	private static final String upgradeFromVersion = "1.x";
	private static final String upgradeToVersion   = "2.0";

/*  This script upgrades the Raptor database to a newer version
	Make sure you execute the "upgrade_v0_to_v1_0_before_java.sql" before running this
	and "upgrade_v0_to_v1_0_after_java.sql" afterwards 
	
	URL example: http://localhost:8082/databank/dispatcher?action=raptor&r_action=system_upgrade
*/
	public static String upgradeDB(HttpServletRequest request) {
		request.setAttribute("system_message", "System upgrade disabled");
		return "raptor/blank.jsp";
		
/*		try {
			if(upgradeFromVersion.equals("1.x")&&upgradeToVersion.equals("2.0"))
				upgrateFromV1ToV2_0(request);
			else
				throw new RuntimeException("Invalid version");
				
			return "raptor/blank.jsp";
		} catch(Exception e) {
			return (new ErrorHandler()).processFatalError(request, e);
		}*/
	}   // upgradeDB

//	private static void upgrateFromV1ToV2_0(HttpServletRequest request) throws Exception {
//		StringBuffer log = new StringBuffer();
//		log.append("Starting upgrade...<br>\n");
//		
//		DataSet ds = DbUtils.executeQuery("SELECT cr.rep_id, cr.sched_mailto_user_ids FROM cr_report cr");
//		for(int i=0; i<ds.getRowCount(); i++) {
//			String repId = ds.getString(i, 0);
//			log.append("<li>Processing report ["+repId+"]: ");
//			
//			Connection connection = DbUtils.startTransaction();
//			String emailIds = nvls(ds.getString(i, 1));
//			if(emailIds.length()>0)
//				try {
//					log.append("Converting emails ");
//					StringTokenizer st = new StringTokenizer(emailIds, ",");
//					while(st.hasMoreTokens()) {
//						String userId = nvls(st.nextToken());
//						log.append(userId);
//						if(userId.length()>0)
//							DbUtils.executeUpdate(connection, "INSERT INTO cr_report_schedule_users (rep_id, user_id) VALUES ("+repId+", "+userId+")");
//						log.append("-success, ");
//					}   // while
//					log.append(" <font color=green>COMPLETED</font>; ");
//				} catch(Exception e) {
//					log.append("-<font color=red>FAILED</font>; ");
//				}
//			
//			String reportXML = ReportLoader.loadCustomReportXML(repId);
//			ReportDefinition rdef = ReportDefinition.unmarshal(reportXML, repId, request);
//			ReportWrapper rw = new ReportWrapper(rdef.cloneCustomReport(), repId, null, null, null, null, null, null, false);
//			
//			for(Iterator iter=rw.getAllColumns().iterator(); iter.hasNext(); ) {
//				DataColumnType col = (DataColumnType) iter.next();
//				String drillDownURL = nvls(col.getDrillDownURL());
//				if(drillDownURL.startsWith("dispatcher?action=custrep.run&c_master=")) {
//					drillDownURL = AppUtils.getReportExecuteActionURL()+drillDownURL.substring("dispatcher?action=custrep.run&c_master=".length());
//					log.append("Drill-down processed; ");
//					col.setDrillDownURL(drillDownURL);
//				}
//			}   // for
//			
//			reportXML = rw.marshal();
//
//			/*PrintWriter xmlOut = new PrintWriter(new BufferedWriter(new FileWriter(new File(AppUtils.getTempFolderPath()+AppUtils.getUserID(request)))));
//			xmlOut.println(reportXML);
//			xmlOut.close();*/
//
//			try {
//				ReportLoader.updateCustomReportRec(connection, rw, reportXML);
//				DbUtils.commitTransaction(connection);
//				log.append("<font color=green>REPORT UPDATED</font></li>\n");
//			} catch(Exception e) {
//				log.append("<font color=red>REPORT UPDATE FAILED</font></li>\n");
//				DbUtils.rollbackTransaction(connection);
//			} finally {
//                DbUtils.clearConnection(connection);         
//            }
//		}   // for
//		
//		log.append("<br>\nSystem upgrade successfully completed...<br>\n");
//		request.setAttribute("system_message", log.toString());
//	}   // upgrateFromV1ToV2_0

}	// SystemUpgrade