Search in sources :

Example 11 with DocumentCollection

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

the class Connect17Documents method run.

@Override
public void run() {
    Session sess = Factory.getSession(SessionType.NATIVE);
    Database extLib = sess.getDatabase("odademo/oda_1.nsf");
    View contacts = extLib.getView("AllContacts");
    View threads = extLib.getView("AllThreadsByAuthor");
    Document doc = contacts.getFirstDocument();
    // Clears changes this function already made
    resetDoc(doc);
    Document newDoc = extLib.createDocument();
    doc.copyAllItems(newDoc, true);
    String prevDocAsJson = doc.toJson(true);
    doc.appendItemValue("State", "AZ");
    doc.replaceItemValue("DateTimeField", new Date());
    doc.replaceItemValue("DateOnlyField", new java.sql.Date(System.currentTimeMillis()));
    System.out.println(doc.getFirstItem("DateOnlyField").getValues());
    doc.replaceItemValue("TimeOnlyField", new java.sql.Time(System.currentTimeMillis()));
    System.out.println(doc.getFirstItem("TimeOnlyField").getValues());
    doc.replaceItemValue("EmptyDate", "");
    Date blankDate = doc.getItemValue("EmptyDate", Date.class);
    System.out.println(blankDate);
    ArrayList<String> list = new ArrayList<String>();
    list.add("Value 1");
    list.add("Value 2");
    doc.replaceItemValue("MVField", list);
    doc.replaceItemValue("DocAsJson", prevDocAsJson);
    HashMap<String, String> mapField = new HashMap<String, String>();
    DocumentCollection dc = threads.getAllDocumentsByKey(doc.getItemValueString("FullName"));
    for (Document tmp : dc) {
        mapField.put(tmp.getUniversalID(), tmp.getItemValueString("Title"));
    }
    doc.put("MapField", mapField);
    BigDecimal decimal = new BigDecimal("2.5");
    doc.replaceItemValue("BigDecimalField", decimal);
    doc.replaceItemValue("EnumField", Fixes.FORCE_HEX_LOWER_CASE);
    doc.save();
    HashMap tmp = doc.getItemValue("MapField", HashMap.class);
    System.out.println(tmp.size());
    System.out.println(doc.getMetaversalID());
    System.out.println(doc.getItemValueString("EnumField"));
    java.sql.Date sqlDt = doc.getItemValue("DateTimeField", java.sql.Date.class);
    System.out.println(sqlDt);
    java.sql.Time sqlTime = doc.getItemValue("DateTimeField", java.sql.Time.class);
    System.out.println(sqlTime);
    System.out.println(doc.getItemValues("BigDecimalField", BigDecimal.class));
    System.out.println(doc.getFirstItem("MVField").getTypeEx());
    ArrayList<String> blank = new ArrayList<String>();
    doc.replaceItemValue("MVField", blank);
    System.out.println(doc.hasItem("MVField"));
    NamesList names = new NamesList();
    names.add("CN=Paul Withers/O=Intec");
    names.add("CN=Admin/O=Intec=PW");
    newDoc.replaceItemValue("Names", names);
    AuthorsList authors = new AuthorsList();
    authors.addAll(names);
    newDoc.replaceItemValue("Authors", authors);
    ReadersList readers = new ReadersList();
    readers.addAll(names);
    newDoc.replaceItemValue("Readers", readers);
    Item dt = newDoc.replaceItemValue("TestDate", "");
    Vector<DateTime> dates = new Vector();
    DateTime dt1 = sess.createDateTime("01/01/2017");
    DateTime dt2 = sess.createDateTime("02/01/2017");
    dates.add(dt1);
    dates.add(dt2);
    dt.setValues(dates);
    newDoc.save();
}
Also used : NamesList(org.openntf.domino.types.NamesList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.openntf.domino.Document) DocumentCollection(org.openntf.domino.DocumentCollection) View(org.openntf.domino.View) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateTime(org.openntf.domino.DateTime) Item(org.openntf.domino.Item) AuthorsList(org.openntf.domino.types.AuthorsList) Database(org.openntf.domino.Database) ReadersList(org.openntf.domino.types.ReadersList) Vector(java.util.Vector) Session(org.openntf.domino.Session)

Example 12 with DocumentCollection

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

the class TestDocuments method testDocumentCollectionParent.

/**
 * Tests for https://github.com/OpenNTF/org.openntf.domino/issues/55
 */
@Test
public void testDocumentCollectionParent() {
    Session session = Factory.getSession();
    Database database = session.getDatabase(AllTests.EMPTY_DB);
    {
        DocumentCollection docs = database.getAllDocuments();
        assertTrue("docs parent should be a database", docs.getParent() instanceof Database);
    }
    {
        Document doc = database.createDocument();
        doc.save();
        Document child = database.createDocument();
        child.makeResponse(doc);
        child.save();
        DocumentCollection children = doc.getResponses();
        assertTrue("children parent should be a database", children.getParent() instanceof Database);
    }
}
Also used : Database(org.openntf.domino.Database) DocumentCollection(org.openntf.domino.DocumentCollection) Document(org.openntf.domino.Document) Session(org.openntf.domino.Session) Test(org.junit.Test)

Example 13 with DocumentCollection

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

the class LargishSortedCollectionTest method run.

