Package com.google.enterprise.connector.spi

Examples of com.google.enterprise.connector.spi.DocumentList

Boundary cases are important for {@link #checkpoint()}: The typical pattern for consuming an object that implements this interface is as follows (disregarding exception handling):
 DocumentList docList = ... Document doc; while (doc = docList.nextDocument()) { handleDoc(doc); if (whatever reason) break; } String check = doclist.checkpoint(); 
Note: because of the restriction that the next call to {@link #nextDocument()} invalidates the previous Document, and thereare similar restrictions in the {@link Document} interface, it is possibleto provide a single stateful object that implements {@link DocumentList}, {@link Document} and {@link Property}, by returning {@code this}(or {@code null}) to all calls to {@link #nextDocument()} and{@link Document#findProperty(String)}. However, if preferred, the implementor may also use separate objects for each of those interfaces. @since 1.0

    @SuppressWarnings("unchecked")
    MockObjectStore os =
        newObjectStore("MockObjectStore", DatabaseType.MSSQL, entries);

    // Begin testing nextDocument for exception
    DocumentList docList = getObjectUnderTest(os, getDocuments(os.getObjects()),
        getCustomDeletion(os.getObjects()), getDeletionEvents(os.getObjects()));

    SkipPosition actualPosition = SkipPosition.FIRST;
    try {
      for (Document doc = docList.nextDocument(); doc != null;
          doc = docList.nextDocument()) {
        actualPosition = SkipPosition.MIDDLE;
      }
      fail("Expect SkippedDocumentException");
    } catch (SkippedDocumentException expected) {
      if (!expected.getMessage().contains(unreleasedGuid.toString())) {
        throw expected;
      }
      if (docList.nextDocument() == null) {
        actualPosition = SkipPosition.LAST;
      }
    }
    assertEquals(expectedPosition, actualPosition);
  }
View Full Code Here


    boolean isAddTested = false;
    boolean isDeletionEventTested = false;
    boolean isCustomDeletionTested = false;

    DocumentList docList =
        getObjectUnderTest(os, docSet, customDeletionSet, deletionEventSet);
    Document doc = null;
    while ((doc = docList.nextDocument()) != null) {
      Property actionProp = doc.findProperty(SpiConstants.PROPNAME_ACTION);
      ActionType actionType = SpiConstants.ActionType.findActionType(
          actionProp.nextValue().toString());

      String id =
          doc.findProperty(SpiConstants.PROPNAME_DOCID).nextValue().toString();
      if (ActionType.ADD.equals(actionType)) {
        IBaseObject object = os.getObject(null, id);
        assertFalse(object instanceof FileDeletionObject);
        assertTrue(checkpointContains(docList.checkpoint(),
            doc.findProperty(SpiConstants.PROPNAME_LASTMODIFIED),
            JsonField.LAST_MODIFIED_TIME));
        isAddTested = true;
      } else if (ActionType.DELETE.equals(actionType)) {
        IBaseObject object = os.getObject(null, id);
        if (object.isDeletionEvent()) {
          assertTrue(checkpointContains(docList.checkpoint(),
              doc.findProperty(SpiConstants.PROPNAME_LASTMODIFIED),
              JsonField.LAST_DELETION_EVENT_TIME));
          isDeletionEventTested = true;
        } else {
          assertTrue(checkpointContains(docList.checkpoint(),
              doc.findProperty(SpiConstants.PROPNAME_LASTMODIFIED),
              JsonField.LAST_CUSTOM_DELETION_TIME));
          isCustomDeletionTested = true;
        }
      }
    }
    assertEquals(expectAddTested, isAddTested);
    assertEquals(expectCustomDeletionTested, isCustomDeletionTested);
    assertEquals(expectDeletionEventTested, isDeletionEventTested);

    String expectedCheckpoint = "{"
        + (expectAddTested
            ? "\"uuid\":\"{AAAAAAA4-0000-0000-0000-000000000000}\","
            + "\"lastModified\":\"" + CHECKPOINT_TIMESTAMP + TZ_OFFSET + "\","
            : "\"uuid\":\"{AAAAAAAA-0000-0000-0000-000000000000}\","
            + "\"lastModified\":\"1990-01-01T00:00:00.000\",")
        + (expectDeletionEventTested
            ? "\"uuidToDelete\":\"{DE000002-0000-0000-0000-000000000000}\","
            + "\"lastRemoveDate\":\"" + CHECKPOINT_TIMESTAMP + TZ_OFFSET + "\","
            : "\"uuidToDelete\":\"{BBBBBBBB-0000-0000-0000-000000000000}\","
            + "\"lastRemoveDate\":\"2000-01-01T00:00:00.000\",")
        + (expectCustomDeletionTested
            ? "\"uuidToDeleteDocs\":\"{CD000003-0000-0000-0000-000000000000}\","
            + "\"lastModifiedDate\":\"" + CHECKPOINT_TIMESTAMP + TZ_OFFSET
            + "\""
            : "\"uuidToDeleteDocs\":\"{CCCCCCCC-0000-0000-0000-000000000000}\","
            + "\"lastModifiedDate\":\"2010-01-01T00:00:00.000\"")
        + "}";
    assertCheckpointEquals(expectedCheckpoint, docList.checkpoint());
  }
