summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/fusion/AppUtils.java
blob: 6ee8e5dc4ed01bdbbec0804a24d836453e923949 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*-
 * ================================================================================
 * eCOMP Portal SDK
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file 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.
 * ================================================================================
 */
package org.openecomp.portalsdk.analytics.system.fusion;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.openecomp.portalsdk.analytics.config.ConfigLoader;
import org.openecomp.portalsdk.analytics.error.RaptorException;
import org.openecomp.portalsdk.analytics.model.base.IdNameValue;
import org.openecomp.portalsdk.analytics.system.Globals;
import org.openecomp.portalsdk.analytics.system.IAppUtils;
import org.openecomp.portalsdk.analytics.system.fusion.adapter.RaptorAdapter;
import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;;

public class AppUtils extends org.openecomp.portalsdk.analytics.RaptorObject implements IAppUtils  {
	
	EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppUtils.class);

	
	private static String tempFolderPath         = "/artemis/PROJECT1/MSA/databank/WEB-INF/temp/";
	private static String uploadFolderPath       = "/artemis/PROJECT1/MSA/databank/WEB-INF/upload/";
	private static String tempFolderURL          = "temp/";
	private static String uploadFolderURL        = "upload/";
	private static String SMTPServer             = "todo.smtp.server.com";
	private static String defaultEmailSender     = "todo.email.sender.com";
	private static String errorPage 			 = "error_page";
	private static String errorPageWMenu 	     = "error_page_wmenu";	
	private static String jspContextPath         = "raptor/";
	private static String imgFolderURL           = "raptor/images/";
	private static String baseFolderURL          = "raptor/";
	//private static String reportExecuteActionURL = "dispatcher?action=raptor&r_action=report.run&c_master=";
	//private static String dataViewActionURL      = "dispatcher?action=";    // dispatcher?action=ACTION_ID&c_master=REC_ID
	//private static String dataViewActionParam    = "c_master=";
	private static String directAccessURL        = "http://localhost:8082/databank/dispatcher?direct.access=raptor&r_action=report.run&show=";
	private static String baseActionURL          = "dispatcher?action=";    // dispatcher?action=ACTION_ID&c_master=REC_ID or dispatcher?action=raptor&r_action=RAPTOR_ACTION_ID&c_master=REC_ID
	private static String baseActionURLNG          = "report#/";    // dispatcher?action=ACTION_ID&c_master=REC_ID or dispatcher?action=raptor&r_action=RAPTOR_ACTION_ID&c_master=REC_ID
	private static String drillActionURL          = "dispatcher?action=";    // dispatcher?action=ACTION_ID&c_master=REC_ID or dispatcher?action=raptor&r_action=RAPTOR_ACTION_ID&c_master=REC_ID
	private static String baseActionParam        = "c_master=";
	private static String superRoleID            = "1";
	private static Vector adminRoleIDs           = new Vector();
	private static Vector quickLinksMenuIDs      = new Vector();
	
	private static Properties raptorAppProperties;

	private static String encryptedSMTPServer	 = "";
	public AppUtils() {}

	public void initializeAppUtils(ServletContext servletContext) {
		try {
			Properties appProperties = ConfigLoader.getProperties(servletContext, ConfigLoader.APP_PROPERTIES, Globals.getSystemType());
			raptorAppProperties = appProperties;
			tempFolderPath         = appProperties.getProperty("temp_folder_path");
			uploadFolderPath       = appProperties.getProperty("upload_folder_path");
			tempFolderURL          = appProperties.getProperty("temp_folder_url");
			uploadFolderURL        = appProperties.getProperty("upload_folder_url");
			SMTPServer             = appProperties.getProperty("smtp_server");
			encryptedSMTPServer    = appProperties.getProperty("encrypted_smtp_server");
			defaultEmailSender     = appProperties.getProperty("default_email_sender");
			errorPage              = appProperties.getProperty("error_page");
			jspContextPath         = appProperties.getProperty("jsp_context_path");
			imgFolderURL           = appProperties.getProperty("img_folder_url");
			baseFolderURL          = appProperties.getProperty("base_folder_url");
/*			reportExecuteActionURL = appProperties.getProperty("report_execute_action_url");
			dataViewActionURL      = appProperties.getProperty("data_view_action_url");
			dataViewActionParam    = appProperties.getProperty("data_view_action_param");*/
			directAccessURL        = appProperties.getProperty("direct_access_url");
			baseActionURL          = appProperties.getProperty("base_action_url");
			baseActionURLNG          = appProperties.getProperty("base_action_url_ng");
			drillActionURL          = appProperties.getProperty("drill_action_url");
			baseActionParam        = appProperties.getProperty("base_action_param");
			superRoleID            = appProperties.getProperty("super_role_id");

			adminRoleIDs.removeAllElements();
			StringTokenizer st = new StringTokenizer(appProperties.getProperty("admin_role_ids"), ",");
			while(st.hasMoreTokens())
				adminRoleIDs.add(st.nextToken());

			quickLinksMenuIDs.removeAllElements();
			st = new StringTokenizer(appProperties.getProperty("quick_links_menu_ids"), ",");
			while(st.hasMoreTokens())
				quickLinksMenuIDs.add(st.nextToken());
		} catch(Exception e) {
			logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] AppUtils.initializeAppUtils: Unable to load properties ["+Globals.getSystemType()+"_"+ConfigLoader.APP_PROPERTIES+"]. Exception: "+e.getMessage()));
			//throw new RuntimeException(e.getMessage());
		}
	}   // initializeAppUtils

	public static void getFullURL(HttpServletRequest req) {
		String applicationBase = "";
	    if (applicationBase == null) {
	        applicationBase = req.getScheme() + "://" + req.getServerName() +
	                getPort(req) + req.getContextPath();
	    }
	}

	private static String getPort(HttpServletRequest req) {
	    if ("http".equalsIgnoreCase(req.getScheme()) && req.getServerPort() != 80 ||
	            "https".equalsIgnoreCase(req.getScheme()) && req.getServerPort() != 443 ) {
	        return (":" + req.getServerPort());
	    } else {
	        return "";
	    }
	}	
	public String getUserID(HttpServletRequest request) {
		String pdfAttachmentKey = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "pdfAttachmentKey");
		String report_email_sent_log_id = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "log_id");
		boolean isEmailAttachment = false;
		if(pdfAttachmentKey != null && report_email_sent_log_id !=null) 
			isEmailAttachment = true;
		if(isEmailAttachment) {
			return RaptorAdapter.getUserID(org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "user_id"));
		} else
			return RaptorAdapter.getUserID(request);
	}   // getUserID

	public Vector getAllUsers(String customizedQuery, String param, boolean isAdmin) {
		Map map = RaptorAdapter.getAllUsers(customizedQuery, param, isAdmin);

		Vector vector = new Vector(map.size());
		for(Iterator iter=map.keySet().iterator(); iter.hasNext(); ) {
			Long key = (Long) iter.next();
			vector.add(new IdNameValue(""+key, (String) map.get(key)));
		}	// for

		return vector;
	}   // getAllUsers

	public String getRoleName(String roleId) {
		return RaptorAdapter.getRoleName(roleId);
	}   // getRoleName

	public Vector getAllRoles(String customizedQuery, String param, boolean isAdmin) {
		Map map = RaptorAdapter.getAllRolesUsingCustomizedQuery(customizedQuery, param, isAdmin);

		Vector vector = new Vector(map.size());
		for(Iterator iter=map.keySet().iterator(); iter.hasNext(); ) {
			Long key = (Long) iter.next();
			vector.add(new IdNameValue(""+key, (String) map.get(key)));
		}	// for

		return vector;
	}   // getAllRoles

	public String getUserName(HttpServletRequest request) {
		return RaptorAdapter.getUserName(request);
	}   // getUserName

	public String getUserName(String userId) {
		return RaptorAdapter.getUserName(userId);
	}   // getUserName

	public String getUserEmail(String userId) {
        return RaptorAdapter.getUserEmail(userId);
    }   // getUserEmail

	public String getUserEmail(HttpServletRequest request) {
        return RaptorAdapter.getUserEmail(request);
    }   // getUserEmail
    
	public String getUserLoginId(HttpServletRequest request) {
		return RaptorAdapter.getUserLoginId(request);
	}   // getUserLoginId

	public String getUserLoginId(String userId) {
		return RaptorAdapter.getUserLoginId(userId);
	}   // getUserLoginId
	
	public String getUserBackdoorLoginId(HttpServletRequest request) {
		String pdfAttachmentKey = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "pdfAttachmentKey");
		String report_email_sent_log_id = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "log_id");
		boolean isEmailAttachment = false;
		if(pdfAttachmentKey != null && report_email_sent_log_id !=null) 
			isEmailAttachment = true;
		if(isEmailAttachment) {
			return RaptorAdapter.getUserBackdoorLoginId(org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "user_id"));
		} else
			return RaptorAdapter.getUserBackdoorLoginId(request);
    }   // getUserBackdoorLoginId

	public boolean isUserInRole(HttpServletRequest request, String roleId) {
		return RaptorAdapter.isCurrentUserInRole(request, roleId);
	}   //  isUserInRole

	public Vector getUserRoles(HttpServletRequest request) {
//		Map map = RaptorAdapter.getAllRoles(userId);
		Set set = RaptorAdapter.getUserRoles(request);

		Vector vector = new Vector(set.size());
		for(Iterator iter=set.iterator(); iter.hasNext(); ) {
			Long key = (Long) iter.next();
			vector.add(""+key);
			//vector.add(new IdNameValue(""+key, (String) map.get(key)));
		}	// for

		return vector;
	}   // getUserRoles

	public Vector getUserRoles(String userId) {
		Set set = RaptorAdapter.getUserRoles(userId);

		Vector vector = new Vector(set.size());
		for(Iterator iter=set.iterator(); iter.hasNext(); ) {
			Long key = (Long) iter.next();
			vector.add(""+key);
			//vector.add(new IdNameValue(""+key, (String) map.get(key)));
		}	// for

		return vector;
		//return null;
	}   // getUserRoles

	public void resetUserCache() {
		//org.openecomp.portalsdk.core.web.support.AppUtils.removeObjectFromCache(RaptorAdapter.KEY_USER_ROLES_CACHE);
	}   // resetUserCache

	public String getSuperRoleID(){
		return superRoleID;
	}   // getSuperRoleID

	public Vector getAdminRoleIDs(){
		return adminRoleIDs;
	}   // getAdminRoleIDs


	public String getTempFolderPath() {
		return tempFolderPath;
	}   // getTempFolderPath

	public String getUploadFolderPath() {
		return uploadFolderPath;
	}   // getUploadFolderPath

	public String getTempFolderURL() {
		return tempFolderURL;
	}   // getTempFolderURL

	public String getUploadFolderURL() {
		return uploadFolderURL;
	}   // getUploadFolderURL

	public String getSMTPServer() {
		return SMTPServer;
	}   // getSMTPServer

	public String getDefaultEmailSender() {
		return defaultEmailSender;
	}   // getDefaultEmailSender

	public String getErrorPage() {
		return errorPage;
	}   // getErrorPage

	public String getJspContextPath() {
		return jspContextPath;
	}   // getJspContextPath

	public String getImgFolderURL() {
		return imgFolderURL;
	}   // getImgFolderURL

	public String getBaseFolderURL() {
		return baseFolderURL;
	}   // getBaseFolderURL

