diff --git a/config/alfresco/subsystems/googledocs/default/googledocs-context.xml b/config/alfresco/subsystems/googledocs/default/googledocs-context.xml index 6e1d11647d..f0f97f625c 100755 --- a/config/alfresco/subsystems/googledocs/default/googledocs-context.xml +++ b/config/alfresco/subsystems/googledocs/default/googledocs-context.xml @@ -34,7 +34,8 @@ - + + @@ -54,6 +55,5 @@ - diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java index 2170406ef4..06a60d96b2 100755 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java +++ b/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java @@ -27,6 +27,12 @@ import org.alfresco.service.cmr.repository.NodeRef; */ public interface GoogleDocsService { + /** + * Indicates whether the GoogleDocs service is enabled or not. + * @return boolean true if enabled, false otherwise + */ + boolean isEnabled(); + /** * Initialises the googles doc service, checking the provided credentials are correct. This need * not be called manually since other service calls will initialise the service on demand, but it can diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java index 79ab6403f6..45129a5ed9 100755 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java +++ b/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java @@ -106,12 +106,15 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter private AuthorityService authorityService; private DictionaryService dictionaryService; + /** Indicates whether the GDoc integration is enabled or not */ + private boolean enabled = false; + /** GoogleDoc base feed url */ private String url = "http://docs.google.com/feeds/default/private/full"; private String downloadUrl = "https://docs.google.com/feeds/download"; /** Authentication credentials */ - private boolean initialised = false; + private boolean initialised = false; private String username; private String password; @@ -246,6 +249,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter public void setUsername(String username) { this.username = username; + this.initialised = false; } /** @@ -254,6 +258,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter public void setPassword(String password) { this.password = password; + this.initialised = false; } /** @@ -263,6 +268,24 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter { this.permissionMap = permissionMap; } + + /** + * Set whether the service is enabled or not. + * @param enabled true if enabled, false otherwise + */ + public void setEnabled(boolean enabled) + { + this.enabled = enabled; + this.initialised = false; + } + + /** + * @see org.alfresco.repo.googledocs.GoogleDocsService#isEnabled() + */ + public boolean isEnabled() + { + return enabled; + } /** * Initialise google docs services diff --git a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java b/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java index 55ba86e03c..098280063a 100755 --- a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java +++ b/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java @@ -57,9 +57,6 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli CheckOutCheckInServicePolicies.OnCheckIn, NodeServicePolicies.BeforeDeleteNodePolicy { - /** Indicates whether behaviour is enabled or not */ - boolean enabled = false; - /** Policy component */ private PolicyComponent policyComponent; @@ -75,14 +72,6 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli /** Content service */ private ContentService contentService; - /** - * @param enabled true if behaviour enabled, false otherwise - */ - public void setEnabled(boolean enabled) - { - this.enabled = enabled; - } - /** * @param policyComponent policy component */ @@ -127,38 +116,35 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli * Initialise method */ public void init() - { - if (enabled == true) - { - // GoogleEditable resource behaviours - policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, - GoogleDocsModel.ASPECT_GOOGLEEDITABLE , - new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(OnCheckOut.QNAME, - GoogleDocsModel.ASPECT_GOOGLEEDITABLE, - new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT)); - - // Google resource behaviours - policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME, - GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(OnCheckIn.QNAME, - GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME, - GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)); - - // Copy behaviours - this.policyComponent.bindClassBehaviour( - QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), - GoogleDocsModel.ASPECT_GOOGLEEDITABLE, - new JavaBehaviour(this, "getGoogleEditableCopyCallback")); - this.policyComponent.bindClassBehaviour( - QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), - GoogleDocsModel.ASPECT_GOOGLERESOURCE, - new JavaBehaviour(this, "getGoogleResourceCopyCallback")); - } + { + // GoogleEditable resource behaviours + policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, + GoogleDocsModel.ASPECT_GOOGLEEDITABLE , + new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)); + policyComponent.bindClassBehaviour(OnCheckOut.QNAME, + GoogleDocsModel.ASPECT_GOOGLEEDITABLE, + new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT)); + + // Google resource behaviours + policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME, + GoogleDocsModel.ASPECT_GOOGLERESOURCE, + new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT)); + policyComponent.bindClassBehaviour(OnCheckIn.QNAME, + GoogleDocsModel.ASPECT_GOOGLERESOURCE, + new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT)); + policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME, + GoogleDocsModel.ASPECT_GOOGLERESOURCE, + new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)); + + // Copy behaviours + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), + GoogleDocsModel.ASPECT_GOOGLEEDITABLE, + new JavaBehaviour(this, "getGoogleEditableCopyCallback")); + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), + GoogleDocsModel.ASPECT_GOOGLERESOURCE, + new JavaBehaviour(this, "getGoogleResourceCopyCallback")); } /** @@ -166,7 +152,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli */ public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) { - if (nodeService.exists(nodeRef) == true) + if (googleDocsService.isEnabled() == true && nodeService.exists(nodeRef) == true) { // Can only make cm:content descendant google editable QName type = nodeService.getType(nodeRef); @@ -183,7 +169,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli */ public void onCheckOut(NodeRef workingCopy) { - if (nodeService.exists(workingCopy) == true && isUpload() == false) + if (googleDocsService.isEnabled() == true && nodeService.exists(workingCopy) == true && isUpload() == false) { // Upload the content of the working copy to google docs googleDocsService.createGoogleDoc(workingCopy, GoogleDocsPermissionContext.SHARE_WRITE); @@ -205,7 +191,8 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli Map versionProperties, String contentUrl, boolean keepCheckedOut) { - if (nodeService.exists(workingCopyNodeRef) == true && + if (googleDocsService.isEnabled() == true && + nodeService.exists(workingCopyNodeRef) == true && nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true && isUpload() == false) { @@ -220,6 +207,18 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true); writer.putContent(is); } + } + + /** + * @see org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckIn#onCheckIn(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public void onCheckIn(NodeRef nodeRef) + { + if (googleDocsService.isEnabled() == true && nodeService.exists(nodeRef) == true) + { + nodeService.removeAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE); + } } /** @@ -227,7 +226,9 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli */ public void beforeDeleteNode(NodeRef nodeRef) { - if (nodeService.exists(nodeRef) == true && isUpload() == false) + if (googleDocsService.isEnabled() == true && + nodeService.exists(nodeRef) == true && + isUpload() == false) { // Delete the associated google resource googleDocsService.deleteGoogleResource(nodeRef); @@ -271,10 +272,4 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli return Collections.emptyMap(); } } - - @Override - public void onCheckIn(NodeRef nodeRef) - { - nodeService.removeAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE); - } }