use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.
the class DocumentSyncHelper method process.
/**
* Process a specific DocumentCollection.
*
* WARNING: Does not currently check that all properties of the SyncHelper have been set up
*
* @param coll
* DocumentCollection of source documents
* @since org.openntf.domino 1.0.0
*/
public void process(final DocumentCollection coll) {
// TODO Check to make sure properties are all set up before running
Session session = coll.getAncestorSession();
Database targetDb = session.getDatabase(getTargetServer(), getTargetFilepath());
View targetView = targetDb.getView(getTargetLookupView());
Strategy strategy = getStrategy();
DatabaseTransaction txn = null;
if (getTransactionRule() == TransactionRule.COMMIT_AT_END) {
txn = targetDb.startTransaction();
}
for (Document source : coll) {
txn = processDocument(targetDb, targetView, strategy, txn, source);
}
if (getTransactionRule() == TransactionRule.COMMIT_AT_END && txn != null) {
txn.commit();
txn = null;
}
}
use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.
the class DominoEmail method send.
/* (non-Javadoc)
* @see org.openntf.domino.email.IEmail#send()
*/
@Override
public Document send() {
try {
Stream stream;
MIMEEntity mimeEntity;
MIMEHeader mimeHeader;
Database currDb;
Session currSess = getSession();
// in case Khan is still in suspended animation!
currSess.setConvertMime(false);
// Create memo doc
try {
currDb = currSess.getCurrentDatabase();
if (null == currDb) {
// Will this work if we're running from DOTS or OSGi plugin??
// $NON-NLS-1$
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
} catch (Throwable t) {
// $NON-NLS-1$
currDb = currSess.getDatabase(currSess.getServerName(), "mail.box");
}
Document memo = currDb.createDocument();
// no replies from out of office agents //$NON-NLS-1$ //$NON-NLS-2$
memo.put("RecNoOutOfOffice", "1");
String mimeBoundary = memo.getUniversalID().toLowerCase();
// $NON-NLS-1$
MIMEEntity mimeRoot = memo.createMIMEEntity("Body");
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("To");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getTo(), ""));
if (cc_.size() > 0) {
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("CC");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getCC(), ""));
// memo.replaceItemValue("cc", getCC());
}
if (bcc_.size() > 0) {
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("BCC");
// $NON-NLS-1$
mimeHeader.setHeaderVal(join(getBCC(), ""));
// memo.replaceItemValue("bcc", getBCC());
}
// set subject
// $NON-NLS-1$
mimeHeader = mimeRoot.createHeader("Subject");
// $NON-NLS-1$
mimeHeader.addValText(getSubject(), "UTF-8");
// create text/alternative directive: text/plain and text/html part will be childs of this entity
MIMEEntity mimeRootChild = mimeRoot.createChildEntity();
// $NON-NLS-1$
mimeHeader = mimeRootChild.createHeader("Content-Type");
// $NON-NLS-1$ //$NON-NLS-2$
mimeHeader.setHeaderVal("multipart/alternative; boundary=\"" + mimeBoundary + "\"");
// create plain text part
if (getText().size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$
stream.writeText(join(getText(), System.getProperty("line.separator")));
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "text/plain; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// create HTML part
if (contentsHTML_.size() > 0) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$
stream.writeText(join(contentsHTML_, System.getProperty("line.separator")));
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "text/html; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// create embedded JSON part
if (!StringUtil.isEmpty(getJSON())) {
mimeEntity = mimeRootChild.createChildEntity();
stream = currSess.createStream();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String json = "{\"url\" : \"" + getJSON() + "\"}" + System.getProperty("line.separator");
stream.writeText(json);
// $NON-NLS-1$
mimeEntity.setContentFromText(stream, "application/embed+json; charset=\"UTF-8\"", MIMEEntity.ENC_NONE);
stream.close();
}
// Add any attachments
addAttachments(mimeRoot);
// set the sender
setSender(mimeRoot);
// mime processing done.
memo.closeMIMEEntities(true);
// send the e-mail
memo.send();
return memo;
} catch (Throwable t) {
DominoUtils.handleException(t);
return null;
}
}
use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.
the class RichTextDoclink method getView.
/* (non-Javadoc)
* @see org.openntf.domino.ext.RichTextDoclink#getView()
*/
@Override
public View getView() {
String viewId = getViewUnID();
if (viewId != null && !viewId.isEmpty()) {
// Use session.resolve to not run afoul of same-named views
Database database = getDatabase();
Session session = getAncestorSession();
String databaseUrl = database.getURL();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String url = databaseUrl.substring(0, databaseUrl.length() - "?OpenDatabase".length()) + "/" + viewId + "?OpenView";
return (View) session.resolve(url);
}
return null;
}
use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.
the class AbstractSessionFactory method wrapSession.
protected Session wrapSession(final lotus.domino.Session raw, final boolean selfCreated) {
WrapperFactory wf = Factory.getWrapperFactory();
org.openntf.domino.Session sess = wf.fromLotus(raw, Session.SCHEMA, wf);
sess.setNoRecycle(!selfCreated);
Fixes[] fixes = Factory.getThreadConfig().fixes;
if (fixes != null) {
for (Fixes fix : fixes) {
if (fix.isKhan()) {
sess.setFixEnable(fix, true);
}
}
}
sess.setAutoMime(Factory.getThreadConfig().autoMime);
sess.setConvertMIME(false);
if (selfCreated && currentApiPath_ != null) {
Database db = sess.getCurrentDatabase();
if (db == null) {
db = sess.getDatabase(currentApiPath_);
setCurrentDatabase(sess, db);
}
}
return sess;
}
use of org.openntf.domino.Session in project org.openntf.domino by OpenNTF.
the class UserProvider method processRequest.
@Override
public Object processRequest(FramedGraph graph, String item, MultivaluedMap<String, String> params) {
Map<String, Object> result = new LinkedHashMap<String, Object>();
try {
Session session = Factory.getSession(SessionType.CURRENT);
String userName = session.getEffectiveUserName();
result.put("username", userName);
Name name = session.createName(userName);
Collection<String> groups = name.getGroups("");
result.put("groups", groups);
} catch (Throwable t) {
t.printStackTrace();
}
return result;
}
Aggregations