manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1444994 - in /manifoldcf/trunk: CHANGES.txt connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
Date Mon, 11 Feb 2013 23:46:09 GMT
Author: kwright
Date: Mon Feb 11 23:46:08 2013
New Revision: 1444994

URL: http://svn.apache.org/r1444994
Log:
Final checkin for CONNECTORS-641.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1444994&r1=1444993&r2=1444994&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Mon Feb 11 23:46:08 2013
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 1.2-dev =====================
 
+CONNECTORS-641: Add filename, mimetype, acls, and proper escaping
+to ElasticSearch connector.
+(Karl Wright)
+
 CONNECTORS-633: Remove dependency on custom version of xerces;
 extend the simple tag parser to be able to handle XML, and move it into
 core/fuzzyml for general use.

Modified: manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java?rev=1444994&r1=1444993&r2=1444994&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
(original)
+++ manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchIndex.java
Mon Feb 11 23:46:08 2013
@@ -42,6 +42,11 @@ import org.apache.manifoldcf.crawler.sys
 public class ElasticSearchIndex extends ElasticSearchConnection
 {
 
+  /** The allow attribute name */
+  protected final static String allowAttributeName = "allow_token_";
+  /** The deny attribute name */
+  protected final static String denyAttributeName = "deny_token_";
+
   private class IndexRequestEntity implements HttpEntity
   {
 
@@ -90,31 +95,18 @@ public class ElasticSearchIndex extends 
       {
         pw.print("{");
         Iterator<String> i = document.getFields();
-        boolean existentFields = false;
+        boolean needComma = false;
         while (i.hasNext()){
           String fieldName = i.next();
           String[] fieldValues = document.getFieldAsStrings(fieldName);
-          if(fieldValues.length>1){
-            for(int j=0; j<fieldValues.length; j++){
-              String fieldValue = fieldValues[j];
-              pw.print(jsonStringEscape(fieldName)+" : "+jsonStringEscape(fieldValue));
-              if(j<fieldValues.length-1){
-                pw.print(",");
-              }
-              existentFields = true;
-            }
-          } else if(fieldValues.length==1){
-            String fieldValue = fieldValues[0];
-            pw.print(jsonStringEscape(fieldName)+" : "+jsonStringEscape(fieldValue));
-            if(i.hasNext()){
-              pw.print(",");
-            }
-            existentFields = true;
-          }
+          needComma = writeField(pw, needComma, fieldName, fieldValues);
         }
-        
+
+        needComma = writeACLs(pw, needComma, "document", document.getACL(), document.getDenyACL());
+        needComma = writeACLs(pw, needComma, "share", document.getShareACL(), document.getShareDenyACL());
+
         if(inputStream!=null){
-          if(existentFields){
+          if(needComma){
             pw.print(",");
           }
           pw.print("\"type\" : \"attachment\",");
@@ -158,6 +150,31 @@ public class ElasticSearchIndex extends 
 
   }
 
+  protected static boolean writeField(PrintWriter pw, boolean needComma,
+    String fieldName, String[] fieldValues)
+    throws IOException
+  {
+    for(int j=0; j<fieldValues.length; j++){
+      if (needComma)
+        pw.print(",");
+      String fieldValue = fieldValues[j];
+      pw.print(jsonStringEscape(fieldName)+" : "+jsonStringEscape(fieldValue));
+      needComma = true;
+    }
+    return needComma;
+  }
+  
+  /** Output an acl level */
+  protected static boolean writeACLs(PrintWriter pw, boolean needComma,
+    String aclType, String[] acl, String[] denyAcl)
+    throws IOException
+  {
+    String metadataACLName = allowAttributeName + aclType;
+    needComma = writeField(pw,needComma,metadataACLName,acl);
+    String metadataDenyACLName = denyAttributeName + aclType;
+    return writeField(pw,needComma,metadataDenyACLName,denyAcl);
+  }
+
   protected static String jsonStringEscape(String value)
   {
     StringBuilder sb = new StringBuilder("\"");
@@ -172,6 +189,7 @@ public class ElasticSearchIndex extends 
     return sb.toString();
   }
   
+
   public ElasticSearchIndex(HttpClient client, ElasticSearchConfig config)
   {
     super(config, client);



Mime
View raw message