Search in sources :

Example 6 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method copyItem.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#copyItem(lotus.domino.Item, java.lang.String)
	 */
@Override
public Item copyItem(final lotus.domino.Item item, final String newName) {
    // TODO - NTF markDirty()? Yes. It's necessary.
    // TODO RPr: ConvertMime?
    checkMimeOpen(newName);
    beginEdit();
    try {
        Item ret = fromLotus(getDelegate().copyItem(toLotus(item), newName), Item.SCHEMA, this);
        markDirty(ret.getName(), true);
        return ret;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
    }
    return null;
}
Also used : RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException)

Example 7 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method closeMIMEEntities.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#closeMIMEEntities(boolean, java.lang.String)
	 */
@Override
public boolean closeMIMEEntities(final boolean saveChanges, final String entityItemName) {
    // checkMimeOpen(); RPr: This is not needed here (just to tweak my grep command)
    if (isDeferred_) {
        return true;
    }
    if (isDead()) {
        return true;
    }
    try {
        // TODO: $Mime-xxx Fields to fieldNames_ List
        if (saveChanges) {
            if (entityItemName == null) {
                markDirty();
            } else {
                markDirty("$NoteHasNativeMIME", true);
                markDirty("MIME_Version", true);
                markDirty("$MIMETrack", true);
                markDirty(entityItemName, true);
            }
        }
        // // This has to be called BEFORE we recycle the Mime entity, otherwise the data may not be stored.
        boolean ret = false;
        if (null != entityItemName) {
            try {
                ret = getDelegate().closeMIMEEntities(saveChanges, entityItemName);
                if (saveChanges && !ret) {
                    if (log_.isLoggable(Level.SEVERE)) {
                        log_.log(Level.SEVERE, "closeMIMEEntities returned false for item " + entityItemName + " on doc " + getNoteID() + " in db " + getAncestorDatabase().getApiPath(), new Throwable());
                    }
                }
            } catch (NotesException e) {
                log_.log(Level.INFO, "Attempted to close a MIMEEntity called " + entityItemName + " even though we can't find an item by that name.", e);
            }
        } else {
            try {
                ret = getDelegate().closeMIMEEntities(saveChanges, null);
            } catch (NotesException e) {
                log_.log(Level.INFO, "Failed to close all MIMEEntities", e);
            }
        }
        // ensure that every MIME item is recycled before closing.
        if (openMIMEEntities_ != null) {
            if (entityItemName == null) {
                Collection<Set<MIMEEntity>> values = openMIMEEntities_.values();
                if (values != null && !values.isEmpty()) {
                    for (Set<MIMEEntity> currEntitySet : values) {
                        if (currEntitySet != null && !currEntitySet.isEmpty()) {
                            for (MIMEEntity currEntity : currEntitySet) {
                                ((org.openntf.domino.impl.MIMEEntity) currEntity).closeMIMEEntity();
                            }
                        }
                    }
                }
                openMIMEEntities_.clear();
            } else {
                String lcName = entityItemName.toLowerCase();
                if (openMIMEEntities_.containsKey(lcName)) {
                    Set<MIMEEntity> currEntitySet = openMIMEEntities_.remove(lcName);
                    if (currEntitySet != null) {
                        for (MIMEEntity currEntity : currEntitySet) {
                            ((org.openntf.domino.impl.MIMEEntity) currEntity).closeMIMEEntity();
                        }
                    }
                } else {
                    log_.log(Level.FINE, "A request was made to close MIMEEntity " + entityItemName + " but that entity isn't currently open");
                }
            }
        }
        if (saveChanges) {
            // This item is for debugging only, so keep 5-10 items in that list
            // http://www-01.ibm.com/support/docview.wss?uid=swg27002572
            Vector<Object> mt = getItemValue("$MIMETrack");
            if (mt.size() > 10) {
                replaceItemValue("$MIMETrack", mt.subList(mt.size() - 10, mt.size()));
            }
        // Other ideas: 1) Delete it completely, 2) write dummy entry
        // removeItem("$MIMETrack");
        // replaceItemValue("$MIMETrack", "Itemize by OpenNTF-Domino API on " + getAncestorSession().getServerName() + " at "
        // + new Date());
        }
        return ret;
    } catch (Exception e) {
        DominoUtils.handleException(e, this);
    }
    return false;
}
Also used : SortedSet(java.util.SortedSet) DocumentEntrySet(org.openntf.domino.helpers.DocumentEntrySet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) JsonException(com.ibm.commons.util.io.json.JsonException) DocumentWriteAccessException(org.openntf.domino.exceptions.DocumentWriteAccessException) DataNotCompatibleException(org.openntf.domino.exceptions.DataNotCompatibleException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) NotesException(lotus.domino.NotesException) DominoNonSummaryLimitException(org.openntf.domino.exceptions.DominoNonSummaryLimitException) IOException(java.io.IOException) ItemNotFoundException(org.openntf.domino.exceptions.ItemNotFoundException) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) MIMEEntity(org.openntf.domino.MIMEEntity) EmbeddedObject(org.openntf.domino.EmbeddedObject)

