001: /*********************************************************************************
002: * The contents of this file are subject to the OpenI Public License Version 1.0
003: * ("License"); You may not use this file except in compliance with the
004: * License. You may obtain a copy of the License at
005: * http://www.openi.org/docs/LICENSE.txt
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is: OpenI Open Source
012: *
013: * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
014: * Portions created by Loyalty Matrix, Inc. are
015: * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
016: *
017: * Contributor(s): i18n: Pedro Casals Fradera (2006/05/12, 2006/11/10)
018: *
019: ********************************************************************************/package org.openi.project;
020:
021: import java.io.Serializable;
022: import java.util.ArrayList;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.LinkedList;
026: import java.util.List;
027: import java.util.Locale;
028: import java.util.Map;
029: import java.util.ResourceBundle;
030:
031: import org.openi.application.Application;
032: import org.openi.menu.Menu;
033: import org.openi.menu.MenuItem;
034: import org.openi.util.Util;
035:
036: /**
037: * configuration file for Project
038: */
039: public class Project implements Serializable {
040: private String projectId;
041: private String projectName;
042: private String externalUrl;
043: private String cssName;
044: private String logoUrl; // i.e. - images/openidemo.jpg
045: private String splashImageUrl; //if splashPage is null, use this image as splash page.
046: private String splashPage = "splash.htm"; //link, notice this functionality is changed, it is now just a link
047: private List modules;
048: private Map dataSourceMap;
049: private String category;
050: private String message; // used in place of date in header i.e. - "data loaded as of 7/22/2005"
051: private Map menuConfig;
052: private boolean customText;
053: private transient List projectMenu;
054: //PCF: i18n
055: private transient boolean menuTranslated;
056:
057: /**
058: * keys - name of color palette
059: * value - List of Paint objects representing a palette
060: */
061: private Map colorPaletteMap;
062: private String defaultPaletteName;
063:
064: /**
065: * comma separated list of Project Admins
066: */
067: private String projectAdmins;
068:
069: /**
070: * comma separated list of Project Users
071: */
072: private String projectUsers;
073:
074: /**
075: * comma separated list of Project read only Users
076: */
077: private String projectReadOnlyUsers;
078:
079: /**
080: * header footer used by print servlet
081: */
082: private Map jdbcMap;
083:
084: // private String reportHeader;
085: //private String reportFooter;
086: private boolean writeImageMap = true;
087:
088: /**
089: * Map of overviews
090: * key: title
091: * value: Overview, which contains a list of links (e.g. - public/Samples/MSAS/HR_Employees.analysis)
092: */
093: private Map overviews = new HashMap();
094:
095: // roles map containg members list for each role - not APP_ADMINISTRATOR, PROJ_ADMINISTRATOR, PORJ_USER
096: private Map roleMembers;
097:
098: // enables openi based multiple filter selection
099: private boolean multipleFilterSelection = false;
100:
101: // TODO: protect to allow centralized caching?
102: public Project() {
103: }
104:
105: /**
106: * @return Returns the cssName.
107: */
108: public String getCssName() {
109: return cssName;
110: }
111:
112: /**
113: * @param cssName The cssName to set.
114: */
115: public void setCssName(String cssName) {
116: this .cssName = cssName;
117: }
118:
119: /**
120: * @return Returns the externalUrl.
121: */
122: public String getExternalUrl() {
123: return externalUrl;
124: }
125:
126: /**
127: * @param externalUrl The externalUrl to set.
128: */
129: public void setExternalUrl(String externalUrl) {
130: this .externalUrl = externalUrl;
131: }
132:
133: /**
134: * @return Returns the projectHomeDir.
135: */
136:
137: /**
138: * @return Returns the projectId.
139: */
140: public String getProjectId() {
141: return projectId;
142: }
143:
144: /**
145: * @param projectId The projectId to set.
146: */
147: public void setProjectId(String projectId) {
148: this .projectId = projectId;
149: }
150:
151: /**
152: * @return Returns the projectName.
153: */
154: public String getProjectName() {
155: return projectName;
156: }
157:
158: /**
159: * @param projectName The projectName to set.
160: */
161: public void setProjectName(String projectName) {
162: this .projectName = projectName;
163: }
164:
165: /**
166: * @return Returns the modules.
167: */
168: public List getModules() {
169: return modules;
170: }
171:
172: /**
173: * @param modules The modules to set.
174: */
175: public void setModules(List modules) {
176: this .modules = modules;
177: }
178:
179: /**
180: * @return Returns the logoUrl.
181: */
182: public String getLogoUrl() {
183: return logoUrl;
184: }
185:
186: /**
187: * @param logoUrl The logoUrl to set.
188: */
189: public void setLogoUrl(String logoUrl) {
190: this .logoUrl = logoUrl;
191: }
192:
193: /**
194: * @return Returns the splashImageUrl.
195: */
196: public String getSplashImageUrl() {
197: return splashImageUrl;
198: }
199:
200: /**
201: *
202: * @return Map of dataSource
203: */
204: public Map getDataSourceMap() {
205: return dataSourceMap;
206: }
207:
208: /**
209: *
210: * @param splashImageUrl The splashImageUrl to set.
211: */
212: public void setSplashImageUrl(String splashImageUrl) {
213: this .splashImageUrl = splashImageUrl;
214: }
215:
216: /**
217: *
218: * @param dataSource Map
219: */
220: public void setDataSourceMap(Map dataSource) {
221: this .dataSourceMap = dataSource;
222: }
223:
224: /**
225: * @return Returns the colorPaletteMap.
226: */
227: public Map getColorPaletteMap() {
228: // return colorPaletteMap;
229: /*
230: colorPaletteMap = new HashMap();
231: List monochrome = new ArrayList();
232: monochrome.add(new Color(249, 219, 224));
233: monochrome.add(new Color(167, 70, 97));
234: monochrome.add(new Color(189, 117, 137));
235: monochrome.add(new Color(212, 163, 177));
236: monochrome.add(new Color(233, 209, 215));
237: monochrome.add(new Color(142, 60, 82));
238: monochrome.add(new Color(125, 53, 73));
239: monochrome.add(new Color(84, 35, 49));
240: colorPaletteMap.put("monochrome", monochrome);
241: List nemo = new ArrayList();
242: nemo.add(new Color( 255, 140, 0));
243: nemo.add(new Color( 0, 0, 205));
244: nemo.add(new Color( 135, 206, 250));
245: nemo.add(new Color( 153, 50, 204));
246: nemo.add(new Color( 0, 153, 102));
247: nemo.add(new Color( 255, 255, 102));
248: colorPaletteMap.put("nemo", nemo);
249: */
250: return this .colorPaletteMap;
251: }
252:
253: /**
254: *
255: * @return String
256: */
257: public String getProjectUsers() {
258: return projectUsers;
259: }
260:
261: /**
262: *
263: * @return String
264: */
265: public String getProjectAdmins() {
266: return projectAdmins;
267: }
268:
269: /**
270: *
271: * @return String
272: */
273: public String getProjectReadOnlyUsers() {
274: return projectReadOnlyUsers;
275: }
276:
277: /**
278: * @param colorPaletteMap The colorPaletteMap to set.
279: */
280: public void setColorPaletteMap(Map colorPaletteMap) {
281: this .colorPaletteMap = colorPaletteMap;
282: }
283:
284: public void setProjectUsers(String projectUsers) {
285: this .projectUsers = projectUsers;
286: }
287:
288: public void setProjectAdmins(String pojectAdmins) {
289: this .projectAdmins = pojectAdmins;
290: }
291:
292: public void setProjectReadOnlyUsers(String projectReadOnlyUsers) {
293: this .projectReadOnlyUsers = projectReadOnlyUsers;
294: }
295:
296: public List getColorPalette(String colorPaletteName) {
297: List palette = null;
298:
299: if (colorPaletteName != null) {
300: palette = (List) this .getColorPaletteMap().get(
301: colorPaletteName);
302: }
303:
304: return palette;
305: }
306:
307: /**
308: * @return Returns the defaultPaletteName.
309: */
310: public String getDefaultPaletteName() {
311: return defaultPaletteName;
312: }
313:
314: /**
315: * @param defaultPaletteName The defaultPaletteName to set.
316: */
317: public void setDefaultPaletteName(String defaultPaletteName) {
318: this .defaultPaletteName = defaultPaletteName;
319: }
320:
321: /**
322: * Checks whether the user is in comma separated list of project users.
323: * @param userName String
324: * @return boolean
325: */
326: public boolean validateUser(String userName) {
327: return Util.isItemInList(userName, projectUsers);
328: }
329:
330: /**
331: * Checks whether the user in in comma seperated list of read only users
332: * @param userName
333: * @return
334: */
335: public boolean validateReadOnlyUser(String userName) {
336: return Util.isItemInList(userName, this .projectReadOnlyUsers);
337: }
338:
339: /**
340: * Checks whether the user in in comma seperated list of user defined roles
341: * @param userName
342: * @return
343: */
344: public boolean validateUserDefinedRoleMember(String userName) {
345: // for user defined role's members
346: Map members = this .getRoleMembers();
347: String otherUsers = null;
348: if (members != null
349: && Application.getInstance().getSecurityRoles() != null) {
350: String roles = Application.getInstance().getSecurityRoles();
351: if (roles.length() != 0) {
352: String roleArr[] = roles.split(",");
353: for (int i = 0; i < roleArr.length; i++) {
354: String users = (String) members.get(roleArr[i]);
355: if (users != null && !"".equals(users)) {
356: if (otherUsers == null)
357: otherUsers = users;
358: else
359: otherUsers = otherUsers + "," + users;
360: }
361: }
362: }
363: }
364: if (otherUsers == null)
365: return false;
366: return Util.isItemInList(userName, otherUsers);
367: }
368:
369: /**
370: * Checks whether the user is in comma separated list of project admins.
371: * @param userName String
372: * @return boolean
373: */
374: public boolean validateAdmin(String userName) {
375: return Util.isItemInList(userName, projectAdmins);
376: }
377:
378: /**
379: * @return Returns the category.
380: */
381: public String getCategory() {
382: return category;
383: }
384:
385: public String getSplashPage() {
386: return splashPage;
387: }
388:
389: /**
390: * @param category The category to set.
391: */
392: public void setCategory(String category) {
393: this .category = category;
394: }
395:
396: public void setSplashPage(String splashPage) {
397: this .splashPage = splashPage;
398: }
399:
400: /**
401: * @return Returns the message.
402: */
403: public String getMessage() {
404: return message;
405: }
406:
407: /**
408: * @param message The message to set.
409: */
410: public void setMessage(String message) {
411: this .message = message;
412: }
413:
414: /**
415: * @return Returns the writeImageMap.
416: */
417: public boolean getWriteImageMap() {
418: return writeImageMap;
419: }
420:
421: /**
422: * @param writeImageMap The writeImageMap to set.
423: */
424: public void setWriteImageMap(boolean writeImageMap) {
425: this .writeImageMap = writeImageMap;
426: }
427:
428: public Map getMenuConfig(Locale locale) {
429: if (menuConfig == null) {
430: this .menuConfig = this .createDefaultAdminMenuConfig();
431:
432: }
433:
434: //Setting locales
435: ResourceBundle res = ResourceBundle.getBundle(
436: "org.openi.labels", locale);
437: Iterator it = menuConfig.values().iterator();
438: while (it.hasNext()) {
439: List lst = (List) it.next();
440: Iterator mnuIt = lst.iterator();
441: while (mnuIt.hasNext()) {
442: MenuItem item = (MenuItem) mnuIt.next();
443:
444: String sDispl;
445: try {
446: sDispl = res.getString("java_Project.adminmenu."
447: + item.getIdItem());
448: } catch (Exception e) {
449: sDispl = item.getDisplayName();
450: }
451: item.setDisplayName(sDispl);
452: }
453: }
454:
455: return menuConfig;
456: }
457:
458: public void setMenuConfig(Map menuConfig) {
459: this .menuConfig = menuConfig;
460: }
461:
462: public Map getJdbcMap() {
463: return this .jdbcMap;
464: }
465:
466: public void setJdbcMap(Map jdbcMap) {
467: this .jdbcMap = jdbcMap;
468: }
469:
470: /**
471: * extract and move to configuration
472: * @return
473: */
474: private Map createDefaultAdminMenuConfig() {
475: Map config = new HashMap();
476: //PCF
477: List appAdminList = new LinkedList();
478: appAdminList.add(new MenuItem("Manage_Application",
479: "editapplication.htm"));
480: appAdminList
481: .add(new MenuItem("Manage_menus", "menuconfig.htm"));
482: config.put("appAdminList", appAdminList);
483:
484: List projectAdminList = new LinkedList();
485: projectAdminList.add(new MenuItem("Manage_Project",
486: "editproject.htm"));
487: projectAdminList.add(new MenuItem("Configure_Datasource",
488: "datasource.htm"));
489: projectAdminList.add(new MenuItem("project_download",
490: "project_download.htm"));
491:
492: projectAdminList.add(new MenuItem("R_Functions",
493: "managerfunction.htm"));
494:
495: config.put("projectAdminList", projectAdminList);
496:
497: List projectUserList = new LinkedList();
498: projectUserList.add(new MenuItem("Manage_Files",
499: "managefiles.htm"));
500: projectUserList.add(new MenuItem("Upload_File",
501: "uploadfile.htm"));
502: projectUserList.add(new MenuItem("Create_New_Analysis",
503: "newanalysis.htm"));
504: projectUserList.add(new MenuItem("Manage_Dashboards",
505: "manageoverview.htm"));
506: projectUserList.add(new MenuItem("autogenerate",
507: "autogenerate.htm"));
508: projectUserList.add(new MenuItem("Manage_Segments",
509: "segment.htm"));
510: projectUserList.add(new MenuItem("User_Administration",
511: "user.htm"));
512:
513: config.put("projectUserList", projectUserList);
514:
515: return config;
516: }
517:
518: public Map getOverviews() {
519: return overviews;
520: }
521:
522: public void setOverviews(Map overviews) {
523: this .overviews = overviews;
524: }
525:
526: public Overview getOverview(String key) {
527: return (Overview) this .overviews.get(key);
528: }
529:
530: public void removeOverview(String overviewKey) {
531: this .overviews.remove(overviewKey);
532:
533: }
534:
535: /**
536: * returns project specific menu list containing list of Menu or MenuItem
537: * @return
538: */
539: public List getProjectMenu(Locale locale) {
540: ResourceBundle res = ResourceBundle.getBundle(
541: "org.openi.labels", locale);
542: if (!menuTranslated) {
543: Menu adminMenu = new Menu(
544: res
545: .getString("java_ProjectContext.adminmenu.Administration"));
546: projectMenu = new ArrayList();
547: projectMenu.add(adminMenu);
548: List children = new ArrayList();
549: for (Iterator iter = this .getMenuConfig(locale).values()
550: .iterator(); iter.hasNext();) {
551: List vals = (List) iter.next();
552: if (vals != null) {
553: for (Iterator iter1 = vals.iterator(); iter1
554: .hasNext();) {
555: Object item = iter1.next();
556: if (item instanceof Menu)
557: children.add(((Menu) item).clone());
558: else
559: children.add(((MenuItem) item).clone());
560: }
561: }
562:
563: }
564: adminMenu.setChildNodes(children);
565: menuTranslated = true;
566: }
567:
568: /* PCF: needed??
569: if(projectMenu == null) return null;
570:
571: for(Iterator iter = this.projectMenu.iterator(); iter.hasNext();) {
572: Object item = iter.next();
573:
574: if (item instanceof MenuItem) {
575: String sDispl;
576: try {
577: sDispl = res.getString("java_Project.adminmenu." + ((MenuItem)item).getIdItem());
578: } catch(Exception e) {
579: sDispl = ((MenuItem)item).getDisplayName();
580: }
581: ((MenuItem)item).setDisplayName(sDispl);
582: }
583: }
584: */
585: return projectMenu;
586: }
587:
588: /**
589: * sets project specific menu list containing list of Menu or MenuItem
590: * @param projectMenu
591: */
592: public void setProjectMenu(List projectMenu) {
593: this .projectMenu = projectMenu;
594: }
595:
596: /**
597: * returns map containing role name as key and users list as value
598: * @return
599: */
600: public Map getRoleMembers() {
601: return roleMembers;
602: }
603:
604: public void setRoleMembers(Map roleMembers) {
605: this .roleMembers = roleMembers;
606: }
607:
608: public boolean isMultipleFilterSelection() {
609: return multipleFilterSelection;
610: }
611:
612: public void setMultipleFilterSelection(
613: boolean multipleFilterSelection) {
614: this .multipleFilterSelection = multipleFilterSelection;
615: }
616:
617: public boolean isCustomText() {
618: return customText;
619: }
620:
621: public void setCustomText(boolean customText) {
622: this.customText = customText;
623: }
624:
625: }
|