Search in sources :

Example 1 with DominoNonSummaryLimitException

use of org.openntf.domino.exceptions.DominoNonSummaryLimitException in project org.openntf.domino by OpenNTF.

the class Document method replaceItemValue.

/**
 * replaceItemValue writes itemFriendly values or a Collection of itemFriendly values.
 *
 * if "autoSerialisation" is enabled. Data exceeding 32k is serialized with replaceItemValueCustomData. If MIME_BEAN_SUFFIX is set, the
 * original item contains the String $ObjectData (=MIME_BEAN_SUFFIX). This is important, if you display data in a view, so that you see
 * immediately, that only serialized content is available
 *
 * @see org.openntf.domino.Document#replaceItemValue(java.lang.String, java.lang.Object)
 */
@Override
public Item replaceItemValue(final String itemName, final Object value, final Boolean isSummary, final boolean boxCompatibleOnly, final boolean returnItem) {
    Item result = null;
    try {
        try {
            // Special case. If the argument is an Item, just copy it.
            if (value instanceof Item) {
                List<lotus.domino.Base> recycleThis = null;
                lotus.domino.Item tmpResult;
                recycleThis = new ArrayList<lotus.domino.Base>();
                // remove the mime item first, so that it will not collide with MIME etc.
                MIMEEntity mimeChk = getMIMEEntity(itemName);
                if (mimeChk != null) {
                    try {
                        mimeChk.remove();
                    } finally {
                        closeMIMEEntities(true, itemName);
                    }
                }
                beginEdit();
                tmpResult = getDelegate().replaceItemValue(itemName, TypeUtils.toDominoFriendly(value, getAncestorSession(), recycleThis));
                markDirty(itemName, true);
                s_recycle(tmpResult);
                if (returnItem) {
                    return getFactory().create(Item.SCHEMA, this, itemName);
                } else {
                    return null;
                }
            }
            result = replaceItemValueLotus(itemName, value, isSummary, returnItem);
        } catch (Exception ex2) {
            if (this.getAutoMime() == AutoMime.WRAP_NONE) {
                // AutoMime completely disabled.
                throw ex2;
            }
            if (!boxCompatibleOnly || ex2 instanceof DominoNonSummaryLimitException) {
                // if the value exceeds 32k or we are called from put() (means boxCompatibleOnly=false) we try to write the object as MIME
                result = replaceItemValueCustomData(itemName, "mime-bean", value, returnItem);
            } else if (this.getAutoMime() == AutoMime.WRAP_ALL) {
                // Compatibility mode
                result = replaceItemValueCustomData(itemName, "mime-bean", value, returnItem);
                log_.log(Level.INFO, "Writing " + value == null ? "null" : value.getClass() + " causes a " + ex2 + " as AutoMime.WRAP_ALL is enabled, the value will be wrapped in a MIME bean." + " Consider using 'put' or something similar in your code.");
            } else {
                throw ex2;
            }
        }
        // TODO RPr: What is this?
        if (this.shouldWriteItemMeta_) {
            // If we've gotten this far, it must be legal - update or create the item info map
            Class<?> valueClass;
            if (value == null) {
                valueClass = Null.class;
            } else {
                valueClass = value.getClass();
            }
            Map<String, Map<String, Serializable>> itemInfo = getItemInfo();
            Map<String, Serializable> infoNode = null;
            if (itemInfo.containsKey(itemName)) {
                infoNode = itemInfo.get(itemName);
            } else {
                infoNode = new HashMap<String, Serializable>();
            }
            infoNode.put("valueClass", valueClass.getName());
            // For sanity checking if the value was changed outside of Java
            infoNode.put("updated", new Date());
            itemInfo.put(itemName, infoNode);
        }
    } catch (Throwable t) {
        DominoUtils.handleException(t, this, "Item=" + itemName);
    }
    return result;
}
Also used : DominoNonSummaryLimitException(org.openntf.domino.exceptions.DominoNonSummaryLimitException) Serializable(java.io.Serializable) 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) Date(java.util.Date) RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) MIMEEntity(org.openntf.domino.MIMEEntity) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

JsonException (com.ibm.commons.util.io.json.JsonException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 NotesException (lotus.domino.NotesException)1 Item (org.openntf.domino.Item)1 MIMEEntity (org.openntf.domino.MIMEEntity)1 RichTextItem (org.openntf.domino.RichTextItem)1 DataNotCompatibleException (org.openntf.domino.exceptions.DataNotCompatibleException)1 DocumentWriteAccessException (org.openntf.domino.exceptions.DocumentWriteAccessException)1 DominoNonSummaryLimitException (org.openntf.domino.exceptions.DominoNonSummaryLimitException)1 ItemNotFoundException (org.openntf.domino.exceptions.ItemNotFoundException)1 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)1 UserAccessException (org.openntf.domino.exceptions.UserAccessException)1