Search in sources :

Example 11 with DateTime

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

the class JsonGraphWriter method outLiteral.

@Override
protected void outLiteral(Object paramObject, final boolean paramBoolean) throws IOException, JsonException {
    // paramObject.getClass().getName()));
    if (paramObject != null) {
        Class<?> objClass = paramObject.getClass();
        IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
        if (adapter != null) {
            paramObject = adapter.toJson(paramObject);
        }
    }
    if (this.getFactory().isNull(paramObject)) {
        outNull();
    // } else if (paramObject instanceof Term) {
    // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Term) paramObject, parameters_,
    // isCollectionRoute_);
    // super.outObject(adapter);
    // } else if (paramObject instanceof Value) {
    // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Value) paramObject, parameters_,
    // isCollectionRoute_);
    // super.outObject(adapter);
    // } else if (paramObject instanceof RichTextReference) {
    // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (RichTextReference) paramObject, parameters_,
    // isCollectionRoute_);
    // super.outObject(adapter);
    } else if (paramObject instanceof VertexFrame) {
        JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
        outObject(adapter);
    } else if (paramObject instanceof EdgeFrame) {
        JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
        outObject(adapter);
    } else if (paramObject instanceof Class<?>) {
        String className = ((Class) paramObject).getName();
        outStringLiteral(className);
    } else if (paramObject instanceof RichTextItem) {
        outRichTextItem((RichTextItem) paramObject);
    } else if (paramObject instanceof Enum) {
        String className = ((Enum) paramObject).getClass().getName();
        String enumName = ((Enum) paramObject).name();
        outStringLiteral(className + " " + enumName);
    } else if (paramObject instanceof CharSequence) {
        outStringLiteral(paramObject.toString());
    } else if (paramObject instanceof Set) {
        // System.out.println("TEMP DEBUG Got a set!");
        outArrayLiteral(((Set) paramObject).toArray());
    } else if (this.getFactory().isString(paramObject)) {
        outStringLiteral(this.getFactory().getString(paramObject));
    } else if (this.getFactory().isNumber(paramObject)) {
        outNumberLiteral(this.getFactory().getNumber(paramObject));
    } else if (this.getFactory().isBoolean(paramObject)) {
        outBooleanLiteral(this.getFactory().getBoolean(paramObject));
    } else if (this.getFactory().isObject(paramObject)) {
        outObject(paramObject, paramBoolean);
    } else if (this.getFactory().isArray(paramObject)) {
        outArrayLiteral(paramObject, paramBoolean);
    } else if (paramObject instanceof JsonReference) {
        outReference((JsonReference) paramObject);
    } else if (paramObject instanceof DateTime) {
        DateTime dt = (DateTime) paramObject;
        outDateLiteral_(dt.toJavaDate());
    } else if (paramObject instanceof DateRange) {
        DateRange dt = (DateRange) paramObject;
        outDateRangeLiteral(dt);
    } else if (paramObject instanceof NoteCoordinate) {
        outNoteCoordinate((NoteCoordinate) paramObject);
    } else if (paramObject instanceof Date) {
        outDateLiteral_((Date) paramObject);
    } else {
        outStringLiteral("JsonGenerator cannot process unknown type of " + ((paramObject != null) ? paramObject.getClass().getName() : "<null>"));
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.impl.NoteCoordinate) EdgeFrame(com.tinkerpop.frames.EdgeFrame) Set(java.util.Set) JsonFrameAdapter(org.openntf.domino.rest.resources.frames.JsonFrameAdapter) IJsonWriterAdapter(org.openntf.domino.rest.json.JsonGraphFactory.IJsonWriterAdapter) DateTime(org.openntf.domino.DateTime) Date(java.util.Date) JsonReference(com.ibm.commons.util.io.json.JsonReference) DateRange(org.openntf.domino.DateRange) VertexFrame(com.tinkerpop.frames.VertexFrame) RichTextItem(org.openntf.domino.RichTextItem)

Example 12 with DateTime

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

the class JsonGraphWriter method outObject.

@Override
public void outObject(Object paramObject) throws IOException, JsonException {
    // + (paramObject == null ? "NULL" : paramObject.getClass().getName()));
    try {
        if (paramObject != null) {
            Class<?> objClass = paramObject.getClass();
            IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
            if (adapter != null) {
                paramObject = adapter.toJson(paramObject);
            }
        }
        if (paramObject == null) {
            super.outNull();
        // } else if (paramObject instanceof Term) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Term) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof Value) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Value) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof RichTextReference) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (RichTextReference) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        } else if (paramObject instanceof EdgeFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof VertexFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof Class<?>) {
            String className = ((Class<?>) paramObject).getName();
            super.outStringLiteral(className);
        } else if (paramObject instanceof RichTextItem) {
            outRichTextItem((RichTextItem) paramObject);
        } else if (paramObject instanceof Enum) {
            String className = ((Enum<?>) paramObject).getClass().getName();
            String enumName = ((Enum<?>) paramObject).name();
        } else if (paramObject instanceof NoteCoordinate) {
            String nc = ((NoteCoordinate) paramObject).toString();
            super.outStringLiteral(nc);
        } else if (paramObject instanceof org.openntf.domino.impl.View.DominoColumnInfo) {
            String itemName = ((org.openntf.domino.impl.View.DominoColumnInfo) paramObject).getItemName();
            super.outStringLiteral(itemName);
        } else if (paramObject instanceof Set) {
            // System.out.println("TEMP DEBUG outObject received a Set");
            outArrayLiteral(((Set) paramObject).toArray());
        } else if (paramObject instanceof DateTime) {
            outDateLiteral((DateTime) paramObject);
        } else if (paramObject instanceof DateRange) {
            outDateRangeLiteral((DateRange) paramObject);
        } else if (paramObject instanceof NoteCoordinate) {
            outNoteCoordinate((NoteCoordinate) paramObject);
        } else if (paramObject instanceof Throwable) {
            outException((Throwable) paramObject);
        } else {
            // Class<?> clazz = paramObject.getClass();
            // String name = clazz.getName();
            super.outObject(paramObject);
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.impl.NoteCoordinate) EdgeFrame(com.tinkerpop.frames.EdgeFrame) Set(java.util.Set) JsonFrameAdapter(org.openntf.domino.rest.resources.frames.JsonFrameAdapter) IJsonWriterAdapter(org.openntf.domino.rest.json.JsonGraphFactory.IJsonWriterAdapter) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DateTime(org.openntf.domino.DateTime) DateRange(org.openntf.domino.DateRange) VertexFrame(com.tinkerpop.frames.VertexFrame) RichTextItem(org.openntf.domino.RichTextItem)

Example 13 with DateTime

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

the class Database method getCreated.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Database#getCreated()
	 */
@Override
public DateTime getCreated() {
    try {
        lotus.domino.DateTime dt = getDelegate().getCreated();
        DateTime ret = fromLotus(dt, DateTime.SCHEMA, getAncestorSession());
        s_recycle(dt);
        return ret;
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
        return null;
    }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) DateTime(org.openntf.domino.DateTime)

Example 14 with DateTime

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

the class DocumentSyncHelper method processDocument.

/**
 * Process a specific Document
 *
 * @param targetDb
 *            Database to retrieve documents to sync to
 * @param targetView
 *            View to retrieve documents to sync to
 * @param strategy
 *            Strategy to sync Items
 * @param txn
 *            DatabaseTransaction to run under
 * @param source
 *            Document to sync from
 * @return DatabaseTransaction to run under
 */
private DatabaseTransaction processDocument(final Database targetDb, final View targetView, final Strategy strategy, DatabaseTransaction txn, final Document source) {
    if (getTransactionRule() == TransactionRule.COMMIT_EVERY_SOURCE) {
        txn = targetDb.startTransaction();
    }
    DateTime sourceLastMod = source.getLastModified();
    // Object lookupKey = Factory.wrappedEvaluate(session, getSourceKeyFormula(), source);
    Object lookupKey = getSourceKeyFormula().getValue(source);
    DocumentCollection targetColl = targetView.getAllDocumentsByKey(lookupKey, true);
    for (Document target : targetColl) {
        // boolean targetDirty = false;
        for (Map.Entry<Formula, String> entry : getSyncMap().entrySet()) {
            String targetItemName = entry.getValue();
            java.util.Vector<?> sourceValue = entry.getKey().getValue(source);
            // Factory.wrappedEvaluate(session, entry.getKey(), source);
            if (strategy == Strategy.CREATE_AND_REPLACE) {
                target.replaceItemValue(targetItemName, sourceValue);
            // targetDirty = true;
            } else {
                Item targetItem = target.getFirstItem(targetItemName);
                if (strategy == Strategy.REPLACE_IF_NEWER) {
                    DateTime itemLastMod = targetItem.getLastModified();
                    if (sourceLastMod.isAfter(itemLastMod)) {
                        targetItem.setValues(sourceValue);
                    // targetDirty = true;
                    }
                } else if (strategy == Strategy.REPLACE_ONLY) {
                    if (targetItem != null) {
                        targetItem.setValues(sourceValue);
                    // targetDirty = true;
                    }
                }
            }
        }
        if (getTransactionRule() == TransactionRule.NO_TRANSACTION || txn == null) {
            target.save();
        }
    }
    if (getTransactionRule() == TransactionRule.COMMIT_EVERY_SOURCE && txn != null) {
        txn.commit();
        txn = null;
    }
    return txn;
}
Also used : Item(org.openntf.domino.Item) DocumentCollection(org.openntf.domino.DocumentCollection) Document(org.openntf.domino.Document) HashMap(java.util.HashMap) Map(java.util.Map) DateTime(org.openntf.domino.DateTime)

Example 15 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.lang.String)
	 */
@Override
public DateTime createDateTime(final String 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