Search in sources :

Example 1 with DocumentCollection

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

the class Document method get.

/**
 * Gets a value depending on the parameter 'key'. Key can either be a @Formula, a special value or an item name.
 * <p>
 * Possible values for the 'key' parameter:
 * <dl>
 * <dt>parentdocument</dt>
 * <dd>Returns the parent document if this document is a response</dd>
 * <dt>@accesseddate</dt>
 * <dd>Indicates the time and date when the document was last accessed by a Notes client, whether for reading or editing as a
 * java.util.Date.</dd>
 * <dt>@modifieddate</dt>
 * <dd>Returns a time-date value indicating when the document was modified initially as a java.util.Date</dd>
 * <dt>@createddate</dt>
 * <dd>Returns the time-date when the document was created as a java.util.Date</dd>
 * </dl>
 * </p>
 *
 * @param key
 *            &#64;formula, item name or a special value from a list above
 * @return value corresponding to the given 'key'
 */
@Override
public Object get(final Object key) {
    // TODO NTF: Implement a read-only mode for Documents so we know in advance that our cache is valid
    if (key == null) {
        return null;
    }
    if (key instanceof CharSequence) {
        String skey = key.toString().toLowerCase();
        if ("parentdocument".equalsIgnoreCase(skey)) {
            return this.getParentDocument();
        }
        if ("form".equalsIgnoreCase(skey)) {
            return this.getFormName();
        }
        if (skey.indexOf("@") != -1) {
            // TODO RPr: Should we REALLY detect all formulas, like "3+5" or "field[2]" ?
            // TODO NTF: If so, we should change to looking for valid item names first, then trying to treat as formula
            int pos = skey.indexOf('(');
            if (pos != -1) {
                skey = skey.substring(0, pos);
            }
            if ("@accessed".equals(skey)) {
                return this.getLastAccessed();
            }
            if ("@modified".equals(skey)) {
                return this.getLastModified();
            }
            if ("@created".equals(skey)) {
                return this.getCreated();
            }
            if ("@accesseddate".equals(skey)) {
                return this.getLastAccessedDate();
            }
            if ("@modifieddate".equals(skey)) {
                return this.getLastModifiedDate();
            }
            if ("@createddate".equals(skey)) {
                return this.getCreatedDate();
            }
            if ("@documentuniqueid".equals(skey)) {
                return this.getUniversalID();
            }
            if ("@noteid".equals(skey)) {
                return this.getNoteID();
            }
            if ("@doclength".equals(skey)) {
                return this.getSize();
            }
            if ("@isresponsedoc".equals(skey)) {
                return this.isResponse();
            }
            if ("@replicaid".equals(skey)) {
                return this.getAncestorDatabase().getReplicaID();
            }
            if ("@responses".equals(skey)) {
                DocumentCollection resp = this.getResponses();
                if (resp == null) {
                    return 0;
                }
                return resp.getCount();
            }
            if ("@isnewdoc".equals(skey)) {
                return this.isNewNote();
            }
            if ("@inheriteddocumentuniqueid".equals(skey)) {
                org.openntf.domino.Document parent = this.getParentDocument();
                if (parent == null) {
                    return "";
                }
                return parent.getUniversalID();
            }
            // TODO RPr: This should be replaced
            // TODO NTF: Agreed when we can have an extensible switch for which formula engine to use
            Formula formula = new Formula();
            formula.setExpression(key.toString());
            List<?> value = formula.getValue(this);
            if (value.size() == 1) {
                return value.get(0);
            }
            return value;
        }
    }
    // TODO: What is the best way to use here without breaking everything?
    // Object value = this.getItemValue(key.toString(), Object.class);
    // Object value = this.getItemValue(key.toString(), Object[].class);
    Object value = null;
    String keyS = key.toString();
    try {
        value = this.getItemValue(keyS, Object.class);
    } catch (OpenNTFNotesException e) {
        if (e.getCause() instanceof NotesException || (e.getCause() != null && e.getCause().getCause() instanceof NotesException)) {
            value = getFirstItem(keyS, true);
        }
        if (value == null) {
            throw e;
        }
    }
    if (value instanceof Vector) {
        Vector<?> v = (Vector<?>) value;
        if (v.size() == 1) {
            return v.get(0);
        }
    }
    return value;
// if (this.containsKey(key)) {
// Vector<Object> value = this.getItemValue(key.toString());
// if (value == null) {
// //TODO Throw an exception if the item data can't be read? Null implies the key doesn't exist
// return null;
// } else if (value.size() == 1) {
// return value.get(0);
// }
// return value;
// }
// return null;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) DocumentCollection(org.openntf.domino.DocumentCollection) Formula(org.openntf.domino.helpers.Formula) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) EmbeddedObject(org.openntf.domino.EmbeddedObject) Vector(java.util.Vector) ItemVector(org.openntf.domino.iterators.ItemVector)

Example 2 with DocumentCollection

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

the class Database method getModifiedDocuments.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Database#getModifiedDocuments(lotus.domino.DateTime, int)
	 */
@Override
public DocumentCollection getModifiedDocuments(final lotus.domino.DateTime since, final int noteClass) {
    try {
        DocumentCollection result;
        lotus.domino.DateTime dt = toLotus(since);
        result = fromLotus(getDelegate().getModifiedDocuments(dt, noteClass), DocumentCollection.SCHEMA, this);
        if (since instanceof Encapsulated) {
            dt.recycle();
        }
        return result;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : Encapsulated(org.openntf.domino.types.Encapsulated) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) DocumentCollection(org.openntf.domino.DocumentCollection)

Example 3 with DocumentCollection

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

the class Database method getModifiedDocuments.

@Override
public DocumentCollection getModifiedDocuments(java.util.Date since, final ModifiedDocClass noteClass) {
    try {
        DocumentCollection result;
        if (since == null) {
            since = new Date(0);
        }
        lotus.domino.DateTime tempDT = getAncestorSession().createDateTime(since);
        lotus.domino.DateTime dt = toLotus(tempDT);
        if (!getDelegate().isOpen()) {
            getDelegate().open();
        }
        result = fromLotus(getDelegate().getModifiedDocuments(dt, noteClass.getValue()), DocumentCollection.SCHEMA, this);
        if (tempDT instanceof Encapsulated) {
            dt.recycle();
        }
        return result;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : Encapsulated(org.openntf.domino.types.Encapsulated) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) DocumentCollection(org.openntf.domino.DocumentCollection) Date(java.util.Date)

Example 4 with DocumentCollection

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

the class Database method createMergeableDocumentCollection.

@Override
@Incomplete
public DocumentCollection createMergeableDocumentCollection() {
    try {
        lotus.domino.Database db = getDelegate();
        if (!db.isOpen()) {
            db.open();
        }
        // $NON-NLS-1$
        lotus.domino.DocumentCollection rawColl = getDelegate().search("@False", db.getLastModified(), 1);
        if (rawColl.getCount() > 0) {
            int[] nids = CollectionUtils.getNoteIDs(rawColl);
            for (int nid : nids) {
                rawColl.subtract(nid);
            }
        }
        org.openntf.domino.DocumentCollection result = fromLotus(rawColl, DocumentCollection.SCHEMA, this);
        return result;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) DocumentCollection(org.openntf.domino.DocumentCollection) Incomplete(org.openntf.domino.annotations.Incomplete)

Example 5 with DocumentCollection

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

the class DocumentSorter method sort.

public DocumentCollection sort() {
    long startMemory = Runtime.getRuntime().freeMemory();
    _sort();
    int[] nids = new int[dataset_.length];
    // System.out.println("Beginning merge of " + dataset_.length + " DocumentDatas");
    for (int i = 0; i < nids.length; i++) {
        nids[i] = dataset_[i].nid_;
    }
    DocumentCollection result = new DocumentList(nids, database_);
    // for (DocumentData data : dataset_) {
    // result.merge(data.nid_);
    // }
    // System.out.println("Completed merge for a result size of " + result.getCount());
    long endMemory = Runtime.getRuntime().freeMemory();
    if (debug) {
        System.out.println("Total memory consumed: " + (endMemory - startMemory) / 1024 + "KB");
    }
    return result;
}
Also used : DocumentList(org.openntf.domino.iterators.DocumentList) DocumentCollection(org.openntf.domino.DocumentCollection)

Aggregations

DocumentCollection (org.openntf.domino.DocumentCollection)23 Database (org.openntf.domino.Database)9 NotesException (lotus.domino.NotesException)8 Document (org.openntf.domino.Document)8 Session (org.openntf.domino.Session)7 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 DateTime (org.openntf.domino.DateTime)4 HashMap (java.util.HashMap)3 Vector (java.util.Vector)3 View (org.openntf.domino.View)3 DocumentSorter (org.openntf.domino.helpers.DocumentSorter)3 Encapsulated (org.openntf.domino.types.Encapsulated)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Map (java.util.Map)2 Test (org.junit.Test)2 Item (org.openntf.domino.Item)2 NoteCollection (org.openntf.domino.NoteCollection)2