View Full Code Here

  public void testCheckpointWithoutNextDocument() throws Exception {
    @SuppressWarnings("unchecked") IObjectStore os =
        newObjectStore("MockObjectStore", DatabaseType.MSSQL,
            new HashMap<IId, IBaseObject>());
    DocumentList docList = getObjectUnderTest(os, newEmptyObjectSet(),
        newEmptyObjectSet(), newEmptyObjectSet());

    assertCheckpointEquals(CHECKPOINT, docList.checkpoint());
  }
View Full Code Here

   */
  public void testEmptyCheckpointWithoutNextDocument() throws Exception {
    @SuppressWarnings("unchecked") IObjectStore os =
        newObjectStore("MockObjectStore", DatabaseType.MSSQL,
            new HashMap<IId, IBaseObject>());
    DocumentList docList = new FileDocumentList(newEmptyObjectSet(),
        newEmptyObjectSet(), newEmptyObjectSet(), os, connec, new Checkpoint());
    Checkpoint cp = new Checkpoint(docList.checkpoint());

    // The checkpoint contains empty string values for the UUIDs and
    // the current time for the dates.
    assertFalse(cp.isEmpty());
    assertEquals("", cp.getString(JsonField.UUID));
View Full Code Here

  }

  public void testStartTraversal() throws RepositoryException {
    Traverser traverser = getObjectUnderTest();
    traverser.setBatchHint(TestConnection.batchSize);
    DocumentList set = traverser.getDocumentList(new Checkpoint());
    long counter = 0;
    com.google.enterprise.connector.spi.Document doc = null;
    doc = set.nextDocument();
    while (doc != null) {
      if (counter == 113) {
        String checkpoint = set.checkpoint();
        System.out.println(checkpoint);
      }
        doc = set.nextDocument();
        counter++;
    }
    assertEquals(TestConnection.batchSize, counter);
  }
View Full Code Here

  }

  public void testResumeTraversal() throws RepositoryException {
    Traverser traverser = getObjectUnderTest();
    traverser.setBatchHint(TestConnection.batchSize);
    DocumentList set = traverser.getDocumentList(
        new Checkpoint(TestConnection.checkpoint2));
    assertNotNull(set);
    int counter = 0;
    com.google.enterprise.connector.spi.Document doc = null;
    doc = set.nextDocument();
    while (doc != null) {
      doc = set.nextDocument();
      counter++;
    }
    assertEquals(TestConnection.batchSize, counter);

  }
View Full Code Here

  }

  public void testSetBatchHint() throws RepositoryException {
    Traverser traverser = getObjectUnderTest();
    traverser.setBatchHint(10);
    DocumentList set = traverser.getDocumentList(new Checkpoint());
    int counter = 0;
    while (set.nextDocument() != null) {
      counter++;
    }
    assertEquals(10, counter);
  }
View Full Code Here

    expect(search.execute(isA(String.class))).andReturn(objectSet).times(2);
    replay(os, factory, search, objectSet);

    FileDocumentTraverser traverser =
        new FileDocumentTraverser(factory, os, connec);
    DocumentList docList = traverser.getDocumentList(new Checkpoint());
    assertNull(docList);
    verify(os, factory, search, objectSet);
  }
View Full Code Here

      throws RepositoryException {
    LOGGER.info("Start Traversal");
    long start = System.currentTimeMillis();
    int numdocs = 0;
    String checkpoint = null;
    DocumentList docList;
    traversalManager.setBatchHint(1000);
    while ((docList = traversalManager.resumeTraversal(checkpoint)) != null) {
      // We need the size and checkpoint, but peek at the internals to get them,
      // rather than iterating over the DocumentList, as that would require a
      // much better mock of the Livelink DB than we have at this point.
      if (((LivelinkDocumentList) docList).recArray != null) {
        numdocs += ((LivelinkDocumentList) docList).recArray.size();
      }
      ((LivelinkDocumentList) docList).checkpoint.advanceToEnd();
      checkpoint = docList.checkpoint();
    }
    long stop = System.currentTimeMillis();
    String msg = "End Traversal: time = " + ((stop - start)/1000) + " seconds, "
                 + "docs returned = " + numdocs;
    LOGGER.info(msg);
View Full Code Here

  }

  public void testAcl_missingGroup() throws RepositoryException, SQLException {
    insertDTreeAcl(29, 2666, Client.PERM_SEECONTENTS);

    DocumentList list = getObjectUnderTest(29, 0, 1002);
    Document doc = list.nextDocument();

    assertNotNull(doc);
    assertEquals(ImmutableSet.of(),
        getPrincipalsNames(doc, SpiConstants.PROPNAME_ACLUSERS));
    assertEquals(ImmutableSet.of(),
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.spi.DocumentList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.