Search in sources :

Example 1 with DateTime

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

the class Document method toJson.

@Override
public String toJson(final boolean compact) {
    StringWriter sw = new StringWriter();
    JsonWriter jw = new JsonWriter(sw, compact);
    try {
        jw.startObject();
        jw.outStringProperty("@unid", getUniversalID());
        jw.outStringProperty("@noteid", getNoteID());
        jw.outStringProperty("@replicaid", getParentDatabase().getReplicaID());
        jw.outStringProperty("@metaversalid", getMetaversalID());
        try {
            jw.outStringProperty("@created", getCreated().toGMTISO());
            jw.outStringProperty("@lastmodified", getLastModified().toGMTISO());
            jw.outStringProperty("@lastaccessed", getLastAccessed().toGMTISO());
        } catch (Exception e) {
            DominoUtils.handleException(e, "Exception trying to index Dates.");
        }
        Set<String> keys = keySet();
        for (String key : keys) {
            Item currItem = getFirstItem(key);
            // A beer to anyone who can work out how this could happen, except for the person who identified it!
            if (null != currItem) {
                Type itemType = currItem.getTypeEx();
                try {
                    if (itemType == Type.ATTACHMENT) {
                        jw.outProperty(key, "ATTACHMENT");
                    } else if (itemType == Type.AUTHORS || itemType == Type.READERS || itemType == Type.NAMES || itemType == Type.TEXT || itemType == Type.NUMBERS) {
                        Vector<Object> values = currItem.getValues();
                        if (values.size() == 1) {
                            jw.outProperty(key, values.elementAt(0));
                        } else {
                            jw.outProperty(key, values);
                        }
                    } else if (itemType == Type.DATETIMES) {
                        Vector<DateTime> values = currItem.getValueDateTimeArray();
                        if (values.size() == 1) {
                            jw.outProperty(key, values.get(0).toGMTISO());
                        } else {
                            jw.outProperty(key, TypeUtils.toStrings(values));
                        }
                    } else if (itemType == Type.EMBEDDEDOBJECT) {
                        jw.outProperty(key, "EMBEDDED_OBJECT");
                    } else if (itemType == Type.RICHTEXT) {
                        RichTextItem rtItem = (RichTextItem) currItem;
                        jw.outProperty(key, rtItem.getUnformattedText());
                    } else if (itemType == Type.MIME_PART) {
                        MIMEEntity mimeEntity = currItem.getMIMEEntity();
                        if (mimeEntity != null) {
                            jw.outProperty(key, mimeEntity.getContentAsText());
                        } else {
                            jw.outProperty(key, "MIME_PART null");
                        }
                    }
                } catch (Exception e) {
                    DominoUtils.handleException(e, this);
                    // NTF - temporary
                    e.printStackTrace();
                }
            }
            // if (currItem.getMIMEEntity() == null) {
            // jw.outProperty(key, currItem.getText());
            // } else {
            // String abstractedText = currItem.abstractText(0, false, false);
            // if (null == abstractedText) {
            // jw.outProperty(key, "**MIME ITEM, VALUE CANNOT BE DECODED TO JSON**");
            // } else {
            // jw.outProperty(key, abstractedText);
            // }
            // }
            // Now output attachments
            jw.outProperty("@attachments", getAttachmentNames());
        }
        jw.endObject();
        jw.flush();
    } catch (IOException e) {
        DominoUtils.handleException(e, this);
        return null;
    } catch (JsonException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
    return sw.toString();
}
Also used : JsonException(com.ibm.commons.util.io.json.JsonException) IOException(java.io.IOException) JsonWriter(com.ibm.commons.util.io.json.util.JsonWriter) 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) DateTime(org.openntf.domino.DateTime) RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) Type(org.openntf.domino.Item.Type) MIMEEntity(org.openntf.domino.MIMEEntity) StringWriter(java.io.StringWriter) RichTextItem(org.openntf.domino.RichTextItem) Vector(java.util.Vector) ItemVector(org.openntf.domino.iterators.ItemVector)

Example 2 with DateTime

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

the class DocumentSyncHelper method processSince.

/**
 * Extended method to process, allowing the developer to define to only process source documents modified since a given Java date
 *
 * @param sourceDb
 *            Database source documents are in
 * @param sinceDate
 *            Date since when documents should have been modified
 * @since org.openntf.domino 1.0.0
 */
public void processSince(final Database sourceDb, final Date sinceDate) {
    DateTime dt = sourceDb.getAncestorSession().createDateTime(sinceDate);
    DocumentCollection sourceCollection = sourceDb.getModifiedDocuments(dt, ModifiedDocClass.DATA);
    process(sourceCollection);
}
Also used : DocumentCollection(org.openntf.domino.DocumentCollection) DateTime(org.openntf.domino.DateTime)

Example 3 with DateTime

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

the class DocumentSyncHelper method processSince.

/**
 * Extended method to process, allowing the developer to define to only process source documents modified since a given Java date
 *
 * @param sourceDb
 *            Database source documents are in
 * @param sinceDate
 *            Date since when documents should have been modified
 * @param formName
 *            String form name to restrict DocumentCollection to
 * @since org.openntf.domino 1.0.0
 */
public void processSince(final Database sourceDb, final Date sinceDate, final String formName) {
    DateTime dt = sourceDb.getAncestorSession().createDateTime(sinceDate);
    DocumentCollection sourceCollection = sourceDb.getModifiedDocuments(dt, ModifiedDocClass.DATA);
    // $NON-NLS-1$ //$NON-NLS-2$
    sourceCollection.FTSearch("[Form] = \"" + formName + "\"");
    process(sourceCollection);
}
Also used : DocumentCollection(org.openntf.domino.DocumentCollection) DateTime(org.openntf.domino.DateTime)

Example 4 with DateTime

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

the class Session method createDateTime.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Session#createDateTime(java.util.Date)
	 */
@Override
public DateTime createDateTime(final Date date) {
    DateTime ret = getFactory().create(DateTime.SCHEMA, this, null);
    ret.setLocalTime(date);
    return ret;
}
Also used : DateTime(org.openntf.domino.DateTime)

Example 5 with DateTime

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

the class Session method createDateTime.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Session#createDateTime(java.util.Calendar)
	 */
@Override
public DateTime createDateTime(final Calendar date) {
    DateTime ret = getFactory().create(DateTime.SCHEMA, this, null);
    ret.setLocalTime(date);
    return ret;
}
Also used : DateTime(org.openntf.domino.DateTime)

Aggregations

DateTime (org.openntf.domino.DateTime)19 Date (java.util.Date)8 DocumentCollection (org.openntf.domino.DocumentCollection)4 Item (org.openntf.domino.Item)4 Vector (java.util.Vector)3 Document (org.openntf.domino.Document)3 RichTextItem (org.openntf.domino.RichTextItem)3 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)3 JsonException (com.ibm.commons.util.io.json.JsonException)2 EdgeFrame (com.tinkerpop.frames.EdgeFrame)2 VertexFrame (com.tinkerpop.frames.VertexFrame)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 NotesException (lotus.domino.NotesException)2 Database (org.openntf.domino.Database)2 DateRange (org.openntf.domino.DateRange)2 Session (org.openntf.domino.Session)2 NoteCoordinate (org.openntf.domino.big.impl.NoteCoordinate)2 UserAccessException (org.openntf.domino.exceptions.UserAccessException)2