summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/system/AppUtils.java
blob: 2b87b1ae3e2a6af80c50e4e418a7e6d63b34b5c0 (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
/*-
 * ================================================================================
 * 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;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.http.*;

import org.openecomp.portalsdk.analytics.error.RaptorException;
import org.openecomp.portalsdk.analytics.util.*;

public class AppUtils /* implements IAppUtils */{
	private static String baseURL = null;

	private AppUtils() {
	}

	/** ******************************************************** */

	public static String generateFileName(HttpServletRequest request, String fileTypeExtension) {
		return AppConstants.FILE_PREFIX + getUserID(request) + fileTypeExtension;
	} // generateFileName

	public static String generateUniqueFileName(HttpServletRequest request, String reportName, String fileTypeExtension) {
        String formattedReportName = new HtmlStripper().stripSpecialCharacters(reportName);
        String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
		return formattedReportName+formattedDate+getUserID(request)+fileTypeExtension;
	} // generateFileName
	
	public static String getRequestValue(HttpServletRequest request, String valueID) {
		String value = (String) request.getAttribute(valueID);
		if (value == null)
			value = request.getParameter(valueID);
		return value;
	} // getRequestValue

	public static String getRequestNvlValue(HttpServletRequest request, String valueID) {
		String value = getRequestValue(request, valueID);
		return (value == null) ? "" : value;
	} // getRequestValue

	public static boolean getRequestFlag(HttpServletRequest request, String valueID) {
		String value = getRequestNvlValue(request, valueID);
		return value.toLowerCase().equals("true") || value.toUpperCase().startsWith("Y");
	} // getRequestFlag

	/** ******************************************************** */

	public static String getUserID(HttpServletRequest request) {
		return Globals.getAppUtils().getUserID(request);
	} // getUserID

	public static String getUserName(HttpServletRequest request) {
		return Globals.getAppUtils().getUserName(request);
	} // getUserName

	public static String getUserName(String userId) {
		return Globals.getAppUtils().getUserName(userId);
	} // getUserName

	public static String getUserEmail(String userId) {
        return Globals.getAppUtils().getUserEmail(userId);
    } // getUserEmail
 
	public static String getUserEmail(HttpServletRequest request) {
        return Globals.getAppUtils().getUserEmail(request);
    } // getUserEmail

	public static String getUserLoginId(HttpServletRequest request) {
		return Globals.getAppUtils().getUserLoginId(request);
	} // getUserLoginId

    public static String getUserLoginId(String userId) {
		return Globals.getAppUtils().getUserLoginId(userId);
	} // getUserLoginId

    public static String getUserBackdoorLoginId(HttpServletRequest request) {
        return Globals.getAppUtils().getUserBackdoorLoginId(request);
    } // getUserBackdoorLoginId
    
    public static Vector getAllUsers(String customizedQuery, String param, boolean isAdmin) {
		return Globals.getAppUtils().getAllUsers(customizedQuery, param, isAdmin);
	} // getAllUsers

	public static String getRoleName(String roleId) {
		return Globals.getAppUtils().getRoleName(roleId);
	} // getRoleName

	public static Vector getAllRoles(String customizedQuery, String param, boolean isAdmin) {
		return Globals.getAppUtils().getAllRoles(customizedQuery, param, isAdmin);
	} // getAllRoles

	public static boolean isUserInRole(HttpServletRequest request, String roleId) throws RaptorException {
		return Globals.getAppUtils().isUserInRole(request,roleId);
	} // isUserInRole

//	public static boolean isUserInRole(String userId, String roleId) throws RaptorException {
//		return Globals.getAppUtils().isUserInRole(userId, roleId);
//	} // isUserInRole

	public static Vector getUserRoles(HttpServletRequest request) throws RaptorException {
		return Globals.getAppUtils().getUserRoles(request);
	} // getUserRoles

	public static Vector getUserRoles(String userID) throws RaptorException {
		return Globals.getAppUtils().getUserRoles(userID);
	} // getUserRoles
	
//	public static Vector getUserRoles(HttpServletRequest request) throws RaptorException {
//		return Globals.getAppUtils().getUserRoles(request);
//	} // getUserRoles

	public static void resetUserCache() {
		Globals.getAppUtils().resetUserCache();
	} // resetUserCache

	public static String getSuperRoleID() {
		return Globals.getAppUtils().getSuperRoleID();
	} // getSuperRoleID

	public static Vector getAdminRoleIDs() {
		return Globals.getAppUtils().getAdminRoleIDs();
	} // getAdminRoleIDs

    // This is changed to check for Admin User as admin user also need super user privilege if explicitly specified in properties file.	
	public static boolean isSuperUser(HttpServletRequest request)throws RaptorException {
		if(Globals.isAdminRoleEquivalenttoSuperRole()) return isAdminUser(request);
		else return isUserInRole(request, getSuperRoleID());
	} // isSuperUser

	/*public static boolean isSuperUser(String userId)  throws RaptorException {
		if(Globals.isAdminRoleEquivalenttoSuperRole()) return isAdminUser(userId);
		else return isUserInRole(userId, getSuperRoleID());
	} // isSuperUser
	*/

	public static boolean isAdminUser(HttpServletRequest request) throws RaptorException {
		if (isSuperUser(request))
			return true;
		for (int i = 0; i < getAdminRoleIDs().size(); i++)
			if (isUserInRole(request, (String) getAdminRoleIDs().get(i)))
				return true;

		return false;
	} // isAdminUser

	/*public static boolean isAdminUser(String userId) throws RaptorException {
		if (isSuperUser(userId))
			return true;

		for (int i = 0; i < getAdminRoleIDs().size(); i++)
			if (isUserInRole(userId, (String) getAdminRoleIDs().get(i)))
				return true;

		return false;
	} // isAdminUser
	*/

	public static String getTempFolderPath() {
		String path = Globals.getAppUtils().getTempFolderPath();
        if (path.endsWith(File.separator) || path.endsWith("/")){
          return path;
        } else {
          path = path + File.separator;
          return path;
        }
	} // getTempFolderPath

	public static String getUploadFolderPath() {
        String path = Globals.getAppUtils().getUploadFolderPath();
        if (path.endsWith(File.separator)){
            return path;
          } else {
            path = path + File.separator;
            return path;
          }        
	} // getUploadFolderPath

	public static String getTempFolderURL() {
		return Globals.getAppUtils().getTempFolderURL();
	} // getTempFolderURL

	public static String getUploadFolderURL() {
		return Globals.getAppUtils().getUploadFolderURL();
	} // getUploadFolderURL

	public static String getSMTPServer()throws Exception {
		return Globals.getAppUtils().getSMTPServer();
	} // getSMTPServer

	public static String getDefaultEmailSender() throws RaptorException {
		return Globals.getAppUtils().getDefaultEmailSender();
	} // getDefaultEmailSender

	public static String getErrorPage() {
		return getJspContextPath() + Globals.getAppUtils().getErrorPage();
	} // getErrorPage

	public static String getErrorPageWMenu() {
		return getJspContextPath() + Globals.getAppUtils().getErrorPageWMenu();
	} // getErrorPage
	
	public static String getJspContextPath() {
		return Globals.getAppUtils().getJspContextPath();
	} // getJspContextPath

	public static String getImgFolderURL() {
		return Globals.getAppUtils().getImgFolderURL();
	} // getImgFolderURL

	public static String getBaseFolderURL() {
		return Globals.getAppUtils().getBaseFolderURL();
	} // getBaseFolderURL

	public static String getChartScriptsPath() {
		return getFolderPathAdj()+getBaseFolderURL();
	} // getBaseFolderURL
	
	public static String getChartScriptsPath(String folderAdj1) {
		return folderAdj1+getBaseFolderURL();
	} // getBaseFolderURL	

	public static String getFolderPathAdj() {
		return Globals.getAppUtils().getFolderPathAdj();
	} // getBaseFolderURL


	/*
	 * public static String getReportExecuteActionURL() { return
	 * Globals.getAppUtils().getReportExecuteActionURL(); } //
	 * getReportExecuteActionURL
	 * 
	 * public static String getDataViewActionURL() { return
	 * Globals.getAppUtils().getDataViewActionURL(); } // getDataViewActionURL
	 * 
	 * public static String getDataViewActionParam() { return
	 * Globals.getAppUtils().getDataViewActionParam(); } //
	 * getDataViewActionParam
	 */
	public static String getDirectAccessURL() {
		return Globals.getAppUtils().getDirectAccessURL();
	} // getDirectAccessURL

	public static String getBaseURL() {
		if (baseURL == null) {
			baseURL = getBaseActionURL();
			if (baseURL.indexOf("?") > 0)
				baseURL = baseURL.substring(0, baseURL.indexOf("?"));
		} // if

		return baseURL;
	} // getBaseURL

	public static String getBaseActionURL() {
		return Globals.getAppUtils().getBaseActionURL();
	} // getBaseActionURL

	public static String getDrillActionURL() {
		return Globals.getAppUtils().getDrillActionURL();
	} // getBaseActionURL
	
	public static String getRaptorActionURL() {
		return Globals.getAppUtils().getBaseActionURL() + "raptor&" + AppConstants.RI_ACTION
				+ "=";
	} // getRaptorActionURL

	public static String getRaptorActionURLNG() {
		return Globals.getAppUtils().getBaseActionURLNG();
	} // getRaptorActionURL

	public static String getReportExecuteActionURL() {
		return getRaptorActionURL() + "report.run.container&" + AppConstants.RI_REPORT_ID + "="; // getBaseActionParam();
	} // getReportExecuteActionURL

	public static String getReportExecuteActionURLNG() {
		return getRaptorActionURLNG() + "report_run/"; // getBaseActionParam();
	} // getReportExecuteActionURL

	public static String getBaseActionParam() {
		return Globals.getAppUtils().getBaseActionParam();
	} // getBaseActionParam

	public static Vector getQuickLinksMenuIDs() {
		return Globals.getAppUtils().getQuickLinksMenuIDs();
	} // getQuickLinksMenuIDs

	public static String getMenuLabel(String menuId) {
		return Globals.getAppUtils().getMenuLabel(menuId);
	} // getMenuLabel

	public static String getReportDbColsMaskSQL() {
		return Globals.getAppUtils().getReportDbColsMaskSQL();
	} // getReportDbColsMaskSQL

	public static String getReportDbLookupsSQL() {
		return Globals.getAppUtils().getReportDbLookupsSQL();
	} // getReportDbLookupsSQL

	public static void processErrorNotification(HttpServletRequest request, RaptorException e) {
		Globals.getAppUtils().processErrorNotification(request, e);
	} // processErrorNotification

	public static String getExcelTemplatePath() {
		String path = Globals.getAppUtils().getExcelTemplatePath();
        if (path.endsWith(File.separator)){
          return path;
        } else {
          path = path + File.separator;
          return path;
        }
	} // getTempFolderPath
	
	public static String nvl(String s) {
		return (s == null) ? "" : s;
	}

	public static boolean isNotEmpty(String s) {
		return nvl(s).length()>0;
	}
	public static String nvls(String s, String sDefault) {
		return nvl(s).equals("") ? sDefault : s;
	}
	
} // AppUtils