2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.system.fusion;
22 import java.util.Iterator;
24 import java.util.Properties;
26 import java.util.StringTokenizer;
27 import java.util.Vector;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
32 import org.openecomp.portalsdk.analytics.config.ConfigLoader;
33 import org.openecomp.portalsdk.analytics.error.RaptorException;
34 import org.openecomp.portalsdk.analytics.model.base.IdNameValue;
35 import org.openecomp.portalsdk.analytics.system.Globals;
36 import org.openecomp.portalsdk.analytics.system.IAppUtils;
37 import org.openecomp.portalsdk.analytics.system.fusion.adapter.RaptorAdapter;
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;;
40 public class AppUtils extends org.openecomp.portalsdk.analytics.RaptorObject implements IAppUtils {
42 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppUtils.class);
45 private static String tempFolderPath = "/artemis/PROJECT1/MSA/databank/WEB-INF/temp/";
46 private static String uploadFolderPath = "/artemis/PROJECT1/MSA/databank/WEB-INF/upload/";
47 private static String tempFolderURL = "temp/";
48 private static String uploadFolderURL = "upload/";
49 private static String SMTPServer = "todo.smtp.server.com";
50 private static String defaultEmailSender = "todo.email.sender.com";
51 private static String errorPage = "error_page";
52 private static String errorPageWMenu = "error_page_wmenu";
53 private static String jspContextPath = "raptor/";
54 private static String imgFolderURL = "raptor/images/";
55 private static String baseFolderURL = "raptor/";
56 //private static String reportExecuteActionURL = "dispatcher?action=raptor&r_action=report.run&c_master=";
57 //private static String dataViewActionURL = "dispatcher?action="; // dispatcher?action=ACTION_ID&c_master=REC_ID
58 //private static String dataViewActionParam = "c_master=";
59 private static String directAccessURL = "http://localhost:8082/databank/dispatcher?direct.access=raptor&r_action=report.run&show=";
60 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
61 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
62 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
63 private static String baseActionParam = "c_master=";
64 private static String superRoleID = "1";
65 private static Vector adminRoleIDs = new Vector();
66 private static Vector quickLinksMenuIDs = new Vector();
68 private static Properties raptorAppProperties;
70 private static String encryptedSMTPServer = "";
73 public void initializeAppUtils(ServletContext servletContext) {
75 Properties appProperties = ConfigLoader.getProperties(servletContext, ConfigLoader.APP_PROPERTIES, Globals.getSystemType());
76 raptorAppProperties = appProperties;
77 tempFolderPath = appProperties.getProperty("temp_folder_path");
78 uploadFolderPath = appProperties.getProperty("upload_folder_path");
79 tempFolderURL = appProperties.getProperty("temp_folder_url");
80 uploadFolderURL = appProperties.getProperty("upload_folder_url");
81 SMTPServer = appProperties.getProperty("smtp_server");
82 encryptedSMTPServer = appProperties.getProperty("encrypted_smtp_server");
83 defaultEmailSender = appProperties.getProperty("default_email_sender");
84 errorPage = appProperties.getProperty("error_page");
85 jspContextPath = appProperties.getProperty("jsp_context_path");
86 imgFolderURL = appProperties.getProperty("img_folder_url");
87 baseFolderURL = appProperties.getProperty("base_folder_url");
88 /* reportExecuteActionURL = appProperties.getProperty("report_execute_action_url");
89 dataViewActionURL = appProperties.getProperty("data_view_action_url");
90 dataViewActionParam = appProperties.getProperty("data_view_action_param");*/
91 directAccessURL = appProperties.getProperty("direct_access_url");
92 baseActionURL = appProperties.getProperty("base_action_url");
93 baseActionURLNG = appProperties.getProperty("base_action_url_ng");
94 drillActionURL = appProperties.getProperty("drill_action_url");
95 baseActionParam = appProperties.getProperty("base_action_param");
96 superRoleID = appProperties.getProperty("super_role_id");
98 adminRoleIDs.removeAllElements();
99 StringTokenizer st = new StringTokenizer(appProperties.getProperty("admin_role_ids"), ",");
100 while(st.hasMoreTokens())
101 adminRoleIDs.add(st.nextToken());
103 quickLinksMenuIDs.removeAllElements();
104 st = new StringTokenizer(appProperties.getProperty("quick_links_menu_ids"), ",");
105 while(st.hasMoreTokens())
106 quickLinksMenuIDs.add(st.nextToken());
107 } catch(Exception e) {
108 logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] AppUtils.initializeAppUtils: Unable to load properties ["+Globals.getSystemType()+"_"+ConfigLoader.APP_PROPERTIES+"]. Exception: "+e.getMessage()));
109 //throw new RuntimeException(e.getMessage());
111 } // initializeAppUtils
113 public static void getFullURL(HttpServletRequest req) {
114 String applicationBase = "";
115 if (applicationBase == null) {
116 applicationBase = req.getScheme() + "://" + req.getServerName() +
117 getPort(req) + req.getContextPath();
121 private static String getPort(HttpServletRequest req) {
122 if ("http".equalsIgnoreCase(req.getScheme()) && req.getServerPort() != 80 ||
123 "https".equalsIgnoreCase(req.getScheme()) && req.getServerPort() != 443 ) {
124 return (":" + req.getServerPort());
129 public String getUserID(HttpServletRequest request) {
130 String pdfAttachmentKey = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "pdfAttachmentKey");
131 String report_email_sent_log_id = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "log_id");
132 boolean isEmailAttachment = false;
133 if(pdfAttachmentKey != null && report_email_sent_log_id !=null)
134 isEmailAttachment = true;
135 if(isEmailAttachment) {
136 return RaptorAdapter.getUserID(org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "user_id"));
138 return RaptorAdapter.getUserID(request);
141 public Vector getAllUsers(String customizedQuery, String param, boolean isAdmin) {
142 Map map = RaptorAdapter.getAllUsers(customizedQuery, param, isAdmin);
144 Vector vector = new Vector(map.size());
145 for(Iterator iter=map.keySet().iterator(); iter.hasNext(); ) {
146 Long key = (Long) iter.next();
147 vector.add(new IdNameValue(""+key, (String) map.get(key)));
153 public String getRoleName(String roleId) {
154 return RaptorAdapter.getRoleName(roleId);
157 public Vector getAllRoles(String customizedQuery, String param, boolean isAdmin) {
158 Map map = RaptorAdapter.getAllRolesUsingCustomizedQuery(customizedQuery, param, isAdmin);
160 Vector vector = new Vector(map.size());
161 for(Iterator iter=map.keySet().iterator(); iter.hasNext(); ) {
162 Long key = (Long) iter.next();
163 vector.add(new IdNameValue(""+key, (String) map.get(key)));
169 public String getUserName(HttpServletRequest request) {
170 return RaptorAdapter.getUserName(request);
173 public String getUserName(String userId) {
174 return RaptorAdapter.getUserName(userId);
177 public String getUserEmail(String userId) {
178 return RaptorAdapter.getUserEmail(userId);
181 public String getUserEmail(HttpServletRequest request) {
182 return RaptorAdapter.getUserEmail(request);
185 public String getUserLoginId(HttpServletRequest request) {
186 return RaptorAdapter.getUserLoginId(request);
189 public String getUserLoginId(String userId) {
190 return RaptorAdapter.getUserLoginId(userId);
193 public String getUserBackdoorLoginId(HttpServletRequest request) {
194 String pdfAttachmentKey = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "pdfAttachmentKey");
195 String report_email_sent_log_id = org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "log_id");
196 boolean isEmailAttachment = false;
197 if(pdfAttachmentKey != null && report_email_sent_log_id !=null)
198 isEmailAttachment = true;
199 if(isEmailAttachment) {
200 return RaptorAdapter.getUserBackdoorLoginId(org.openecomp.portalsdk.analytics.system.AppUtils.getRequestValue(request, "user_id"));
202 return RaptorAdapter.getUserBackdoorLoginId(request);
203 } // getUserBackdoorLoginId
205 public boolean isUserInRole(HttpServletRequest request, String roleId) {
206 return RaptorAdapter.isCurrentUserInRole(request, roleId);
209 public Vector getUserRoles(HttpServletRequest request) {
210 // Map map = RaptorAdapter.getAllRoles(userId);
211 Set set = RaptorAdapter.getUserRoles(request);
213 Vector vector = new Vector(set.size());
214 for(Iterator iter=set.iterator(); iter.hasNext(); ) {
215 Long key = (Long) iter.next();
217 //vector.add(new IdNameValue(""+key, (String) map.get(key)));
223 public Vector getUserRoles(String userId) {
224 Set set = RaptorAdapter.getUserRoles(userId);
226 Vector vector = new Vector(set.size());
227 for(Iterator iter=set.iterator(); iter.hasNext(); ) {
228 Long key = (Long) iter.next();
230 //vector.add(new IdNameValue(""+key, (String) map.get(key)));
237 public void resetUserCache() {
238 //org.openecomp.portalsdk.core.web.support.AppUtils.removeObjectFromCache(RaptorAdapter.KEY_USER_ROLES_CACHE);
241 public String getSuperRoleID(){
245 public Vector getAdminRoleIDs(){
250 public String getTempFolderPath() {
251 return tempFolderPath;
252 } // getTempFolderPath
254 public String getUploadFolderPath() {
255 return uploadFolderPath;
256 } // getUploadFolderPath
258 public String getTempFolderURL() {
259 return tempFolderURL;
260 } // getTempFolderURL
262 public String getUploadFolderURL() {
263 return uploadFolderURL;
264 } // getUploadFolderURL
266 public String getSMTPServer() {
270 public String getDefaultEmailSender() {
271 return defaultEmailSender;
272 } // getDefaultEmailSender
274 public String getErrorPage() {
278 public String getJspContextPath() {
279 return jspContextPath;
280 } // getJspContextPath
282 public String getImgFolderURL() {
286 public String getBaseFolderURL() {
287 return baseFolderURL;
288 } // getBaseFolderURL
290 /* public String getReportExecuteActionURL() {
291 return reportExecuteActionURL;
292 } // getReportExecuteActionURL
294 public String getDataViewActionURL() {
295 return dataViewActionURL;
296 } // getDataViewActionURL
298 public String getDataViewActionParam() {
299 return dataViewActionParam;
300 } // getDataViewActionParam
302 public String getDirectAccessURL() {
303 return directAccessURL.trim();
304 } // getDirectAccessURL
306 public String getBaseActionURL() {
307 return baseActionURL;
308 } // getBaseActionURL
310 public String getBaseActionURLNG() {
311 return baseActionURLNG;
312 } // getBaseActionURLNG
314 public String getDrillActionURL() {
315 return drillActionURL;
316 } // getBaseActionURL
318 public String getBaseActionParam() {
319 return baseActionParam;
320 } // getBaseActionParam
322 public Vector getQuickLinksMenuIDs(){
323 return quickLinksMenuIDs;
324 } // getQuickLinksMenuIDs
326 public String getMenuLabel(String menuId) {
327 //return menuId.substring(0, 1).toUpperCase()+menuId.substring(1).toLowerCase();
331 public String getReportDbColsMaskSQL() {
334 return "SELECT f.table_name, UPPER(f.column_name) column_name, f.label "+
335 "FROM fields f WHERE f.active_yn = 'Y'"; */
336 } // getReportDbColsMaskSQL
338 public String getReportDbLookupsSQL() {
341 return "SELECT DISTINCT f.table_name, UPPER(f.column_name) column_name, f.lookup_table, f.lookup_id_field, f.lookup_name_field "+
342 "FROM fields f WHERE f.active_yn = 'Y'"; */
343 } // getReportDbLookupsSQL
345 public void processErrorNotification(HttpServletRequest request, RaptorException e) {
346 //RaptorAdapter.processErrorNotification(request, e);
347 } // processErrorNotification
349 public String getErrorPageWMenu() {
350 return errorPageWMenu;
353 public String getExcelTemplatePath() {
354 return nvls(raptorAppProperties.getProperty("excel_template_path"), "");
357 * @return the encryptedSMTPServer
359 public String getEncryptedSMTPServer() {
360 return encryptedSMTPServer;
363 public String getFolderPathAdj(){
364 return nvls(raptorAppProperties.getProperty("folder_path_adj"), "");