mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Google docs delete reliability improved
- Google doc remove now happens at the end of the transaction when its commited to help ensure the Alfresco state and google doc state are more likely insync - Changed behaviour to remove content when object is deleted. Ensures correct behaviour on check-in, cancel check-in and if a object (inlcuding folder) is deleted. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20223 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -86,6 +86,10 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
public static final String TYPE_PRESENTATION = "presentation";
|
public static final String TYPE_PRESENTATION = "presentation";
|
||||||
public static final String TYPE_PDF = "pdf";
|
public static final String TYPE_PDF = "pdf";
|
||||||
|
|
||||||
|
/** Transaction resource keys */
|
||||||
|
private final static String KEY_MARKED_CREATE = "google_doc_service.marked_resources";
|
||||||
|
private final static String KEY_MARKED_DELETE = "google_doc_service.marked_delete";
|
||||||
|
|
||||||
/** Services */
|
/** Services */
|
||||||
private DocsService googleDocumentService;
|
private DocsService googleDocumentService;
|
||||||
private GoogleService spreadsheetsService;
|
private GoogleService spreadsheetsService;
|
||||||
@@ -327,31 +331,20 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
throw new AlfrescoRuntimeException("Unable to create google doc, because service could not be initialised.", e);
|
throw new AlfrescoRuntimeException("Unable to create google doc, because service could not be initialised.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (nodeService.hasAspect(nodeRef, ASPECT_GOOGLERESOURCE) == true)
|
||||||
{
|
{
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_GOOGLERESOURCE) == true)
|
// Get the entry
|
||||||
|
DocumentListEntry entry = getDocumentListEntry(nodeRef);
|
||||||
|
if (entry == null)
|
||||||
{
|
{
|
||||||
// Get the entry
|
throw new AlfrescoRuntimeException("Unable to find google resource to delete for node " + nodeRef.toString());
|
||||||
DocumentListEntry entry = getDocumentListEntry(nodeRef);
|
|
||||||
if (entry == null)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to find google resource to delete for node " + nodeRef.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perminantly delete the entry
|
|
||||||
googleDocumentService.delete(new URL(entry.getEditLink().getHref() + "?delete=true"), entry.getEtag());
|
|
||||||
|
|
||||||
// Remove the aspect from the node
|
|
||||||
nodeService.removeAspect(nodeRef, ASPECT_GOOGLERESOURCE);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (ServiceException e)
|
// Mark the resource for deletion upon completion of the transaction
|
||||||
{
|
markResource(KEY_MARKED_DELETE, entry.getResourceId());
|
||||||
throw new AlfrescoRuntimeException("Unable to delete google resource for the node "+ nodeRef.toString());
|
|
||||||
}
|
// Remove the aspect from the node
|
||||||
catch (IOException e)
|
nodeService.removeAspect(nodeRef, ASPECT_GOOGLERESOURCE);
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException("Unable to delete google resource for the node "+ nodeRef.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,7 +736,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
docEntry);
|
docEntry);
|
||||||
|
|
||||||
// Mark create entry
|
// Mark create entry
|
||||||
markCreated(document.getResourceId());
|
markResource(KEY_MARKED_CREATE, document.getResourceId());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@@ -854,7 +847,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
folder);
|
folder);
|
||||||
|
|
||||||
// Mark create entry
|
// Mark create entry
|
||||||
markCreated(folderEntry.getResourceId());
|
markResource(KEY_MARKED_CREATE, folderEntry.getResourceId());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@@ -979,17 +972,20 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String KEY_MARKED_RESOURCES = "GoogleDocService.marked_resources";
|
/**
|
||||||
|
* Marks a resource as created in this transaction
|
||||||
|
*
|
||||||
|
* @param resourceId resource id of created resource
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void markCreated(String resourceId)
|
private void markResource(String key, String resourceId)
|
||||||
{
|
{
|
||||||
List<String> resources = (List<String>)AlfrescoTransactionSupport.getResource(KEY_MARKED_RESOURCES);
|
List<String> resources = (List<String>)AlfrescoTransactionSupport.getResource(key);
|
||||||
if (resources == null)
|
if (resources == null)
|
||||||
{
|
{
|
||||||
// bind pending rules to the current transaction
|
// bind pending rules to the current transaction
|
||||||
resources = new ArrayList<String>();
|
resources = new ArrayList<String>();
|
||||||
AlfrescoTransactionSupport.bindResource(KEY_MARKED_RESOURCES, resources);
|
AlfrescoTransactionSupport.bindResource(key, resources);
|
||||||
// bind the rule transaction listener
|
// bind the rule transaction listener
|
||||||
AlfrescoTransactionSupport.bindListener(this);
|
AlfrescoTransactionSupport.bindListener(this);
|
||||||
}
|
}
|
||||||
@@ -998,24 +994,61 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
{
|
{
|
||||||
if (logger.isDebugEnabled() == true)
|
if (logger.isDebugEnabled() == true)
|
||||||
{
|
{
|
||||||
logger.debug("Marking created resource " + resourceId);
|
logger.debug("Marking resource " + resourceId + " with key " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
resources.add(resourceId);
|
resources.add(resourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.transaction.TransactionListenerAdapter#afterCommit()
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void afterCommit()
|
public void afterCommit()
|
||||||
{
|
{
|
||||||
// TODO go ahead and delete any resources that have be queued up for deletion ....
|
List<String> resources = (List<String>)AlfrescoTransactionSupport.getResource(KEY_MARKED_DELETE);
|
||||||
|
if (resources != null)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("Transaction commited, deleting Google resources");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String resourceId : resources)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("Deleting resource " + resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete resource
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DocumentListEntry entry = getDocumentListEntry(resourceId);
|
||||||
|
googleDocumentService.delete(new URL(entry.getEditLink().getHref() + "?delete=true"), entry.getEtag());
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
// Ignore, but log
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("Unable to delete resource " + resourceId + " during commit.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.transaction.TransactionListenerAdapter#afterRollback()
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void afterRollback()
|
public void afterRollback()
|
||||||
{
|
{
|
||||||
List<String> resources = (List<String>)AlfrescoTransactionSupport.getResource(KEY_MARKED_RESOURCES);
|
List<String> resources = (List<String>)AlfrescoTransactionSupport.getResource(KEY_MARKED_CREATE);
|
||||||
if (resources != null)
|
if (resources != null)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled() == true)
|
if (logger.isDebugEnabled() == true)
|
||||||
@@ -1038,7 +1071,11 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
|
|||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// Ignore
|
// Ignore, but log
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("Unable to delete resource " + resourceId + " during rollback.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCancelCheckOu
|
|||||||
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckIn;
|
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.node.NodeServicePolicies;
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
|
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
|
||||||
import org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy;
|
import org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy;
|
||||||
import org.alfresco.repo.policy.JavaBehaviour;
|
import org.alfresco.repo.policy.JavaBehaviour;
|
||||||
import org.alfresco.repo.policy.PolicyComponent;
|
import org.alfresco.repo.policy.PolicyComponent;
|
||||||
@@ -45,7 +46,8 @@ import org.alfresco.service.namespace.QName;
|
|||||||
public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPolicy,
|
public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPolicy,
|
||||||
CheckOutCheckInServicePolicies.OnCheckOut,
|
CheckOutCheckInServicePolicies.OnCheckOut,
|
||||||
CheckOutCheckInServicePolicies.OnCheckIn,
|
CheckOutCheckInServicePolicies.OnCheckIn,
|
||||||
CheckOutCheckInServicePolicies.BeforeCancelCheckOut
|
NodeServicePolicies.BeforeDeleteNodePolicy
|
||||||
|
//CheckOutCheckInServicePolicies.BeforeCancelCheckOut
|
||||||
{
|
{
|
||||||
/** Indicates whether behaviour is enabled or not */
|
/** Indicates whether behaviour is enabled or not */
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
@@ -130,9 +132,9 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
|
|||||||
policyComponent.bindClassBehaviour(OnCheckIn.QNAME,
|
policyComponent.bindClassBehaviour(OnCheckIn.QNAME,
|
||||||
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
|
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
|
||||||
new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT));
|
new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT));
|
||||||
policyComponent.bindClassBehaviour(BeforeCancelCheckOut.QNAME,
|
policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
|
||||||
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
|
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
|
||||||
new JavaBehaviour(this, "beforeCancelCheckOut", NotificationFrequency.FIRST_EVENT));
|
new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,19 +190,30 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
|
|||||||
writer.putContent(is);
|
writer.putContent(is);
|
||||||
|
|
||||||
// Delete the associated google resource
|
// Delete the associated google resource
|
||||||
googleDocsService.deleteGoogleResource(nodeRef);
|
//googleDocsService.deleteGoogleResource(nodeRef);
|
||||||
|
|
||||||
|
nodeService.removeAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void beforeDeleteNode(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
if (nodeService.exists(nodeRef) == true)
|
||||||
|
{
|
||||||
|
// Delete the associated google resource
|
||||||
|
googleDocsService.deleteGoogleResource(nodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCancelCheckOut#beforeCancelCheckOut(org.alfresco.service.cmr.repository.NodeRef)
|
* @see org.alfresco.repo.coci.CheckOutCheckInServicePolicies.BeforeCancelCheckOut#beforeCancelCheckOut(org.alfresco.service.cmr.repository.NodeRef)
|
||||||
*/
|
*/
|
||||||
public void beforeCancelCheckOut(NodeRef workingCopyNodeRef)
|
// public void beforeCancelCheckOut(NodeRef workingCopyNodeRef)
|
||||||
{
|
// {
|
||||||
if (nodeService.exists(workingCopyNodeRef) == true)
|
// if (nodeService.exists(workingCopyNodeRef) == true)
|
||||||
{
|
// {
|
||||||
// Delete the associated google resource
|
// // Delete the associated google resource
|
||||||
googleDocsService.deleteGoogleResource(workingCopyNodeRef);
|
// googleDocsService.deleteGoogleResource(workingCopyNodeRef);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user