@Override
public void run() {
    long testStartTime = System.nanoTime();
    Session session = Factory.getSession(SessionType.CURRENT);
    // Database db = session.getDatabase("", "events4.nsf");
    Database db = session.getDatabase("", "events4.nsf");
    // System.out.println("Starting build of byMod view");
    // long vStartTime = System.nanoTime();
    // View newView = db.createView("ModTest", "SELECT @All");
    // ViewColumn modCol = newView.createColumn(1, "Modified", "@Modified");
    // modCol.setSorted(true);
    // newView.refresh();
    // long vEndTime = System.nanoTime();
    // System.out.println("Completed building byModView in " + ((vEndTime - vStartTime) / 1000000) + "ms");
    // IndexDatabase index = new IndexDatabase(session.getDatabase("", "redpill/index.nsf"));
    // Document indexDoc = index.getDbDocument(db.getReplicaID());
    // System.out.println("UNSORTED");
    List<String> criteria = new ArrayList<String>();
    // criteria.add("@doclength");
    criteria.add("@modifieddate");
    try {
        DocumentSorter sorter = null;
        // if (indexDoc.hasItem("DocumentSorter")) {
        // sorter = indexDoc.getItemValue("DocumentSorter", DocumentSorter.class);
        // sorter.setDatabase(db);
        // System.out.println("Starting resort of " + sorter.getCount() + " documents");
        // } else {
        DocumentCollection coll = db.getAllDocuments();
        sorter = new DocumentSorter(coll, criteria);
        System.out.println("Starting resort of " + coll.getCount() + " documents");
        // }
        // System.out.println("SORTING...");
        long startTime = System.nanoTime();
        DocumentCollection sortedColl = sorter.sort();
        long endTime = System.nanoTime();
        System.out.println("Completed resort of " + sortedColl.getCount() + " in " + ((endTime - startTime) / 1000000) + " ms");
    // int count = 0;
    // for (Document doc : sortedColl) {
    // //				System.out.println(doc.getLastModifiedDate().getTime() + " " + doc.getNoteID());
    // if (++count > 500) {
    // break;
    // }
    // }
    // indexDoc.replaceItemValue("DocumentList", sortedColl);
    // indexDoc.replaceItemValue("DocumentSorter", sorter);
    // indexDoc.save();
    // System.out.println("Saved sorter and result list to document of length " + (indexDoc.getSize() / 1024) + "KB");
    // System.out.println("SORTED");
    // for (Document doc : sortedColl) {
    // System.out.println(doc.getItemValueString("MainSortValue") + " " + doc.getLastModifiedDate().getTime());
    // }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    long testEndTime = System.nanoTime();
    System.out.println("Completed " + getClass().getSimpleName() + " run in " + ((testEndTime - testStartTime) / 1000000000) + " s");
// View modView = db.getView("AllByLengthMod");
// long startTime = System.nanoTime();
// if (modView != null) {
// modView.refresh();
// }
// long endTime = System.nanoTime();
// System.out.println("Completed view build in " + ((endTime - startTime) / 1000000) + "ms");
}
Also used : Database(org.openntf.domino.Database) ArrayList(java.util.ArrayList) DocumentSorter(org.openntf.domino.helpers.DocumentSorter) DocumentCollection(org.openntf.domino.DocumentCollection) Session(org.openntf.domino.Session)

Example 14 with DocumentCollection

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

the class Connect17Transaction method queueTransaction.

private void queueTransaction(final Database db, final String state) {
    boolean toggle = true;
    int count = 0;
    View contacts = db.getView("AllContactsByState");
    DocumentCollection dc = contacts.getAllDocumentsByKey(state, true);
    for (Document doc : dc) {
        if (toggle) {
            doc.replaceItemValue("txnTest", new Date());
            count += 1;
        }
        toggle = !toggle;
    }
    System.out.println("...Updated " + Integer.toString(count) + " Contacts pending committal.");
}
Also used : DocumentCollection(org.openntf.domino.DocumentCollection) Document(org.openntf.domino.Document) View(org.openntf.domino.View) Date(java.util.Date)

Example 15 with DocumentCollection

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

the class Connect17SyncHelper method run.

@Override
public void run() {
    Session sess = Factory.getSession(SessionType.NATIVE);
    Database extLib = sess.getDatabase("odademo/oda_1.nsf");
    java.util.Map<Object, String> syncMap = new java.util.HashMap<Object, String>();
    syncMap.put("Key", "State");
    syncMap.put("Name", "StateName");
    syncMap.put("@Now", "LastSync");
    DocumentSyncHelper helper = new DocumentSyncHelper(DocumentSyncHelper.Strategy.CREATE_AND_REPLACE, syncMap, extLib.getServer(), extLib.getFilePath(), "AllContactsByState", "Key");
    View states = extLib.getView("AllStates");
    DocumentCollection sourceCollection = states.getAllDocuments();
    helper.process(sourceCollection);
    System.out.println("Updated " + sourceCollection.getCount() + " documents");
}
Also used : Database(org.openntf.domino.Database) DocumentSyncHelper(org.openntf.domino.helpers.DocumentSyncHelper) DocumentCollection(org.openntf.domino.DocumentCollection) View(org.openntf.domino.View) Session(org.openntf.domino.Session)

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