manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rh...@apache.org
Subject svn commit: r1666371 - in /manifoldcf/branches/CONNECTORS-1168/connectors/searchblox: ./ connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/ connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/
Date Fri, 13 Mar 2015 08:26:02 GMT
Author: rharo
Date: Fri Mar 13 08:26:02 2015
New Revision: 1666371

URL: http://svn.apache.org/r1666371
Log:
Updated SearchBlox Document Test and Fixed Bug for deletion

Modified:
    manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/SearchBloxDocument.java
    manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/SearchBloxDocumentTest.java
    manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/pom.xml

Modified: manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/SearchBloxDocument.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/SearchBloxDocument.java?rev=1666371&r1=1666370&r2=1666371&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/SearchBloxDocument.java
(original)
+++ manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/main/java/org/apache/manifoldcf/agents/output/searchblox/SearchBloxDocument.java
Fri Mar 13 08:26:02 2015
@@ -60,14 +60,13 @@ public class SearchBloxDocument {
 		ADD_UPDATE, DELETE, STATUS, CREATE, CLEAR
 	}
     static final List<String> xmlElements= Lists.newArrayList("searchblox","document","url","title","keywords","content","description","lastmodified","size",
-            "alpha","contenttype","category","meta","acl","uid");
+            "alpha","contenttype","category","meta","uid");
 
 	static final String COLNAME_ATTRIBUTE = "colname";
 	static final String APIKEY_ATTRIBUTE = "apikey";
 	static final String NAME_ATTRIBUTE = "name";
-	static final String LOCATION_ATTRIBUTE = "location";
+	static final String UID_ATTRIBUTE = "uid";
 	static final String BOOST_ATTRIBUTE = "boost";
-	static final String ACL_TYPE_ATTRIBUTE = "boost";
 
 	private Multimap<String, Object> data_fields = HashMultimap.create();
 
@@ -151,21 +150,20 @@ public class SearchBloxDocument {
 								+ name, e);
 			}
 		}
-		data_fields.put(xmlElements.get(12), metadata);
 
-		// ACLS
-		Multimap<String, String> acls = HashMultimap.create();
+		// ACLS must be stored as metadata, as Searchblox use that construct to index custom named
fields
+        //the approach has been implemented and tested live
 		Iterator<String> aclTypes = rd.securityTypesIterator();
 		while (aclTypes.hasNext()) {
 			String aclType = aclTypes.next();
-			String[] tokens = rd.getSecurityACL(aclType);
-			for (String token : tokens)
-				acls.put(aclType, token);
-			tokens = rd.getSecurityDenyACL(aclType);
-			for (String token : tokens)
-				acls.put(aclType, token);
+			String[] allow_tokens = rd.getSecurityACL(aclType);
+			for (String token : allow_tokens)
+				metadata.put(aclType+"_allow", token);
+            String[] deny_tokens = rd.getSecurityDenyACL(aclType);
+            for (String token : deny_tokens)
+                metadata.put(aclType+"_deny", token);
 		}
