mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Google doc integration
- fix to prevent document upload freezing when documents large git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20344 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,16 +20,13 @@ package org.alfresco.repo.googledocs;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies;
|
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies;
|
||||||
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCheckIn;
|
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCheckIn;
|
||||||
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckIn;
|
|
||||||
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckOut;
|
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckOut;
|
||||||
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
||||||
import org.alfresco.repo.copy.CopyDetails;
|
import org.alfresco.repo.copy.CopyDetails;
|
||||||
@@ -181,38 +178,20 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
|
|||||||
*/
|
*/
|
||||||
public void onCheckOut(NodeRef workingCopy)
|
public void onCheckOut(NodeRef workingCopy)
|
||||||
{
|
{
|
||||||
if (nodeService.exists(workingCopy) == true)
|
if (nodeService.exists(workingCopy) == true && isUpload() == false)
|
||||||
{
|
{
|
||||||
// Upload the content of the working copy to google docs
|
// Upload the content of the working copy to google docs
|
||||||
googleDocsService.createGoogleDoc(workingCopy, GoogleDocsPermissionContext.SHARE_WRITE);
|
googleDocsService.createGoogleDoc(workingCopy, GoogleDocsPermissionContext.SHARE_WRITE);
|
||||||
|
|
||||||
// Mark checkout
|
|
||||||
markCheckOut(workingCopy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String KEY_CHECKEDOUT = "googleeditableaspect.checkedout";
|
private boolean isUpload()
|
||||||
|
|
||||||
private void markCheckOut(NodeRef nodeRef)
|
|
||||||
{
|
|
||||||
List<NodeRef> resources = (List<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_CHECKEDOUT);
|
|
||||||
if (resources == null)
|
|
||||||
{
|
|
||||||
// bind pending rules to the current transaction
|
|
||||||
resources = new ArrayList<NodeRef>();
|
|
||||||
AlfrescoTransactionSupport.bindResource(KEY_CHECKEDOUT, resources);
|
|
||||||
}
|
|
||||||
resources.add(nodeRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isMarkedCheckOut(NodeRef nodeRef)
|
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
List<NodeRef> resources = (List<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_CHECKEDOUT);
|
String value = (String)AlfrescoTransactionSupport.getResource("checkoutforupload");
|
||||||
if (resources != null &&
|
if (value != null)
|
||||||
resources.contains(nodeRef) == true)
|
|
||||||
{
|
{
|
||||||
result = true;
|
result = Boolean.parseBoolean(value);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -223,7 +202,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
|
|||||||
{
|
{
|
||||||
if (nodeService.exists(workingCopyNodeRef) == true &&
|
if (nodeService.exists(workingCopyNodeRef) == true &&
|
||||||
nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true &&
|
nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true &&
|
||||||
isMarkedCheckOut(workingCopyNodeRef) == false)
|
isUpload() == false)
|
||||||
{
|
{
|
||||||
// Get input stream for the google doc
|
// Get input stream for the google doc
|
||||||
InputStream is = googleDocsService.getGoogleDocContent(workingCopyNodeRef);
|
InputStream is = googleDocsService.getGoogleDocContent(workingCopyNodeRef);
|
||||||
@@ -243,7 +222,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
|
|||||||
*/
|
*/
|
||||||
public void beforeDeleteNode(NodeRef nodeRef)
|
public void beforeDeleteNode(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
if (nodeService.exists(nodeRef) == true)
|
if (nodeService.exists(nodeRef) == true && isUpload() == false)
|
||||||
{
|
{
|
||||||
// Delete the associated google resource
|
// Delete the associated google resource
|
||||||
googleDocsService.deleteGoogleResource(nodeRef);
|
googleDocsService.deleteGoogleResource(nodeRef);
|
||||||
|
@@ -49,6 +49,8 @@ import org.alfresco.repo.thumbnail.CreateThumbnailActionExecuter;
|
|||||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||||
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
|
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
|
||||||
import org.alfresco.repo.thumbnail.script.ScriptThumbnail;
|
import org.alfresco.repo.thumbnail.script.ScriptThumbnail;
|
||||||
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
|
import org.alfresco.repo.transaction.TransactionUtil;
|
||||||
import org.alfresco.repo.version.VersionModel;
|
import org.alfresco.repo.version.VersionModel;
|
||||||
import org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance;
|
import org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance;
|
||||||
import org.alfresco.scripts.ScriptException;
|
import org.alfresco.scripts.ScriptException;
|
||||||
@@ -1953,6 +1955,17 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
|||||||
return workingCopy;
|
return workingCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a check-out of this document for the purposes of an upload
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ScriptNode checkoutForUpload()
|
||||||
|
{
|
||||||
|
AlfrescoTransactionSupport.bindResource("checkoutforupload", Boolean.TRUE.toString());
|
||||||
|
return checkout();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a check-out of this document into the specified destination space.
|
* Perform a check-out of this document into the specified destination space.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user