Example 8 with NotesException

use of lotus.domino.NotesException 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 9 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method getItemValueCustomDataBytes.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#getItemValueCustomDataBytes(java.lang.String, java.lang.String)
	 */
@Override
public byte[] getItemValueCustomDataBytes(final String itemName, final String dataTypeName) throws IOException {
    checkMimeOpen(itemName);
    try {
        byte[] ret = getDelegate().getItemValueCustomDataBytes(itemName, dataTypeName);
        if (ret != null && ret.length != 0) {
            return ret;
        }
        MIMEEntity entity;
        if ((entity = getMIMEEntity(itemName)) == null) {
            return ret;
        }
        Object o = null;
        try {
            o = Documents.getItemValueMIME(this, itemName, entity);
        } finally {
            closeMIMEEntities(false, itemName);
        }
        if (o != null && o.getClass().getName().equals("[B")) {
            ret = (byte[]) o;
        }
        return ret;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this, "Item=" + itemName);
    }
    return null;
}
Also used : MIMEEntity(org.openntf.domino.MIMEEntity) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) EmbeddedObject(org.openntf.domino.EmbeddedObject)

Example 10 with NotesException

use of lotus.domino.NotesException in project org.openntf.domino by OpenNTF.

the class Document method setUniversalID.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#setUniversalID(java.lang.String)
	 */
@Override
public void setUniversalID(final String unid) {
    if (getUniversalID().equalsIgnoreCase(unid)) {
        // it's already that unid. Don't waste time...
        return;
    }
    checkMimeOpen(unid);
    beginEdit();
    try {
        try {
            lotus.domino.Document del = getDelegate().getParentDatabase().getDocumentByUNID(unid);
            if (del != null) {
                // this is surprising. Why didn't we already get it?
                log_.log(Level.WARNING, "Document " + unid + " already existed in the database with noteid " + del.getNoteID() + " and we're trying to set a doc with noteid " + getNoteID() + " to that. The existing document is a " + del.getItemValueString("form") + " and the new document is a " + getItemValueString("form"));
                if (isDirty()) {
                    // we've already made other changes that we should tuck away...
                    log_.log(Level.WARNING, "Attempting to stash changes to this document to apply to other document of the same UNID. This is pretty dangerous...");
                    org.openntf.domino.Document stashDoc = copyToDatabase(getParentDatabase());
                    setDelegate(del, true);
                    try {
                        for (Item item : stashDoc.getItems()) {
                            lotus.domino.Item delItem = del.getFirstItem(item.getName());
                            if (delItem != null) {
                                lotus.domino.DateTime delDt = delItem.getLastModified();
                                java.util.Date delDate = delDt.toJavaDate();
                                delDt.recycle();
                                Date modDate = item.getLastModifiedDate();
                                if (modDate.after(delDate)) {
                                    item.copyItemToDocument(del);
                                }
                            } else {
                                item.copyItemToDocument(del);
                            }
                        // TODO NTF properties?
                        }
                    } catch (Throwable t) {
                        DominoUtils.handleException(t);
                    }
                } else {
                    log_.log(Level.WARNING, "Resetting delegate to existing document for id " + unid);
                    setDelegate(del, true);
                }
            } else {
                getDelegate().setUniversalID(unid);
            }
            markDirty();
        } catch (NotesException ne) {
            // this is what's expected
            getDelegate().setUniversalID(unid);
            markDirty();
        }
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
    }
    unid_ = unid;
}
Also used : RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) Date(java.util.Date) Date(java.util.Date)

Aggregations

NotesException (lotus.domino.NotesException)105 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)29 ArrayList (java.util.ArrayList)28 List (java.util.List)19 ViewNavigator (org.openntf.domino.ViewNavigator)13 Vector (java.util.Vector)11 Database (lotus.domino.Database)11 Database (org.openntf.domino.Database)10 IOException (java.io.IOException)8 ViewColumn (org.openntf.domino.ViewColumn)8 DocumentCollection (org.openntf.domino.DocumentCollection)7 EmbeddedObject (org.openntf.domino.EmbeddedObject)7 RichTextItem (org.openntf.domino.RichTextItem)7 Session (lotus.domino.Session)6 MIMEEntity (org.openntf.domino.MIMEEntity)5 Date (java.util.Date)4 Document (org.openntf.domino.Document)4 DocumentCollection (lotus.domino.DocumentCollection)3 DominoQuery (lotus.domino.DominoQuery)3 Item (org.openntf.domino.Item)3