manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From piergior...@apache.org
Subject svn commit: r1808360 - in /manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf: agents/output/cmisoutput/ crawler/connectors/cmis/
Date Thu, 14 Sep 2017 15:39:21 GMT
Author: piergiorgio
Date: Thu Sep 14 15:39:21 2017
New Revision: 1808360

URL: http://svn.apache.org/viewvc?rev=1808360&view=rev
Log:
completed a first working version of the removeDocument method using the content migration
flag for the CMIS Repository and Output Connectors (CONNECTORS-1356)

Modified:
    manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
    manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnectorUtils.java
    manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
    manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnectorUtils.java

Modified: manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java?rev=1808360&r1=1808359&r2=1808360&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
(original)
+++ manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
Thu Sep 14 15:39:21 2017
@@ -45,6 +45,7 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
@@ -1046,7 +1047,7 @@ public class CmisOutputConnector extends
 			folder = (Folder) session.getObjectByPath(leafParent.getPath() + CmisOutputConnectorUtils.SLASH
+ folderName);
 		} catch (CmisObjectNotFoundException onfe) {
 			Map<String, Object> props = new HashMap<String, Object>();
-		  props.put(PropertyIds.OBJECT_TYPE_ID,  "cmis:folder");
+		  props.put(PropertyIds.OBJECT_TYPE_ID,  BaseTypeId.CMIS_FOLDER.value());
 		  props.put(PropertyIds.NAME, folderName);
 		  folder = leafParent.createFolder(props);
 		  
@@ -1065,9 +1066,17 @@ public class CmisOutputConnector extends
 		getSession();
 		long startTime = System.currentTimeMillis();
 		String result = StringUtils.EMPTY;
+		
+		//append the prefix for the relative path in the target repo
+		String parentDropZonePath = parentDropZoneFolder.getPath();
+		String fullDocumentURIinTargetRepo = parentDropZonePath + documentURI;
 		try {
-			session.deleteByPath(documentURI);
-			result = DOCUMENT_DELETION_STATUS_ACCEPTED;
+			if(session.existsPath(fullDocumentURIinTargetRepo)) {
+				session.deleteByPath(fullDocumentURIinTargetRepo);
+				result = DOCUMENT_DELETION_STATUS_ACCEPTED;
+			} else {
+				result = DOCUMENT_DELETION_STATUS_REJECTED;
+			}
 		} catch (Exception e) {
 			result = DOCUMENT_DELETION_STATUS_REJECTED;
 			throw new ManifoldCFException(e.getMessage(), e);

Modified: manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnectorUtils.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnectorUtils.java?rev=1808360&r1=1808359&r2=1808360&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnectorUtils.java
(original)
+++ manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnectorUtils.java
Thu Sep 14 15:39:21 2017
@@ -21,13 +21,19 @@ package org.apache.manifoldcf.agents.out
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.util.*;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
 
 import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Property;
 import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.AtomPubParser;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
 import org.apache.chemistry.opencmis.commons.enums.PropertyType;
@@ -50,8 +56,7 @@ public class CmisOutputConnectorUtils {
     private static final String FROM_TOKEN = "from";
     public static final String SEP = " ";
     private static final String SELECT_STAR_CLAUSE = "select *";
-    private static final String OBJECT_ID_PROPERTY = "cmis:objectId";
-    private static final String OBJECT_ID_TERM = OBJECT_ID_PROPERTY + ",";
+    private static final String OBJECT_ID_TERM = PropertyIds.OBJECT_ID + ",";
     private static final String SELECT_CLAUSE_TERM_SEP = ",";
     private static final String SELECT_PREFIX = "select ";
     private final static String TOKENIZER_SEP = ",\n\t";
@@ -104,7 +109,7 @@ public class CmisOutputConnectorUtils {
                     selectTerm = term;
                     firstTermSelectClause = false;
                 } else {
-                    if (term.contains(OBJECT_ID_PROPERTY)){
+                    if (term.contains(PropertyIds.OBJECT_ID)){
                         foundObjIdClause = true;
                         cmisQueryResult = cmisQuery;
                         break;

Modified: manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java?rev=1808360&r1=1808359&r2=1808360&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
(original)
+++ manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
Thu Sep 14 15:39:21 2017
@@ -40,6 +40,7 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
@@ -48,6 +49,7 @@ import org.apache.commons.io.input.NullI
 import org.apache.commons.lang.StringUtils;
 import org.apache.manifoldcf.agents.interfaces.RepositoryDocument;
 import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
+import org.apache.manifoldcf.agents.output.cmisoutput.CmisOutputConnectorUtils;
 import org.apache.manifoldcf.core.interfaces.ConfigParams;
 import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
 import org.apache.manifoldcf.core.interfaces.IPasswordMapperActivity;
@@ -74,9 +76,6 @@ public class CmisRepositoryConnector ext
   protected final static String ACTIVITY_READ = "read document";
   protected static final String RELATIONSHIP_CHILD = "child";
 
-  private static final String CMIS_FOLDER_BASE_TYPE = "cmis:folder";
-  private static final String CMIS_DOCUMENT_BASE_TYPE = "cmis:document";
-
   // Tab name properties
 
   private static final String CMIS_SERVER_TAB_PROPERTY = "CmisRepositoryConnector.Server";
@@ -1115,7 +1114,7 @@ public class CmisRepositoryConnector ext
 
       String versionString;
 
-      if (cmisObject.getBaseType().getId().equals(CMIS_DOCUMENT_BASE_TYPE)) {
+      if (cmisObject.getBaseType().getId().equals(BaseTypeId.CMIS_DOCUMENT.value())) {
         Document document = (Document) cmisObject;
 
         // Since documents that are not current have different node id's, we can return a
constant version,
@@ -1153,17 +1152,15 @@ public class CmisRepositoryConnector ext
         try {
           String baseTypeId = cmisObject.getBaseType().getId();
 
-          if (baseTypeId.equals(CMIS_FOLDER_BASE_TYPE)) {
-
+          if (baseTypeId.equals(BaseTypeId.CMIS_FOLDER.value())) {
             // adding all the children for a folder
-
             Folder folder = (Folder) cmisObject;
             ItemIterable<CmisObject> children = folder.getChildren();
             for (CmisObject child : children) {
               activities.addDocumentReference(child.getId(), documentIdentifier,
                   RELATIONSHIP_CHILD);
             }
-          } else if(baseTypeId.equals(CMIS_DOCUMENT_BASE_TYPE)) {
+          } else if(baseTypeId.equals(BaseTypeId.CMIS_DOCUMENT.value())) {
             // content ingestion
 
             Document document = (Document) cmisObject;
@@ -1173,16 +1170,9 @@ public class CmisRepositoryConnector ext
             long fileLength = document.getContentStreamLength();
             String fileName = document.getContentStreamFileName();
             String mimeType = document.getContentStreamMimeType();
+            
             //documentURI
-            String documentURI = StringUtils.EMPTY;
-            if(enableContentMigration) {
-            	String path = document.getPropertyValue(PropertyIds.PATH);
-            	String name = document.getName();
-            	String fullContentPath = path + SLASH + name;
-            	documentURI = fullContentPath;
-            } else {
-            	documentURI = CmisRepositoryConnectorUtils.getDocumentURL(document, session);
-            }
+            String documentURI = getDocumentURI(cmisObject, enableContentMigration);
 
             // Do any filtering (which will save us work)
             if(!enableContentMigration) {
@@ -1294,6 +1284,32 @@ public class CmisRepositoryConnector ext
     }
 
   }
+  
+  private String getDocumentURI(CmisObject cmisObject, boolean enableContentMigration) throws
ManifoldCFException {
+  	String documentURI = StringUtils.EMPTY;
+  	String currentBaseTypeId = cmisObject.getBaseTypeId().value();
+  	if(StringUtils.equals(currentBaseTypeId, BaseTypeId.CMIS_DOCUMENT.value())) {
+  		Document currentDocument = (Document) cmisObject;
+  		if(enableContentMigration) {
+  			if(currentDocument.getParents() != null
+  					&& !currentDocument.getParents().isEmpty()) {
+  				String path = currentDocument.getParents().get(0).getPath();
+        	String name = currentDocument.getName();
+        	String fullContentPath = path + CmisRepositoryConnectorUtils.SLASH + name;
+        	documentURI = fullContentPath;
+  			}
+      } else {
+      	documentURI = CmisRepositoryConnectorUtils.getDocumentURL(currentDocument, session);
+      }
+  	} else if(StringUtils.equals(currentBaseTypeId, BaseTypeId.CMIS_FOLDER.value())) {
+  		Folder currentFolder = (Folder) cmisObject;
+  		String path = currentFolder.getPath();
+  		String name = currentFolder.getName();
+  		String fullContentPath = path + CmisRepositoryConnectorUtils.SLASH + name;
+  		documentURI = fullContentPath;
+  	}
+  	return documentURI;
+  }
 
   protected static void handleIOException(IOException e, String context) throws ManifoldCFException,
ServiceInterruption {
     if (e instanceof InterruptedIOException) {

Modified: manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnectorUtils.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnectorUtils.java?rev=1808360&r1=1808359&r2=1808360&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnectorUtils.java
(original)
+++ manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnectorUtils.java
Thu Sep 14 15:39:21 2017
@@ -55,6 +55,7 @@ public class CmisRepositoryConnectorUtil
     private static final String SELECT_CLAUSE_TERM_SEP = ",";
     private static final String SELECT_PREFIX = "select ";
     private final static String TOKENIZER_SEP = ",\n\t";
+    public static final String SLASH = "/";
     
     /** The standard Path property for ManifoldCF used for migrate contents **/
     private static final String CONTENT_MIGRATION_PATH_PROPERTY = "manifoldcf:path";



Mime
View raw message