public UploadedFile[] processJava2Domino(Document docCurrent, Object objCurrent, Definition def) { try { UploadedFile file = getValue(objCurrent, def.getJavaField()); if (file != null) { IUploadedFile FTemp = file.getUploadedFile(); File SrFile = FTemp.getServerFile(); File FNew = new File( SrFile.getParentFile().getAbsolutePath() + File.separator + FTemp.getClientFileName()); SrFile.renameTo(FNew); RichTextItem rt = null; rt = (RichTextItem) docCurrent.getFirstItem(def.getNotesField()); if (rt == null) rt = docCurrent.createRichTextItem(def.getNotesField()); rt.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", FNew.getAbsolutePath(), null); } } catch (Exception e) { e.printStackTrace(); } return null; }
public InputStream getFileSteam(FileHelper fh) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return null; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return null; } EmbeddedObject entity = docCurrent.getAttachment(fh.getName()); if (entity == null) { ndbCurrent.recycle(); docCurrent.recycle(); return null; } InputStream is = entity.getInputStream(); entity.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); return is; // entity.getInputStream(); } catch (Exception e) { e.printStackTrace(); } return null; }
protected void saveAsset(ImportSource source, VFSFile root, AssetNode node) throws Exception { JSSnippet snippet = (JSSnippet) node.load(root); Document doc = getDatabase().createDocument(); try { setItemValue(doc, "Form", "CodeSnippet"); setItemValue( doc, "Author", doc.getParentDatabase() .getParent() .getUserName()); // Should we make this private (reader field)? setItemValue(doc, "Id", node.getUnid()); setItemValue(doc, "Category", node.getCategory()); setItemValue(doc, "Name", node.getName()); setItemValue(doc, "Description", snippet.getProperty("description")); setItemValue(doc, "Tags", snippet.getProperty("tags")); setItemValue(doc, "ImportSource", source.getName()); setItemValueRichText(doc, "Html", snippet.getHtml()); setItemValueRichText(doc, "Css", snippet.getCss()); setItemValueRichText(doc, "JavaScript", snippet.getJs()); setItemValueRichText(doc, "Properties", snippet.getPropertiesAsString()); setItemValueRichText(doc, "Documentation", snippet.getDocHtml()); doc.save(); } finally { doc.recycle(); } }
/** * @param sendTo * @param subject * @param body * @throws NotesException */ public static void sendSimpleEmail(String sendTo, String subject, String body) throws NotesException { Document mailDoc = thisDb.createDocument(); mailDoc.replaceItemValue("SendTo", sendTo.split(",")); mailDoc.replaceItemValue("Subject", subject); mailDoc.replaceItemValue("body", body); mailDoc.send(); }
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; } } }
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; }
/** * RWFException constructor * * @param Database d the current database */ public RWFException(Database d) { super(); try { Document e = d.createDocument(); e.replaceItemValue("Form", EXCEPTION_FORM); e.replaceItemValue(EXCEPTION_TYPE_FIELD, "Workflow Exception"); e.save(); } catch (NotesException e) { e.printStackTrace(); System.out.println(e.text); } }
public void setCallTreeRoleBased() { this.callTreeType = CALLTREE_TYPE_ROLE; try { Document docSettings = ExtLibUtil.getCurrentDatabase().getDocumentByUNID(settingsUnid); docSettings.replaceItemValue("callTreeType", callTreeType); docSettings.save(); docSettings.recycle(); } catch (NotesException e) { Logger.error(e); } }
public FileHelper addFile(FileHelper fh, UploadedFile file, String strNewId) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return null; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return null; } IUploadedFile FTemp = file.getUploadedFile(); File SrFile = FTemp.getServerFile(); File FNew = new File( SrFile.getParentFile().getAbsolutePath() + File.separator + FTemp.getClientFileName()); SrFile.renameTo(FNew); RichTextItem rt = null; rt = (RichTextItem) docCurrent.getFirstItem(fh.getFieldName()); if (rt == null) { rt = docCurrent.createRichTextItem(fh.getFieldName()); } EmbeddedObject em = rt.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", FNew.getAbsolutePath(), null); docCurrent.save(true, false, true); FileHelper fhNew = new FileHelper(); fhNew.setFieldName(fh.getFieldName()); fhNew.setServer(fh.getServer()); fhNew.setPath(fh.getPath()); fhNew.setFileSize(em.getFileSize()); fhNew.setName(em.getName()); fhNew.setDisplayName(FTemp.getClientFileName()); fhNew.setId(strNewId); fhNew.setDocID(fh.getDocID()); fhNew.setFileType(ComponentSessionFacade.get().getMimeTypes().getContentType(FNew)); fhNew.setNewFile(false); rt.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); return fhNew; } catch (Exception e) { e.printStackTrace(); } return null; }
private boolean swap(String noteID, boolean previous) throws Exception { // Is there a faster way? View view = ExtLibUtil.getCurrentDatabase().getView("AllDocumentation"); // view.setAutoUpdate(false); ViewNavigator vn = view.createViewNav(); try { for (ViewEntry ve = vn.getFirst(); ve != null; ve = vn.getNext(ve)) { if (ve.getNoteID().equals(noteID)) { int docIndent = ve.getIndentLevel(); Document doc = ve.getDocument(); ve = previous ? vn.getPrev(ve) : vn.getNext(ve); if (ve != null) { Document other = ve.getDocument(); if (ve.getIndentLevel() == docIndent) { Object ts = other.getItemValue("OrderTS"); other.replaceItemValue("OrderTS", doc.getItemValue("OrderTS")); doc.replaceItemValue("OrderTS", ts); doc.save(); other.save(); view.refresh(); return true; } } return false; } } } finally { vn.recycle(); } return false; }
public static void createAppDefinition(String appPath, boolean hideFromWS, boolean autoLaunch) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docApp = null; try { String correctedPath = appPath.replace("\\", "/"); Logger.debug("create unplugged application " + correctedPath); Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.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) { // create new app document Logger.debug("application not found: create new"); docApp = dbUnplugged.createDocument(); docApp.replaceItemValue("form", "UserDatabase"); docApp.replaceItemValue("Path", correctedPath); } else { throw (new Exception("application for " + correctedPath + " already exists in Unplugged")); } docApp.replaceItemValue("Active", "1"); docApp.replaceItemValue("ShowOnWS", (hideFromWS ? "no" : "")); docApp.replaceItemValue("AutoLaunchApp", (autoLaunch ? "yes" : "")); docApp.replaceItemValue("ReplAttachmentExts", ""); // send all attachments docApp.computeWithForm(true, true); docApp.save(); Logger.debug("done"); } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docApp, dbUnplugged); } }
/** * RWFException constructor * * @param - msg, String the error message to be used. * @param Document doc the context document. */ public RWFException(String msg, Document doc) { Database db = null; try { db = doc.getParentDatabase(); } catch (NotesException e) { e.printStackTrace(); } new RWFException(msg, db, doc); }
/** * Wrap. * * @param doc the doc * @return the document */ public static Document wrap(final lotus.domino.Document doc) { try { lotus.domino.Database db = doc.getParentDatabase(); Session session = Factory.fromLotus(db.getParent(), Session.class, null); Database wrappedDB = Factory.fromLotus(db, Database.class, session); return Factory.fromLotus(doc, Document.class, wrappedDB); } catch (lotus.domino.NotesException ne) { return null; } }
@SuppressWarnings("unchecked") public void removeFile(FileHelper fh) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return; } // RESULTS IN NOTE ITEM NOT FOUND ERROR AFTERWARDS // EmbeddedObject entity = docCurrent.getAttachment(fh.getName()); // if (entity == null) // return; // entity.remove(); RichTextItem rti = (RichTextItem) docCurrent.getFirstItem(fh.getFieldName()); Vector<EmbeddedObject> entitys = rti.getEmbeddedObjects(); for (EmbeddedObject entity : entitys) { if (entity.getType() == EmbeddedObject.EMBED_ATTACHMENT) { if (entity.getName().equals(fh.getName())) { entity.remove(); break; } } } docCurrent.save(true, false, true); rti.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); } catch (Exception e) { e.printStackTrace(); } }
/** * 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 } }
/** * RWFException constructor * * @param - msg, String the error message to be used. * @param Database d the current database * @param Document doc the context document. */ public RWFException(String msg, Database d, Document doc) { super(msg); try { Document e = d.createDocument(); e.replaceItemValue("Form", EXCEPTION_FORM); e.replaceItemValue(EXCEPTION_TYPE_FIELD, "Workflow Exception"); e.replaceItemValue(EXCEPTION_MSG_FIELD, msg); RichTextItem rt = e.createRichTextItem(EXCEPTION_DOCLINK_FIELD); rt.appendDocLink(doc); e.save(); } catch (NotesException e) { e.printStackTrace(); System.out.println(e.text); } }
// create an Unplugged user private static void createUser(Database dbUnplugged, String userName, boolean isActive) { Document docUser = null; try { Logger.info("create user document for " + userName); docUser = dbUnplugged.createDocument(); docUser.replaceItemValue("Form", "User"); docUser.replaceItemValue("UserName", userName); docUser.replaceItemValue("Active", (isActive ? "1" : "0")); docUser.computeWithForm(true, true); docUser.save(); } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docUser); } }
// 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; }
/* * 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); } }
@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); } }