public static void removeApplication(String appPath) throws NotesException { Session session = null; Database dbUnplugged = null; String correctedPath = appPath.replace("\\", "/"); Logger.debug("Remove Unplugged application for app at " + correctedPath); Configuration config = Configuration.get(); // open unplugged db session = Utils.getCurrentSession(); dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // 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) { Logger.warn("- Unplugged application document not found"); } else if (dcApp.getCount() > 1) { Logger.error("- Multiple Unplugged application documents found: not removed"); } else { Logger.info("- Unplugged add configuration found"); dcApp.getFirstDocument().remove(true); Logger.info("- Unplugged app configuration removed"); } }
public static void removeUsersAndDevices(String alias) throws NotesException { Session session = null; Database dbUnplugged = null; String alias1 = "/" + alias.toLowerCase(); String alias2 = "/o=" + alias.toLowerCase(); Logger.debug("Remove Unplugged users and devices for alias \"" + alias + "\""); Configuration config = Configuration.get(); // open unplugged db session = Utils.getCurrentSession(); dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // check if an app document for this app already exists and create it if not String q = "Form=\"User\":\"Device\" & ( @Contains(@LowerCase(UserName); \"" + alias1 + "\") | @Contains(@LowerCase(UserName); \"" + alias2 + "\") )"; DocumentCollection dcApp = dbUnplugged.search(q); Logger.info("- finding users and devices with query: " + q); if (dcApp.getCount() == 0) { Logger.info("- No Unplugged users/ devices found"); } else { Logger.info("- found " + dcApp.getCount() + " users and/or devices"); Document doc = dcApp.getFirstDocument(); while (null != doc) { Document t = dcApp.getNextDocument(doc); Logger.info( "- removing " + doc.getItemValueString("form") + " for " + doc.getItemValueString("UserName")); doc.remove(true); try { doc.recycle(); } catch (Exception e) { } doc = t; } } }
@SuppressWarnings("unchecked") private void convert( String dataVersion, String DATA_VERSION, Database dbCurrent, View vwAllByType, Document docSettings) { try { DebugToolbar.get() .info( "Start conversion (current data version: " + dataVersion + ", update to " + DATA_VERSION + ")"); DebugToolbar.get().info("- convert role > appMenuOptions"); DocumentCollection dc; dc = dbCurrent.search("form=\"fRole\" & @IsUnavailable(appMenuOptions)"); if (dc.getCount() > 0) { dc.stampAll("appMenuOptions", "all"); } DebugToolbar.get() .info("- convert contacts (app menu options, org units, org unit in call tree)"); dc = dbCurrent.search("form=\"fContact\""); if (dc.getCount() > 0) { boolean changed = false; Document doc = dc.getFirstDocument(); while (null != doc) { changed = false; // remove app menu options field if (doc.hasItem("appMenuOptions")) { doc.removeItem("appMenuOptions"); changed = true; } if (doc.hasItem("appMenuOptionsActive")) { doc.removeItem("appMenuOptionsActive"); changed = true; } String callTreeRoot = doc.getItemValueString("callTreeRoot"); Vector<String> callTreeCalledBy = doc.getItemValue("callTreeCalledBy"); Vector<String> callTreeContacts = doc.getItemValue("callTreeContacts"); String orgUnitId = null; if (doc.hasItem("orgUnitId")) { orgUnitId = doc.getItemValueString("orgUnitId"); } else { Vector<String> o = doc.getItemValue("orgUnitIds"); if (o.size() > 0) { orgUnitId = o.get(0); } } boolean callTreeChanged = false; if (StringUtil.isNotEmpty(orgUnitId)) { if (callTreeRoot.length() > 0 && callTreeRoot.indexOf("-") == -1) { doc.replaceItemValue("callTreeRoot", orgUnitId + "-" + callTreeRoot); callTreeChanged = true; } for (int i = 0; i < callTreeCalledBy.size(); i++) { String _this = callTreeCalledBy.get(i); if (_this.length() > 0 && _this.indexOf("-") == -1) { callTreeCalledBy.set(i, orgUnitId + "-" + _this); callTreeChanged = true; } } for (int i = 0; i < callTreeContacts.size(); i++) { String _this = callTreeContacts.get(i); if (_this.length() > 0 && _this.indexOf("-") == -1) { callTreeContacts.set(i, orgUnitId + "-" + _this); callTreeChanged = true; } } if (callTreeChanged) { changed = true; doc.replaceItemValue("callTreeCalledBy", callTreeCalledBy); doc.replaceItemValue("callTreeContacts", callTreeContacts); } } // convert org unit to multi-value name if (doc.hasItem("orgUnitId")) { doc.replaceItemValue("orgUnitIds", doc.getItemValueString("orgUnitId")); doc.removeItem("orgUnitId"); changed = true; } if (doc.hasItem("orgUnitName")) { doc.replaceItemValue("orgUnitNames", doc.getItemValueString("orgUnitName")); doc.removeItem("orgUnitName"); changed = true; } if (changed) { doc.save(); } Document tmp = dc.getNextDocument(doc); doc.recycle(); doc = tmp; } dc.stampAll("appMenuOptions", "all"); } DebugToolbar.get().info("Conversion finished - update data version"); // update version in settings document docSettings = vwAllByType.getDocumentByKey("fSettings", true); // re-retrieve here using signer access docSettings.replaceItemValue("dataVersion", DATA_VERSION); docSettings.save(); } catch (Exception e) { DebugToolbar.get().error(e); } }
// 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; }