-		data_fields.put(xmlElements.get(13), acls);
+        data_fields.put(xmlElements.get(12), metadata);
 	}
 
     /**
@@ -208,26 +206,20 @@ public class SearchBloxDocument {
 			throw new SearchBloxException(
 					"The Collection Name of the SearchBlox Server CAN'T be NULL");
 		document.setAttribute(COLNAME_ATTRIBUTE, colName);
+        if(action == DocumentAction.DELETE)
+            document.setAttribute(UID_ATTRIBUTE,uid);
 		root.appendChild(document);
 
-        // Uid
-        if (uid != null && !uid.isEmpty()) {
-            Element uidElement = doc.createElement(xmlElements.get(14));
-            uidElement.setTextContent(uid);
-            document.appendChild(uidElement);
-        }
-
 		if (action == DocumentAction.ADD_UPDATE) {
-			// Location
-			Collection<Object> location = data_fields.get(LOCATION_ATTRIBUTE);
-			if (location != null && !location.isEmpty()) {
-				document.setAttribute(LOCATION_ATTRIBUTE, (String) location.iterator().next());
-			}else{
-				document.setAttribute(LOCATION_ATTRIBUTE, "");
-			}
-				
+            // Uid
+            if (uid != null && !uid.isEmpty()) {
+                Element uidElement = doc.createElement(xmlElements.get(13));
+                uidElement.setTextContent(uid);
+                document.appendChild(uidElement);
+            }
+
             for(String element:xmlElements){
-                if (!element.equals(xmlElements.get(12)) && !element.equals(xmlElements.get(13))
) {
+                if (!element.equals(xmlElements.get(12))) {
                     Collection<Object> values = data_fields.get(element);
                     if (values!=null && values.size()>0) {
                         Object next = values.iterator()
@@ -252,12 +244,10 @@ public class SearchBloxDocument {
                 }
             }
 
-
 			// Metadata
             Collection<Object> metadataSet = data_fields
                     .get(xmlElements.get(12));
             if(metadataSet!=null && metadataSet.size()>0){
-            @SuppressWarnings("unchecked")
 			Multimap<String, String> metadata = (Multimap<String, String>) metadataSet.iterator().next();
 			if (metadata != null && !metadata.isEmpty()) {
 				for (String name : metadata.keySet())
@@ -268,22 +258,6 @@ public class SearchBloxDocument {
 						document.appendChild(metaElement);
 					}
 			}  }
-
-			// ACL
-            Collection<Object> aclSet = data_fields
-                    .get(xmlElements.get(13));
-            if(aclSet!=null &&aclSet.size()>0){
-            @SuppressWarnings("unchecked")
-			Multimap<String, String> acls = (Multimap<String, String>) aclSet.iterator().next();
-			if (acls != null && !acls.isEmpty()) {
-				for (String type : acls.keySet())
-					for (String value : acls.get(type)) {
-						Element aclElement = doc.createElement(xmlElements.get(13));
-						aclElement.setAttribute(ACL_TYPE_ATTRIBUTE, type);
-						aclElement.setTextContent(value);
-						document.appendChild(aclElement);
-					}
-			}  }
 		}
 
 		return getStringFromDocument(doc);

Modified: manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/SearchBloxDocumentTest.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/SearchBloxDocumentTest.java?rev=1666371&r1=1666370&r2=1666371&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/SearchBloxDocumentTest.java
(original)
+++ manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/connector/src/test/java/org/apache/manifoldcf/agents/output/searchblox/tests/SearchBloxDocumentTest.java
Fri Mar 13 08:26:02 2015
@@ -26,6 +26,7 @@ import org.apache.manifoldcf.agents.outp
 import org.apache.manifoldcf.agents.output.searchblox.SearchBloxDocument.DocumentAction;
 import org.apache.manifoldcf.agents.output.searchblox.SearchBloxDocument.IndexingFormat;
 import org.apache.manifoldcf.agents.output.searchblox.SearchBloxException;
+import org.junit.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -72,14 +73,41 @@ public class SearchBloxDocumentTest exte
         realRepoDoc.addField("content","I am a nice content in english!");
         realRepoDoc.addField("description","I am a little tiny description");
         realRepoDoc.addField("meta1","I am META1!");
+        realRepoDoc.addField("meta2","I am META2!");
         realRepoDoc.setMimeType("html");
         realRepoDoc.setBinary(stream,100);
         realRepoDoc.setCreatedDate(new Date(System.currentTimeMillis()));
+        realRepoDoc.setSecurityACL(RepositoryDocument.SECURITY_TYPE_SHARE,new String[]{"user1","user2","user3"});
+        realRepoDoc.setSecurityACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT,new String[]{"user12","user22","user33"});
+        realRepoDoc.setSecurityDenyACL(RepositoryDocument.SECURITY_TYPE_SHARE, new String[]{"user4",
"user5"});
+        realRepoDoc.setSecurityDenyACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT, new String[]{"user42",
"user52"});
+        //allowAttributeName + aclType
         return realRepoDoc;
     }
 
-    public void testXmlString() throws SearchBloxException {
+    @Test
+    public void testUpdateXmlString() throws SearchBloxException {
         String xmlGenerated=toTest.toString(IndexingFormat.XML, DocumentAction.ADD_UPDATE);
+        System.out.println(xmlGenerated);
+        String xmlExpected="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                "<searchblox apikey=\"apikey\"><document colname=\"collection1\">"
+
+                "<uid>URI</uid><title boost=\"1\">I am a nice title</title><content
boost=\"2\">I am a nice content in english!</content>" +
+                "<description boost=\"4\">I am a little tiny description</description><size>100</size><contenttype>html</contenttype>"
+
+                "<meta name=\"meta2\">I am META2!</meta><meta name=\"share_allow\">user3</meta>"
+
+                "<meta name=\"share_allow\">user2</meta><meta name=\"share_allow\">user1</meta>"
+
+                "<meta name=\"meta1\">I am META1!</meta><meta name=\"share_deny\">user4</meta>"
+
+                "<meta name=\"share_deny\">user5</meta><meta name=\"document_deny\">user52</meta>"
+
+                "<meta name=\"document_deny\">user42</meta><meta name=\"document_allow\">user22</meta>"
+
+                "<meta name=\"document_allow\">user12</meta><meta name=\"document_allow\">user33</meta></document></searchblox>";
+        assertEquals(xmlExpected,xmlGenerated);
+    }
+
+    @Test
+    public void testDeleteXmlString() throws SearchBloxException {
+        String xmlGenerated=toTest.toString(IndexingFormat.XML, DocumentAction.DELETE);
+        System.out.println(xmlGenerated);
+        String xmlExpected="<?xml version=\"1.0\" encoding=\"UTF-8\"?><searchblox
apikey=\"apikey\"><document colname=\"collection1\" uid=\"URI\"/></searchblox>";
+        assertEquals(xmlExpected,xmlGenerated);
     }
 
 }

Modified: manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/pom.xml
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/pom.xml?rev=1666371&r1=1666370&r2=1666371&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/pom.xml (original)
+++ manifoldcf/branches/CONNECTORS-1168/connectors/searchblox/pom.xml Fri Mar 13 08:26:02
2015
@@ -6,7 +6,7 @@
 	<parent>
 		<groupId>org.apache.manifoldcf</groupId>
 		<artifactId>mcf-connectors</artifactId>
-		<version>2.1-SNAPSHOT</version>
+		<version>2.0.2</version>
 	</parent>
 
 	<artifactId>mcf-searchblox-connector</artifactId>
@@ -298,6 +298,13 @@
 			<artifactId>guava</artifactId>
 			<version>15.0</version>
 		</dependency>
+		
+		<dependency>
+			<!-- jsoup HTML parser library @ http://jsoup.org/ -->
+			<groupId>org.jsoup</groupId>
+			<artifactId>jsoup</artifactId>
+			<version>1.8.1</version>
+		</dependency>
 
 		<!-- Testing dependencies -->
 
@@ -454,11 +461,5 @@
 			<artifactId>mockito-all</artifactId>
 			<version>1.9.5</version>
 		</dependency>
-		<dependency>
-			<!-- jsoup HTML parser library @ http://jsoup.org/ -->
-			<groupId>org.jsoup</groupId>
-			<artifactId>jsoup</artifactId>
-			<version>1.8.1</version>
-		</dependency>
 	</dependencies>
 </project>



Mime
View raw message