Search in sources :

Example 1 with Database

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

the class Document method save.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#save(boolean, boolean, boolean)
	 */
@Override
public boolean save(final boolean force, final boolean makeResponse, final boolean markRead) {
    // System.out.println("Starting save operation on " + this.getMetaversalID() + ". isNew: " + String.valueOf(isNewNote()));
    // Throwable t = new Throwable();
    // t.printStackTrace();
    // checkMimeOpen();
    // System.out.println("TEMP DEBUG Starting save operation on " + unid_ + " in " + this.getAncestorDatabase().getApiPath() + " as user "
    // + this.getAncestorSession().getCommonUserName());
    boolean result = false;
    if (removeType_ != null) {
        log_.log(Level.INFO, "Save called on a document marked for a transactional delete. So there's no point...");
        return true;
    }
    // START SPECIAL DEBUG SECTION FOR NTF IN GRAPH2 ENGINE
    if (getAncestorDatabase().getFileName().equalsIgnoreCase("factproxy.nsf")) {
        if (getItemValueString("form").equalsIgnoreCase("vertexframe")) {
            Throwable t = new Throwable();
            writeStackTraceToItem("stackTrace", t);
        } else if (Strings.isBlankString(getItemValueString("$$key")) || getItemValueString("$$key").length() < 48) {
            Throwable t = new Throwable();
            writeStackTraceToItem("stackTrace", t);
        }
    }
    if (isNewNote() || isDirty()) {
        boolean go = true;
        Database db = getAncestorDatabase();
        go = !db.hasListeners() ? true : db.fireListener(generateEvent(Events.BEFORE_UPDATE_DOCUMENT, null));
        if (go) {
            writeItemInfo();
            // fieldNames_ = null;
            isNew_ = false;
            try {
                lotus.domino.Document del = getDelegate();
                if (del != null) {
                    result = del.save(force, makeResponse, markRead);
                    // complex cases are not needed unless you want to log
                    // if (noteid_ == null || !noteid_.equals(del.getNoteID())) {
                    // // System.out.println("Resetting note id from " + noteid_ + " to " + del.getNoteID());
                    // noteid_ = del.getNoteID();
                    // }
                    // if (unid_ == null || !unid_.equals(del.getUniversalID())) {
                    // // System.out.println("Resetting unid from " + unid_ + " to " + del.getUniversalID());
                    // unid_ = del.getUniversalID();
                    // }
                    // so we can do that in every case
                    noteid_ = del.getNoteID();
                    unid_ = del.getUniversalID();
                    // don't set to true, save may fail!
                    isNew_ = noteid_.equals("0") || noteid_.isEmpty();
                    invalidateCaches();
                } else {
                    log_.severe("Delegate document for " + unid_ + " is NULL!??!");
                }
            } catch (NotesException e) {
                // e.printStackTrace();
                if (e.text.contains("Database already contains a document with this ID")) {
                    // Throwable t = new RuntimeException();
                    String newunid = DominoUtils.toUnid(new Date().getTime());
                    String message = "Unable to save a document with id " + getUniversalID() + " because that id already exists. Saving a " + this.getFormName() + (this.hasItem("$$Key") ? " (key: '" + getItemValueString("$$Key") + "')" : "") + " to a different unid instead: " + newunid;
                    setUniversalID(newunid);
                    try {
                        getDelegate().save(force, makeResponse, markRead);
                        noteid_ = getDelegate().getNoteID();
                        isNew_ = noteid_.equals("0") || noteid_.isEmpty();
                        System.out.println(message);
                        log_.log(Level.WARNING, message);
                    } catch (NotesException ne) {
                        log_.log(Level.SEVERE, "Okay, now it's time to really panic. Sorry...");
                        DominoUtils.handleException(e, this);
                    }
                } else if (e.text.contains("You are not authorized")) {
                    throw new DocumentWriteAccessException(this);
                } else {
                    DominoUtils.handleException(e, this);
                }
            }
            if (result) {
                clearDirty();
                getAncestorDatabase().fireListener(generateEvent(Events.AFTER_UPDATE_DOCUMENT, null));
            }
        } else {
            // System.out.println("Before Update listener blocked save.");
            if (log_.isLoggable(Level.FINE)) {
                log_.log(Level.FINE, "Document " + getNoteID() + " was not saved because the DatabaseListener for update returned false.");
            }
            result = false;
        }
    } else {
        // System.out.println("No changes occured therefore not saving.");
        if (log_.isLoggable(Level.FINE)) {
            log_.log(Level.FINE, "Document " + getNoteID() + " was not saved because nothing on it was changed.");
        }
        // because nothing changed, we don't want to activate any potential failure behavior in the caller
        result = true;
    }
    return result;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Database(org.openntf.domino.Database) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException) Date(java.util.Date)

Example 2 with Database

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

the class DbDirectory method toArray.

/**
 * Returns an array containing all of the databases in this directory
 */
@Override
public Object[] toArray() {
    Object[] ret = new Object[size()];
    int i = 0;
    for (DatabaseMetaData metaData : getMetaDataSet()) {
        Database db = getFactory().create(Database.SCHEMA, getAncestorSession(), metaData);
        ret[i++] = db;
    }
    return ret;
}
Also used : Database(org.openntf.domino.Database) DatabaseMetaData(org.openntf.domino.helpers.DatabaseMetaData)

Example 3 with Database

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

the class DbDirectory method createDatabase.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.DbDirectory#createDatabase(java.lang.String, boolean)
	 */
@Override
public Database createDatabase(final String dbFile, final boolean open) {
    org.openntf.domino.Database result = null;
    try {
        if (getAncestorSession().isFixEnabled(Fixes.CREATE_DB)) {
            result = openDatabase(dbFile, false);
            if (result != null) {
                return result;
            }
        }
        lotus.domino.Database delDb = getDelegate().createDatabase(dbFile, open);
        result = fromLotus(delDb, Database.SCHEMA, getAncestorSession());
        return result;
    } catch (NotesException e) {
        // System.out.println("DEBUG: " + e.id + " - " + e.text);
        if (e.id == 4005 && getAncestorSession().isFixEnabled(Fixes.CREATE_DB)) {
            result = getAncestorSession().getDatabase(getName(), dbFile);
            return result;
        } else {
            DominoUtils.handleException(e);
            return null;
        }
    }
}
Also used : NotesException(lotus.domino.NotesException) Database(org.openntf.domino.Database)

Example 4 with Database

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

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

Database (org.openntf.domino.Database)131 Session (org.openntf.domino.Session)73 Document (org.openntf.domino.Document)49 Test (org.junit.Test)19 View (org.openntf.domino.View)19 DbDirectory (org.openntf.domino.DbDirectory)17 NotesException (lotus.domino.NotesException)12 ArrayList (java.util.ArrayList)11 NoteCollection (org.openntf.domino.NoteCollection)11 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)10 DocumentCollection (org.openntf.domino.DocumentCollection)8 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)8 Date (java.util.Date)6 UserAccessException (org.openntf.domino.exceptions.UserAccessException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ViewEntry (org.openntf.domino.ViewEntry)5 FastTable (javolution.util.FastTable)4 Item (org.openntf.domino.Item)4 RichTextItem (org.openntf.domino.RichTextItem)4