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();
}
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);
}
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);
}
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;
}
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;
}
Aggregations