Search in sources :

Example 1 with Document

use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.

the class Database method getDocumentWithKey.

@Override
public Document getDocumentWithKey(final Serializable key, final boolean createOnFail) {
    try {
        if (key != null) {
            if (key instanceof String && ((String) key).length() == 32) {
                if ("000000000000000000000000000000000000".equals(key)) {
                    // $NON-NLS-1$
                    Document result = getIconNote();
                    if (result == null) {
                        result = getACLNote();
                    }
                    return result;
                }
            }
            String checksum = DominoUtils.toUnid(key);
            Document doc = this.getDocumentByUNID(checksum);
            if (doc == null && createOnFail) {
                doc = this.createDocument();
                if (checksum != null) {
                    doc.setUniversalID(checksum, true);
                }
                // $NON-NLS-1$
                doc.replaceItemValue("$$Key", key);
                // $NON-NLS-1$
                doc.replaceItemValue("$Created", new Date());
            }
            return doc;
        } else if (createOnFail) {
            // log_.log(java.util.logging.Level.FINE,
            // "Document by key requested with null key. This is probably not what you meant to do...");
            // NTF No, its exactly what we meant to do in the case of graph elements
            Document doc = this.createDocument();
            // $NON-NLS-1$
            doc.replaceItemValue("$Created", new Date());
            // doc.replaceItemValue("$$Key", "");
            return doc;
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (Exception e) {
        DominoUtils.handleException(e, this);
    }
    return null;
}
Also used : Document(org.openntf.domino.Document) UserAccessException(org.openntf.domino.exceptions.UserAccessException) Date(java.util.Date) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) FileNotFoundException(java.io.FileNotFoundException) TransactionAlreadySetException(org.openntf.domino.exceptions.TransactionAlreadySetException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) InvalidClassException(java.io.InvalidClassException) NotesException(lotus.domino.NotesException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 2 with Document

use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.

the class Database method createDocument.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Database#createDocument()
	 */
@Override
public Document createDocument() {
    // System.out.println("Generating a new document in " + this.getFilePath());
    // try {
    // Thread.sleep(100);
    // } catch (InterruptedException e1) {
    // DominoUtils.handleException(e1);
    // return null;
    // }
    Document result = null;
    boolean go;
    go = !hasListeners() ? true : fireListener(generateEvent(Events.BEFORE_CREATE_DOCUMENT, this, null));
    if (go) {
        try {
            open();
            result = fromLotus(getDelegate().createDocument(), Document.SCHEMA, this);
            ((org.openntf.domino.impl.Document) result).isNew_ = true;
        } catch (NotesException e) {
            DominoUtils.handleException(e, this);
        }
        if (hasListeners()) {
            fireListener(generateEvent(Events.AFTER_CREATE_DOCUMENT, this, null));
        }
    }
    // }
    return result;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Document(org.openntf.domino.Document)

Example 3 with Document

use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.

the class DocumentSorter method _normalize.

protected void _normalize() {
    if (dataset_ == null) {
        List<String> criteria = getCriteria();
        if (criteria.isEmpty()) {
            // $NON-NLS-1$
            addCriteria("@created");
        }
        if (sourceColl_ == null) {
            throw new IllegalStateException("Cannot sort from a null DocumentCollection. Please add a DocumentCollection that you want to sort...");
        }
        // System.out.println("Normalizing collection of " + sourceColl_.getCount() + " docs");
        long startTime = System.nanoTime();
        int docCount = 0;
        dataset_ = new DocumentData[sourceColl_.getCount()];
        for (Document doc : sourceColl_) {
            dataset_[docCount++] = new DocumentData(doc, criteria);
            // System.out.println("Processed " + ++docCount + " documents");
            if (debug) {
                if (docCount % 50000 == 0) {
                    System.out.println("Added " + docCount + " documents to set for sorting...");
                }
            }
        }
        long endTime = System.nanoTime();
        if (debug) {
            System.out.println("Normalized dataset of " + docCount + " in " + (endTime - startTime) / 1000000 + "ms");
        }
    }
}
Also used : Document(org.openntf.domino.Document)

Example 4 with Document

use of org.openntf.domino.Document 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 5 with Document

use of org.openntf.domino.Document 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)

Aggregations

Document (org.openntf.domino.Document)112 Database (org.openntf.domino.Database)48 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)31 Session (org.openntf.domino.Session)28 Map (java.util.Map)20 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 DocumentCollection (org.openntf.domino.DocumentCollection)15 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 Item (org.openntf.domino.Item)13 Set (java.util.Set)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 HashMap (java.util.HashMap)9 View (org.openntf.domino.View)9 Collection (java.util.Collection)8 UserAccessException (org.openntf.domino.exceptions.UserAccessException)8 Serializable (java.io.Serializable)7 Test (org.junit.Test)7 NotesException (lotus.domino.NotesException)6