Package com.google.enterprise.connector.notes.client

Examples of com.google.enterprise.connector.notes.client.NotesDocument


    Set<String> keys = docIds.keySet();
    assertEquals(unid, keys.iterator().next());
  }
 
  public void testGetDocumentReaders() throws RepositoryException {
    NotesDocument doc = docs.get(0);
    Set<String> reader1 = notesDocManager.getDocumentReaders(
        doc.getItemValueString(NCCONST.NCITM_UNID),
        doc.getItemValueString(NCCONST.NCITM_REPLICAID));
    assertEquals(4, reader1.size());
   
    doc = docs.get(1);
    Set<String> reader2 = notesDocManager.getDocumentReaders(
        doc.getItemValueString(NCCONST.NCITM_UNID),
        doc.getItemValueString(NCCONST.NCITM_REPLICAID));
    assertEquals(0, reader2.size());
  }
View Full Code Here


        doc.getItemValueString(NCCONST.NCITM_REPLICAID));
    assertEquals(0, reader2.size());
  }
 
  public void testDeleteDocument() throws RepositoryException {
    NotesDocument doc = null;
    String unid = null;
    String repid = null;
    Connection conn = null;
    try {
      conn = notesDocManager.getDatabaseConnection();
      for (int i = 0; i < NUM_OF_DOCS/10; i++) {
        doc = docs.get(i);
        unid = doc.getItemValueString(NCCONST.NCITM_UNID);
        repid = doc.getItemValueString(NCCONST.NCITM_REPLICAID);
        assertTrue(notesDocManager.deleteDocument(unid, repid, conn));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
View Full Code Here

  public void testDeleteAttachments() throws RepositoryException {
    Connection conn = null;
    try {
      conn = notesDocManager.getDatabaseConnection();
      NotesDocument doc = docs.get(0);
      assertNotNull(doc);
     
      String unid = doc.getItemValueString(NCCONST.NCITM_UNID);
      String repid = doc.getItemValueString(NCCONST.NCITM_REPLICAID);
     
      Vector<String> attachmentNames = new Vector<String>();
      attachmentNames.add("attachment1.doc");
      attachmentNames.add("attachment2.doc");
      doc.replaceItemValue(NCCONST.ITM_GMETAATTACHMENTDOCIDS, attachmentNames);
     
      notesDocManager.addIndexedDocument(doc, conn);
      Set<String> fileNames =
          notesDocManager.getAttachmentIds(conn, unid, repid);
View Full Code Here

          NotesDatabase cdb =
              ns.getDatabase(ncs.getServer(), ncs.getDatabase());
          NotesView securityView = cdb.getView(NCCONST.VIEWSECURITY);
          for (String docId : docIds) {
            NotesViewNavigator secVN = null;
            NotesDocument dbdoc = null;
            try {
              // Extract the database and UNID from the URL
              String repId = getRepIdFromDocId(docId);
              String unid = getUNIDFromDocId(docId);
              LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
View Full Code Here

    String docid = null;
    try {
      docid = deleteDoc.getItemValueString(NCCONST.ITM_DOCID);
      NotesDocId notesId = new NotesDocId(docid);
      docidvw.refresh();
      NotesDocument prevDoc = docidvw.getDocumentByKey(docid, true);
      if (prevDoc != null) {
        prevDoc.remove(true);
      }
      deleteDoc.remove(true);
      if (!Util.isAttachment(docid)) {
        ncs.getNotesDocumentManager().deleteDocument(
            notesId.getDocId(), notesId.getReplicaId(), databaseConnection);
View Full Code Here

    // TODO:   Consider moving content to a text file and then we can cache it
    indexedDoc.removeItem(NCCONST.ITM_CONTENT);
    // Do we all ready have a document with this url all ready?
    String docid = indexedDoc.getItemValueString(NCCONST.ITM_DOCID);
    docidvw.refresh();
    NotesDocument prevDoc = docidvw.getDocumentByKey(docid, true);
    if (null != prevDoc) {
      prevDoc.remove(true);
    }

    boolean isRetained = true;
    if (!ncs.getRetainMetaData()) {
      if (!NCCONST.AUTH_CONNECTOR.equals(
View Full Code Here

          for (Iterator<String> ci = unidList.iterator(); ci.hasNext();) {
            indexedDocUnid = ci.next();
            LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
                "Checkpointing document: " + indexedDocUnid);
            try {
              NotesDocument indexedDoc = db.getDocumentByUNID(indexedDocUnid);
              if (indexedDoc.getItemValueString(NCCONST.ITM_ACTION)
                  .equalsIgnoreCase(ActionType.ADD.toString())) {
                // Handle ACL documents separately from content documents.
                if (indexedDoc.hasItem(NCCONST.NCITM_DBACL)) {
                  checkpointAcl(indexedDoc);
                } else {
                  checkpointAdd(indexedDoc, docidvw);
                }
              } else if (indexedDoc.getItemValueString(NCCONST.ITM_ACTION)
                  .equalsIgnoreCase(ActionType.DELETE.toString())) {
                checkpointDelete(indexedDoc, docidvw);
              }
              Util.recycle(indexedDoc);
              // Remove from the document list
View Full Code Here

    try {
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Loading configuration from system setup document.");

      NotesView vw = db.getView(NCCONST.VIEWSYSTEMSETUP);
      NotesDocument systemDoc = vw.getFirstDocument();
      if (null == systemDoc) {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "System configuration document not found.");
        return false;
      }

      // "." means no file extension.  Replace with an empty string if it exists.
      ExcludedExtns = (Vector<String>)
          systemDoc.getItemValue(NCCONST.SITM_EXCLUDEDEXTENSIONS);
      for (int i = 0; i < ExcludedExtns.size(); i++ ) {
        LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
            "The following file extensions will be excluded " +
            ExcludedExtns.elementAt(i).toString());
        if (ExcludedExtns.elementAt(i).equals(".")) {
          ExcludedExtns.set(i, "");
        }
      }

      MaxFileSize = 1024 * 1024 *
          systemDoc.getItemValueInteger(NCCONST.SITM_MAXFILESIZE);
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Maximum attachment size is " + MaxFileSize);

      // If 0, use the default value
      if (0 == MaxFileSize)
        MaxFileSize = 1024 * 1024 * NCCONST.DEFAULT_MAX_FILE_LIMIT;

      // Get the spool directory for processing attachments
      SpoolDir = systemDoc.getItemValueString(NCCONST.SITM_SPOOLDIR);
      if ((null == SpoolDir) || (0 == SpoolDir.length())) {
        SpoolDir = String.format("%s/%s",
            ns.getEnvironmentString(NCCONST.INIDIRECTORY, true),
            NCCONST.DEFAULT_ATTACHMENT_DIR);;
      }
      java.io.File sdir = new java.io.File(SpoolDir);

      // Make the directory and make sure we can write to it
      sdir.mkdirs();
      if (!sdir.isDirectory() || !sdir.canWrite()) {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "Can't write to spool directory " + SpoolDir);
        return false;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Attachment spool directory is set to " + SpoolDir);

      // Threshhold for polling
      maxCrawlQDepth = systemDoc.getItemValueInteger(
          NCCONST.SITM_MAXCRAWLQDEPTH);
      if (maxCrawlQDepth < 1)  {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "Invalid setting for maxCrawlQDepth: " + maxCrawlQDepth);
        return false;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "maxCrawlQDepth is " + maxCrawlQDepth);

      // Time between user/group cache updates
      cacheUpdateInterval = systemDoc.getItemValueInteger(
          NCCONST.SITM_CACHEUPDATEINTERVAL);
      if (cacheUpdateInterval < 1)  {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "Invalid setting for cache update interval: "
            + cacheUpdateInterval);
        return false;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "cacheUpdateInterval is " + cacheUpdateInterval);

      // Get the directory and see if we can open it
      directory = systemDoc.getItemValueString(
          NCCONST.SITM_DIRECTORY);
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Path to Domino directory: " + directory);

      NotesDatabase dirDb = ns.getDatabase(this.getServer(), directory);
      dirDb.recycle();

      userNameFormula = systemDoc.getItemValueString(
          NCCONST.SITM_USERNAMEFORMULA);
      if (0 == userNameFormula.length()) {
        LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
            "User Name formula is empty - using default");
        userNameFormula = NCCONST.DEFAULT_USERNAMEFORMULA;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
            "User Name formula: " + userNameFormula);

      String usernameTypeConfig = systemDoc.getItemValueString(
          NCCONST.SITM_USERNAMETYPE);
      if (usernameTypeConfig != null && usernameTypeConfig.length() > 0) {
        usernameType = NotesUsernameType.findUsernameType(
            usernameTypeConfig.toUpperCase());
      }
      LOGGER.log(Level.CONFIG, "Notes username type: " + usernameType.name());

      userSelectionFormula = systemDoc.getItemValueString(
          NCCONST.SITM_USERSELECTIONFORMULA);
      if (0 == userSelectionFormula.length()) {
        LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
            "User Selection formula is empty - using default");
        userSelectionFormula = NCCONST.DEFAULT_USERSELECTIONFORMULA;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "User Selection formula: " + userSelectionFormula);

      gsaGroupPrefix =
          systemDoc.getItemValueString(NCCONST.SITM_GSAGROUPPREFIX);
      if (null != gsaGroupPrefix) {
        gsaGroupPrefix = gsaGroupPrefix.trim();
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Group prefix: " + gsaGroupPrefix);

      // Number of docs to check when deleting
      deletionBatchSize = systemDoc.getItemValueInteger(
          NCCONST.SITM_DELETIONBATCHSIZE);
      if (deletionBatchSize < 1)  {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "Invalid setting for deletionBatchSize: " + deletionBatchSize);
        return false;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "deletionBatchSize is " + deletionBatchSize);

      // Number of crawler threads to spawn
      numCrawlerThreads = systemDoc.getItemValueInteger(
          NCCONST.SITM_NUMCRAWLERTHREADS);
      if ((numCrawlerThreads < 0) || (numCrawlerThreads > 5)) {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "Invalid setting for numCrawlerThreads: " + numCrawlerThreads);
        return false;
      }
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "numCrawlerThreads is " + numCrawlerThreads);

      // Load server regions
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD, "Loading server domains.");
      NotesView serversView = db.getView(NCCONST.VIEWSERVERS);
      serversView.refresh();
      NotesViewNavigator svn = serversView.createViewNav();
      NotesViewEntry sve = svn.getFirst();
      while (null != sve) {
        Vector<?> columnVals = sve.getColumnValues();
        String domain = columnVals.elementAt(2).toString().toLowerCase();
        if (!Strings.isNullOrEmpty(domain)) {
          if (!domain.trim().startsWith(".")) {
            domain = "." + domain.trim();
          }
        }

        // This is a problem with the Notes Java API. When the
        // server field for a given region has 1 element we get a
        // String in the server column of the ViewEntry. When
        // the server field has more than 1 element we get one
        // ViewEntry for each server value, but the value
        // returned in the getColumnValues Vector is a Vector
        // with one element.
        String server;
        Object serverObject = columnVals.elementAt(0);
        if (serverObject instanceof String) {
          server = ((String) serverObject).toLowerCase();
        } else if (serverObject instanceof Vector) {
          Vector serverVector = (Vector) serverObject;
          if (serverVector.size() == 0) {
            LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD, "Empty server value");
            continue;
          }
          server = ((String) serverVector.elementAt(0)).toLowerCase();
        } else {
            LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
                "Unknown server value " + serverObject);
            continue;
        }
        LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
            "Server {0} is in domain {1}", new Object[] { server, domain });
        serverDomainMap.put(server, domain);
        NotesViewEntry tmpsve = svn.getNext();
        sve.recycle();
        sve = tmpsve;
      }
      svn.recycle();
      serversView.recycle();
      if (0 == serverDomainMap.size()) {
        LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
            "No regions have been configured for this connector.");
        return false;
      }

      // Load the mimetypes
      // TODO:  Fix the extension list to include new ones like .docx
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD, "Loading mimetypes.");
      Vector<?> mimeTypeData = systemDoc.getItemValue(NCCONST.SITM_MIMETYPES);
      HashMap<String, String> tmpMimeExtnMap = new HashMap<String, String>();
      for (int i = 0; i < mimeTypeData.size(); i++) {
        String mimerecord = mimeTypeData.elementAt(i).toString();
        String ext = mimerecord.substring(0,
            mimerecord.indexOf('@')).toLowerCase();
        String mimetype = mimerecord.substring(mimerecord.indexOf('@') + 1);
        String TmpMsg = String.format(
            "File extension %s is set for mimetype %s", ext, mimetype);
        LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD, TmpMsg);
        tmpMimeExtnMap.put(ext, mimetype);
      }
      // Load into a new map then reassign to minimize threading issues
      MimeTypeMap = tmpMimeExtnMap;

      String retainMetaDataConfig =
          systemDoc.getItemValueString(NCCONST.SITM_RETAINMETADATA);
      retainMetaData = "yes".equalsIgnoreCase(retainMetaDataConfig);
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "RetainMetaData configured value: " + retainMetaDataConfig);
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "RetainMetaData: " + retainMetaData);

      systemDoc.recycle();
      LOGGER.logp(Level.CONFIG, CLASS_NAME, METHOD,
          "Configuration successfully loaded.");
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, CLASS_NAME, e);
      return false;
