6ee8e5dc4ed01bdbbec0804a24d836453e923949
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalsdk.analytics.system.fusion;
21
22 import java.util.Iterator;
23 import java.util.Map;
24 import java.util.Properties;
25 import java.util.Set;
26 import java.util.StringTokenizer;
27 import java.util.Vector;
28
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31
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;;
39
40 public class AppUtils extends org.openecomp.portalsdk.analytics.RaptorObject implements IAppUtils  {
41         
42         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppUtils.class);
43
44         
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();
67         
68         private static Properties raptorAppProperties;
69
70         private static String encryptedSMTPServer        = "";
71         public AppUtils() {}
72
73         public void initializeAppUtils(ServletContext servletContext) {
74                 try {
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");
97
98                         adminRoleIDs.removeAllElements();
99                         StringTokenizer st = new StringTokenizer(appProperties.getProperty("admin_role_ids"), ",");
100                         while(st.hasMoreTokens())
101                                 adminRoleIDs.add(st.nextToken());
102
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());
110                 }
111         }   // initializeAppUtils
112
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();
118             }
119         }
120
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());
125             } else {
126                 return "";
127             }
128         }       
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"));
137                 } else
138                         return RaptorAdapter.getUserID(request);
139         }   // getUserID
140
141         public Vector getAllUsers(String customizedQuery, String param, boolean isAdmin) {
142                 Map map = RaptorAdapter.getAllUsers(customizedQuery, param, isAdmin);
143
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)));
148                 }       // for
149
150                 return vector;
151         }   // getAllUsers
152
153         public String getRoleName(String roleId) {
154                 return RaptorAdapter.getRoleName(roleId);
155         }   // getRoleName
156
157         public Vector getAllRoles(String customizedQuery, String param, boolean isAdmin) {
158                 Map map = RaptorAdapter.getAllRolesUsingCustomizedQuery(customizedQuery, param, isAdmin);
159
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)));
164                 }       // for
165
166                 return vector;
167         }   // getAllRoles
168
169         public String getUserName(HttpServletRequest request) {
170                 return RaptorAdapter.getUserName(request);
171         }   // getUserName
172
173         public String getUserName(String userId) {
174                 return RaptorAdapter.getUserName(userId);
175         }   // getUserName
176
177         public String getUserEmail(String userId) {
178         return RaptorAdapter.getUserEmail(userId);
179     }   // getUserEmail
180
181         public String getUserEmail(HttpServletRequest request) {
182         return RaptorAdapter.getUserEmail(request);
183     }   // getUserEmail
184     
185         public String getUserLoginId(HttpServletRequest request) {
186                 return RaptorAdapter.getUserLoginId(request);
187         }   // getUserLoginId
188
189         public String getUserLoginId(String userId) {
190                 return RaptorAdapter.getUserLoginId(userId);
191         }   // getUserLoginId
192         
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"));
201                 } else
202                         return RaptorAdapter.getUserBackdoorLoginId(request);
203     }   // getUserBackdoorLoginId
204
205         public boolean isUserInRole(HttpServletRequest request, String roleId) {
206                 return RaptorAdapter.isCurrentUserInRole(request, roleId);
207         }   //  isUserInRole
208
209         public Vector getUserRoles(HttpServletRequest request) {
210 //              Map map = RaptorAdapter.getAllRoles(userId);
211                 Set set = RaptorAdapter.getUserRoles(request);
212
213                 Vector vector = new Vector(set.size());
214                 for(Iterator iter=set.iterator(); iter.hasNext(); ) {
215                         Long key = (Long) iter.next();
216                         vector.add(""+key);
217                         //vector.add(new IdNameValue(""+key, (String) map.get(key)));
218                 }       // for
219
220                 return vector;
221         }   // getUserRoles
222
223         public Vector getUserRoles(String userId) {
224                 Set set = RaptorAdapter.getUserRoles(userId);
225
226                 Vector vector = new Vector(set.size());
227                 for(Iterator iter=set.iterator(); iter.hasNext(); ) {
228                         Long key = (Long) iter.next();
229                         vector.add(""+key);
230                         //vector.add(new IdNameValue(""+key, (String) map.get(key)));
231                 }       // for
232
233                 return vector;
234                 //return null;
235         }   // getUserRoles
236
237         public void resetUserCache() {
238                 //org.openecomp.portalsdk.core.web.support.AppUtils.removeObjectFromCache(RaptorAdapter.KEY_USER_ROLES_CACHE);
239         }   // resetUserCache
240
241         public String getSuperRoleID(){
242                 return superRoleID;
243         }   // getSuperRoleID
244
245         public Vector getAdminRoleIDs(){
246                 return adminRoleIDs;
247         }   // getAdminRoleIDs
248
249
250         public String getTempFolderPath() {
251                 return tempFolderPath;
252         }   // getTempFolderPath
253
254         public String getUploadFolderPath() {
255                 return uploadFolderPath;
256         }   // getUploadFolderPath
257
258         public String getTempFolderURL() {
259                 return tempFolderURL;
260         }   // getTempFolderURL
261
262         public String getUploadFolderURL() {
263                 return uploadFolderURL;
264         }   // getUploadFolderURL
265
266         public String getSMTPServer() {
267                 return SMTPServer;
268         }   // getSMTPServer
269
270         public String getDefaultEmailSender() {
271                 return defaultEmailSender;
272         }   // getDefaultEmailSender
273
274         public String getErrorPage() {
275                 return errorPage;
276         }   // getErrorPage
277
278         public String getJspContextPath() {
279                 return jspContextPath;
280         }   // getJspContextPath
281
282         public String getImgFolderURL() {
283                 return imgFolderURL;
284         }   // getImgFolderURL
285
286         public String getBaseFolderURL() {
287                 return baseFolderURL;
288         }   // getBaseFolderURL
289
290 /*      public String getReportExecuteActionURL() {
291                 return reportExecuteActionURL;
292         }   // getReportExecuteActionURL
293
294         public String getDataViewActionURL() {
295                 return dataViewActionURL;
296         }   // getDataViewActionURL
297
298         public String getDataViewActionParam() {
299                 return dataViewActionParam;
300         }   // getDataViewActionParam
301 */
302         public String getDirectAccessURL() {
303                 return directAccessURL.trim();
304         }   // getDirectAccessURL
305
306         public String getBaseActionURL() {
307                 return baseActionURL;
308         }   // getBaseActionURL
309
310         public String getBaseActionURLNG() {
311                 return baseActionURLNG;
312         }   // getBaseActionURLNG
313
314         public String getDrillActionURL() {
315                 return drillActionURL;
316         }   // getBaseActionURL
317
318         public String getBaseActionParam() {
319                 return baseActionParam;
320         }   // getBaseActionParam
321
322         public Vector getQuickLinksMenuIDs(){
323                 return quickLinksMenuIDs;
324         }   // getQuickLinksMenuIDs
325
326         public String getMenuLabel(String menuId) {
327                 //return menuId.substring(0, 1).toUpperCase()+menuId.substring(1).toLowerCase();
328                 return menuId;
329         }   // getMenuLabel
330
331         public String getReportDbColsMaskSQL() {
332                 return null;
333 /*              Example:
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
337
338         public String getReportDbLookupsSQL() {
339                 return null;
340 /*              Example:
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
344
345  public void processErrorNotification(HttpServletRequest request, RaptorException e) {
346                 //RaptorAdapter.processErrorNotification(request, e);
347 }   // processErrorNotification
348
349         public String getErrorPageWMenu() {
350                 return errorPageWMenu;
351         }
352         
353         public String getExcelTemplatePath() {
354                 return nvls(raptorAppProperties.getProperty("excel_template_path"), "");
355         }
356         /**
357          * @return the encryptedSMTPServer
358          */
359         public String getEncryptedSMTPServer() {
360                 return encryptedSMTPServer;
361         }
362         
363     public String getFolderPathAdj(){
364         return nvls(raptorAppProperties.getProperty("folder_path_adj"), "");
365     }   
366
367 }   // AppUtils