/*	public String getReportExecuteActionURL() {
		return reportExecuteActionURL;
	}   // getReportExecuteActionURL

	public String getDataViewActionURL() {
		return dataViewActionURL;
	}   // getDataViewActionURL

	public String getDataViewActionParam() {
		return dataViewActionParam;
	}   // getDataViewActionParam
*/
	public String getDirectAccessURL() {
		return directAccessURL.trim();
	}   // getDirectAccessURL

	public String getBaseActionURL() {
		return baseActionURL;
	}   // getBaseActionURL

	public String getBaseActionURLNG() {
		return baseActionURLNG;
	}   // getBaseActionURLNG

	public String getDrillActionURL() {
		return drillActionURL;
	}   // getBaseActionURL

	public String getBaseActionParam() {
		return baseActionParam;
	}   // getBaseActionParam

	public Vector getQuickLinksMenuIDs(){
		return quickLinksMenuIDs;
	}   // getQuickLinksMenuIDs

	public String getMenuLabel(String menuId) {
		//return menuId.substring(0, 1).toUpperCase()+menuId.substring(1).toLowerCase();
		return menuId;
	}   // getMenuLabel

	public String getReportDbColsMaskSQL() {
		return null;
/*		Example:
		return	"SELECT f.table_name, UPPER(f.column_name) column_name, f.label "+
				"FROM fields f WHERE f.active_yn = 'Y'"; */
	}   // getReportDbColsMaskSQL

	public String getReportDbLookupsSQL() {
		return null;
/*		Example:
		return	"SELECT DISTINCT f.table_name, UPPER(f.column_name) column_name, f.lookup_table, f.lookup_id_field, f.lookup_name_field "+
				"FROM fields f WHERE f.active_yn = 'Y'"; */
	}   // getReportDbLookupsSQL

 public void processErrorNotification(HttpServletRequest request, RaptorException e) {
		//RaptorAdapter.processErrorNotification(request, e);
}   // processErrorNotification

	public String getErrorPageWMenu() {
		return errorPageWMenu;
	}
	
	public String getExcelTemplatePath() {
		return nvls(raptorAppProperties.getProperty("excel_template_path"), "");
	}
	/**
	 * @return the encryptedSMTPServer
	 */
	public String getEncryptedSMTPServer() {
		return encryptedSMTPServer;
	}
	
    public String getFolderPathAdj(){
    	return nvls(raptorAppProperties.getProperty("folder_path_adj"), "");
    }  	

}   // AppUtils