View Full Code Here

          ncs.getServer(), ncs.getDatabase());

      // Reset the last update date for each configured database
      NotesView incrawlView = cdb.getView(NCCONST.VIEWINCRAWL);
      incrawlView.refresh();
      NotesDocument srcDoc = incrawlView.getFirstDocument();
      while (null != srcDoc) {
        LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
            "Connector starting - Resetting crawl document found " +
            "in INCRAWL state " + srcDoc.getUniversalID());
        srcDoc.replaceItemValue(NCCONST.NCITM_STATE, NCCONST.STATENEW);
        NotesDocument prevDoc = srcDoc;
        srcDoc = incrawlView.getNextDocument(prevDoc);

        // Don't save this until we have the next doc in the view.
        // Otherwise an exception will result
        prevDoc.save();
        prevDoc.recycle();
      }
      incrawlView.recycle();
    } catch (Exception e) {
      LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
          "Error resetting crawl document.", e);
View Full Code Here

  protected boolean prefetchDoc(NotesDocument crawlDoc) {
    final String METHOD = "prefetchDoc";
    LOGGER.entering(CLASS_NAME, METHOD);

    String NotesURL = null;
    NotesDocument srcDoc = null;
    try {
      NotesURL = crawlDoc.getItemValueString(NCCONST.ITM_GMETANOTESLINK);
      LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
          "Prefetching document " + NotesURL);

      // Get the template for this document
      loadTemplateDoc(crawlDoc.getItemValueString(NCCONST.NCITM_TEMPLATE));
      if (null == templateDoc) {
        LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
            "No template found for document " +
            crawlDoc.getItemValueString(NCCONST.ITM_GMETANOTESLINK));
        return false;
      }

      // Check to see if the database we all ready have open is
      // the right one by comparing replicaids
      String crawlDocDbRepId = crawlDoc.getItemValueString(
          NCCONST.NCITM_REPLICAID);
      if (!crawlDocDbRepId.contentEquals(openDbRepId)) {
        // Different ReplicaId - Recycle and close the old database
        if (srcdb != null) {
          srcdb.recycle();
          srcdb= null;
        }
        // Open the new database
        srcdb = ns.getDatabase(null, null);
        srcdb.openByReplicaID(crawlDoc.getItemValueString(
                NCCONST.NCITM_SERVER), crawlDocDbRepId);
        openDbRepId = crawlDocDbRepId;
      }

      // Load our source document
      srcDoc = srcdb.getDocumentByUNID(crawlDoc.getItemValueString(
              NCCONST.NCITM_UNID));
      // Get the form configuration for this document
      loadForm(srcDoc.getItemValueString(NCCONST.ITMFORM));
      if (null == formDoc) {
        LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
            "No form definition found.  Using template definition " +
            "to process document " + NotesURL);
      }

      boolean hasReaders = getDocumentReaderNames(crawlDoc, srcDoc);
      if (hasReaders) {
        if (NCCONST.AUTH_ACL.equals(
            crawlDoc.getItemValueString(NCCONST.NCITM_AUTHTYPE))) {

          // Continue processing doc if GSA supports inherited
          // ACLs. Return false if not; doc won't be indexed.
          if (!((NotesTraversalManager) ncs.getTraversalManager())
              .getTraversalContext().supportsInheritedAcls()) {
            LOGGER.logp(Level.WARNING, CLASS_NAME, METHOD,
                "Document " + NotesURL + " has document-level security, "
                + "but the connector is configured to use database-level "
                + "Policy ACLs. This document will not be indexed.");
            return false;
          }
        }
      }
      setDocumentSecurity(crawlDoc, srcDoc);

      mapFields(crawlDoc, srcDoc);
      mapMetaFields(crawlDoc, srcDoc);

      // Process the attachments associated with this document
      // When there are multiple attachments with the same name
      // Lotus Notes automatically generates unique names for next document
      Vector<?> va = ns.evaluate("@AttachmentNames", srcDoc);
      Vector<String> docIds = new Vector<String>();

      NotesItem attachItems = crawlDoc.replaceItemValue(
          NCCONST.ITM_GMETAATTACHMENTS, "");
      for (int i = 0; i < va.size(); i++) {
        String attachName = va.elementAt(i).toString();

        if (attachName.length() == 0) {
          continue;
        }
        String xtn = null;
        int period = attachName.lastIndexOf(".");
        if (period == -1) {
          xtn = "";
        } else {
          xtn = attachName.substring(period + 1);
        }
        if (!ncs.isExcludedExtension(xtn.toLowerCase())) {
          String docId = createAttachmentDoc(crawlDoc, srcDoc,
              attachName, ncs.getMimeType(xtn));
          if (docId != null) {
            attachItems.appendToTextList(attachName);
            docIds.add(docId);
          } else {
            LOGGER.log(Level.FINER,
                "Attachment document was not created for {0}", attachName);
          }
        } else {
          LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
              "Excluding attachment in " + NotesURL + " : " + attachName);
        }
      }
      crawlDoc.replaceItemValue(NCCONST.ITM_GMETAALLATTACHMENTS, va);
      crawlDoc.replaceItemValue(NCCONST.ITM_GMETAATTACHMENTDOCIDS, docIds);

      // Get our content after processing attachments
      // We don't want the document content in the attachment docs
      // Our content must be stored as non-summary rich text to
      // avoid the 32/64K limits in Domino
      NotesRichTextItem contentItem = crawlDoc.createRichTextItem(
          NCCONST.ITM_CONTENT);
      String content = getContentFields(srcDoc);
      contentItem.appendText(content);
      contentItem.setSummary(false);

      // Update the status of the document to be fetched.
      crawlDoc.replaceItemValue(NCCONST.ITM_ACTION, ActionType.ADD.toString());
      srcDoc.recycle();

      // Check attachments against H2 database and create delete requests for
      // attachments which no longer exist in source document.
      NotesDocId notesDocId =
          new NotesDocId(crawlDoc.getItemValueString(NCCONST.ITM_DOCID));
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.notes.client.NotesDocument

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.