public String getFirstContactID() throws NotesException { if (!firstContactIDRead) { Database db = ExtLibUtil.getCurrentDatabase(); View view = db.getView("AllContacts"); Document doc = view.getFirstDocument(); if (doc != null) { firstContactID = doc.getNoteID(); } } return firstContactID; }
/** Read the snippet categories */ public String[] getAllCategories() throws NotesException { Database db = ExtLibUtil.getCurrentDatabase(); View v = db.getView("AllSnippets"); ViewNavigator nav = v.createViewNav(); try { nav.setMaxLevel(0); // nav.setCacheSize(128); List<String> categories = new ArrayList<String>(); for (ViewEntry ve = nav.getFirst(); ve != null; ve = nav.getNext(ve)) { categories.add((String) ve.getColumnValues().get(0)); } return categories.toArray(new String[categories.size()]); } finally { nav.recycle(); } }
private RootNode readSnippetsNodes() throws NotesException { Database db = ExtLibUtil.getCurrentDatabase(); View v = db.getView("AllSnippetsFlat"); try { RootNode root = new RootNode(); String snippetSearch = (String) ExtLibUtil.getViewScope().get("snippetSearch"); if (StringUtil.isNotEmpty(snippetSearch)) { v.FTSearch(snippetSearch); ViewEntryCollection col = v.getAllEntries(); for (ViewEntry e = col.getFirstEntry(); e != null; e = col.getNextEntry()) { Vector<?> values = e.getColumnValues(); String unid = e.getUniversalID(); String cat = (String) values.get(0); String name = (String) values.get(1); String jspUrl = (String) values.get(2); CategoryNode c = findCategory(root, cat); SnippetNode snippet = new SnippetNode(c, name, cat, unid, jspUrl); c.getChildren().add(snippet); } } else { v.setAutoUpdate(false); ViewNavigator nav = v.createViewNav(); nav.setBufferMaxEntries(500); for (ViewEntry e = nav.getFirst(); e != null; e = nav.getNext()) { Vector<?> values = e.getColumnValues(); String unid = e.getUniversalID(); String cat = (String) values.get(0); String name = (String) values.get(1); String jspUrl = (String) values.get(2); CategoryNode c = findCategory(root, cat); SnippetNode snippet = new SnippetNode(c, name, cat, unid, findUniqueUrl(c, unid, jspUrl)); c.getChildren().add(snippet); } } return root; } finally { v.recycle(); } }
/** * This will display an error page to the user. The error page must be in a view in the current * Database with the name matching the value of EXCEPTION_VIEW. The key of the document in the * view is the same as the class of the exception that is calling this method. * * @param - contextDoc Document , the context document. */ public void showExceptionWebPage(Document contextDoc) { try { Database db = contextDoc.getParentDatabase(); View view = db.getView(EXCEPTION_VIEW); if (view != null) { Document errorPage = view.getDocumentByKey(EXCEPTION_KEY); if (errorPage != null) { contextDoc.replaceItemValue( "$$Return", "[/" + db.getFilePath() + "/" + EXCEPTION_VIEW + "/" + EXCEPTION_KEY + "?OpenDocument]"); } } } catch ( NotesException e) {; /// Do nothing if the database doesn't have an exception page for this exception } }
/* * Reload the application configuration by reading the settings document */ public void reload() { Database dbCurrent = null; View vwAllByType = null; Document docSettings = null; try { Session sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbCurrent = sessionAsSigner.getCurrentDatabase(); vwAllByType = dbCurrent.getView("vwAllByType"); docSettings = vwAllByType.getDocumentByKey("fSettings", true); if (docSettings == null) { System.out.println("could not read settings document"); } else { String dataVersion = docSettings.getItemValueString("dataVersion"); if (!dataVersion.equals(DATA_VERSION)) { convert(dataVersion, DATA_VERSION, dbCurrent, vwAllByType, docSettings); } serverName = dbCurrent.getServer(); continuityDbPath = dbCurrent.getFilePath(); continuityDbUrl = "/" + continuityDbPath.replace("\\", "/"); settingsUnid = docSettings.getUniversalID(); organisationName = docSettings.getItemValueString("organisationName"); organisationId = docSettings.getItemValueString("organisationId"); directoryDbPath = docSettings.getItemValueString("directoryDbPath"); unpluggedDbPath = docSettings.getItemValueString("unpluggedDbPath"); callTreeType = docSettings.getItemValueString("callTreeType"); if (callTreeType.length() == 0) { callTreeType = CALLTREE_TYPE_ROLE; // default: role based } senderEmail = docSettings.getItemValueString("senderEmail"); senderName = docSettings.getItemValueString("senderName"); // defaults if (senderEmail.length() == 0) { senderEmail = "*****@*****.**"; } if (senderName.length() == 0) { senderName = "Continuity"; } // labels String riskNaming = docSettings.getItemValueString("riskNaming"); String incidentNaming = docSettings.getItemValueString("incidentNaming"); if (riskNaming.equals("activities")) { labels.put("assets", "Activities"); labels.put("asset", "Activity"); } else if (riskNaming.equals("sites")) { labels.put("assets", "Sites"); labels.put("asset", "Site"); } else if (riskNaming.equals("locations")) { labels.put("assets", "Locations"); labels.put("asset", "Location"); } else { labels.put("assets", "Assets"); labels.put("asset", "Asset"); } if (incidentNaming.equals("crises")) { labels.put("incidents", "Crises"); labels.put("incident", "Crisis"); } else if (incidentNaming.equals("emergencies")) { labels.put("incidents", "Emergencies"); labels.put("incident", "Emergency"); } else { labels.put("incidents", "Incidents"); labels.put("incident", "Incident"); } labels.put("miniConfigGuide", getMiniConfigGuide()); labels.put("contactsImportGuide", getContactsImportGuide()); } } catch (Exception e) { e.printStackTrace(); } finally { Utils.recycle(docSettings, vwAllByType, dbCurrent); } }
// removes the specified applications for the user from Unplugged @SuppressWarnings("unchecked") public static void deleteApplication(String userName, Vector<String> appPaths) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docUser = null; View vwUsers = null; Name nmUser = null; Document docApp = null; try { Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); nmUser = sessionAsSigner.createName(userName); // get all application documents for this user DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)"); Document docTemp = null; int numRemoved = 0; // update app documents docApp = dcApp.getFirstDocument(); while (null != docApp) { String path = docApp.getItemValueString("Path"); if (appPaths.contains(path)) { // remove application Vector<String> appUsers = docApp.getItemValue("UserName"); Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing"); appUsers.remove(nmUser.getCanonical()); docApp.replaceItemValue("UserName", appUsers); docApp.computeWithForm(true, true); docApp.save(); numRemoved++; } docTemp = dcApp.getNextDocument(docApp); docApp.recycle(); docApp = docTemp; } if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config Logger.info( "Unplugged user " + nmUser.getCanonical() + " removed from all applications - remove user config"); // check for user account vwUsers = dbUnplugged.getView(USERS_VIEW); docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true); if (docUser != null) { docUser.remove(true); Logger.info("removed Unplugged user " + nmUser.getCanonical()); } } } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner); } }
/* * Create an Unplugged application definition in the Unplugged database * and add the specified user to it. The user is created if Unplugged * if he doesn't exist yet. */ @SuppressWarnings("unchecked") public static boolean createApplication(String userName, String appPath, boolean isActive) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docApp = null; Document docUser = null; View vwUsers = null; Name nmUser = null; try { String correctedPath = appPath.replace("\\", "/"); Logger.debug("create unplugged application " + correctedPath + " for " + userName); Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // create notes name object for user nmUser = sessionAsSigner.createName(userName); // check if user already exists in Unplugged vwUsers = dbUnplugged.getView(USERS_VIEW); docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true); if (docUser == null) { // user doesn't exist yet: create Unplugged.createUser(dbUnplugged, nmUser.getCanonical(), isActive); } else if (docUser.getItemValueString("Active").equals("1") && !isActive) { // mark user as inactive docUser.replaceItemValue("Active", "0"); docUser.save(); } else if (!docUser.getItemValueString("Active").equals("1") && isActive) { // mark user as active docUser.replaceItemValue("Active", "1"); docUser.save(); } // check if an app document for this app already exists and create it if not DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\""); if (dcApp.getCount() == 0) { // create new app document Logger.debug("application not found: create new"); docApp = dbUnplugged.createDocument(); docApp.replaceItemValue("form", "UserDatabase"); docApp.replaceItemValue("Path", correctedPath); } else { // update existing app document docApp = dcApp.getFirstDocument(); } Vector<String> appUsers = docApp.getItemValue("UserName"); if (!appUsers.contains(nmUser.getCanonical())) { Logger.debug(nmUser.getCanonical() + " not in list of application users: adding"); appUsers.add(nmUser.getCanonical()); docApp.replaceItemValue("UserName", appUsers); docApp.replaceItemValue("Active", "1"); docApp.computeWithForm(true, true); docApp.save(); } Logger.debug("done"); } catch (NotesException e) { Logger.error(e); } finally { Utils.recycle(docUser, docApp, nmUser, dbUnplugged); } return true; }