Search in sources :

Example 1 with Session

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;
    }
}
Also used : Database(org.openntf.domino.Database) DatabaseTransaction(org.openntf.domino.transactions.DatabaseTransaction) Document(org.openntf.domino.Document) View(org.openntf.domino.View) Session(org.openntf.domino.Session)

Example 2 with Session

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;
    }
}
Also used : MIMEEntity(org.openntf.domino.MIMEEntity) Database(org.openntf.domino.Database) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Stream(org.openntf.domino.Stream) Document(org.openntf.domino.Document) MIMEHeader(org.openntf.domino.MIMEHeader) Session(org.openntf.domino.Session)

Example 3 with Session

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;
}
Also used : Database(org.openntf.domino.Database) View(org.openntf.domino.View) Session(org.openntf.domino.Session)

Example 4 with Session

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;
}
Also used : WrapperFactory(org.openntf.domino.WrapperFactory) Fixes(org.openntf.domino.ext.Session.Fixes) Database(org.openntf.domino.Database) Session(org.openntf.domino.Session)

Example 5 with Session

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Session(org.openntf.domino.Session) Name(org.openntf.domino.Name)

Aggregations

Session (org.openntf.domino.Session)101 Database (org.openntf.domino.Database)73 Document (org.openntf.domino.Document)28 Test (org.junit.Test)25 View (org.openntf.domino.View)20 DbDirectory (org.openntf.domino.DbDirectory)11 ArrayList (java.util.ArrayList)10 DocumentCollection (org.openntf.domino.DocumentCollection)7 Vector (java.util.Vector)5 ViewEntry (org.openntf.domino.ViewEntry)5 IOException (java.io.IOException)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 NotesException (lotus.domino.NotesException)4 Item (org.openntf.domino.Item)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Agent (org.openntf.domino.Agent)3 NoteCollection (org.openntf.domino.NoteCollection)3