- Added web script to return the status of the GDoc service (see ALF-8684)
  - Refactor of service code to fix some of the issues when configuration details are changed via JMX or Share



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28681 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2011-06-29 05:58:56 +00:00
parent 6600f32e30
commit 4a8f493553
4 changed files with 80 additions and 56 deletions

View File

@@ -34,7 +34,8 @@
<property name="permissionService" ref="PermissionService"/> <property name="permissionService" ref="PermissionService"/>
<property name="ownableService" ref="OwnableService"/> <property name="ownableService" ref="OwnableService"/>
<property name="authorityService" ref="AuthorityService"/> <property name="authorityService" ref="AuthorityService"/>
<property name="dictionaryService" ref="DictionaryService"/> <property name="dictionaryService" ref="DictionaryService"/>
<property name="enabled" value="${googledocs.googleeditable.enabled}"/>
<property name="url" value="${googledocs.url}"/> <property name="url" value="${googledocs.url}"/>
<property name="downloadUrl" value="${googledocs.downloadurl}"/> <property name="downloadUrl" value="${googledocs.downloadurl}"/>
<property name="username" value="${googledocs.username}"/> <property name="username" value="${googledocs.username}"/>
@@ -54,6 +55,5 @@
<property name="nodeService" ref="NodeService"/> <property name="nodeService" ref="NodeService"/>
<property name="contentService" ref="ContentService"/> <property name="contentService" ref="ContentService"/>
<property name="dictionaryService" ref="DictionaryService"/> <property name="dictionaryService" ref="DictionaryService"/>
<property name="enabled" value="${googledocs.googleeditable.enabled}"/>
</bean> </bean>
</beans> </beans>

View File

@@ -27,6 +27,12 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/ */
public interface GoogleDocsService 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 * 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 * not be called manually since other service calls will initialise the service on demand, but it can

View File

@@ -106,12 +106,15 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
private AuthorityService authorityService; private AuthorityService authorityService;
private DictionaryService dictionaryService; private DictionaryService dictionaryService;
/** Indicates whether the GDoc integration is enabled or not */
private boolean enabled = false;
/** GoogleDoc base feed url */ /** GoogleDoc base feed url */
private String url = "http://docs.google.com/feeds/default/private/full"; private String url = "http://docs.google.com/feeds/default/private/full";
private String downloadUrl = "https://docs.google.com/feeds/download"; private String downloadUrl = "https://docs.google.com/feeds/download";
/** Authentication credentials */ /** Authentication credentials */
private boolean initialised = false; private boolean initialised = false;
private String username; private String username;
private String password; private String password;
@@ -246,6 +249,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
public void setUsername(String username) public void setUsername(String username)
{ {
this.username = username; this.username = username;
this.initialised = false;
} }
/** /**
@@ -254,6 +258,7 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
public void setPassword(String password) public void setPassword(String password)
{ {
this.password = password; this.password = password;
this.initialised = false;
} }
/** /**
@@ -263,6 +268,24 @@ public class GoogleDocsServiceImpl extends TransactionListenerAdapter
{ {
this.permissionMap = permissionMap; 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 * Initialise google docs services

View File

@@ -57,9 +57,6 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
CheckOutCheckInServicePolicies.OnCheckIn, CheckOutCheckInServicePolicies.OnCheckIn,
NodeServicePolicies.BeforeDeleteNodePolicy NodeServicePolicies.BeforeDeleteNodePolicy
{ {
/** Indicates whether behaviour is enabled or not */
boolean enabled = false;
/** Policy component */ /** Policy component */
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
@@ -75,14 +72,6 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
/** Content service */ /** Content service */
private ContentService contentService; private ContentService contentService;
/**
* @param enabled true if behaviour enabled, false otherwise
*/
public void setEnabled(boolean enabled)
{
this.enabled = enabled;
}
/** /**
* @param policyComponent policy component * @param policyComponent policy component
*/ */
@@ -127,38 +116,35 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
* Initialise method * Initialise method
*/ */
public void init() public void init()
{ {
if (enabled == true) // GoogleEditable resource behaviours
{ policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME,
// GoogleEditable resource behaviours GoogleDocsModel.ASPECT_GOOGLEEDITABLE ,
policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME, new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT));
GoogleDocsModel.ASPECT_GOOGLEEDITABLE , policyComponent.bindClassBehaviour(OnCheckOut.QNAME,
new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)); GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
policyComponent.bindClassBehaviour(OnCheckOut.QNAME, new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT));
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT)); // Google resource behaviours
policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME,
// Google resource behaviours GoogleDocsModel.ASPECT_GOOGLERESOURCE,
policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME, new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT));
GoogleDocsModel.ASPECT_GOOGLERESOURCE, policyComponent.bindClassBehaviour(OnCheckIn.QNAME,
new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT)); GoogleDocsModel.ASPECT_GOOGLERESOURCE,
policyComponent.bindClassBehaviour(OnCheckIn.QNAME, new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT));
GoogleDocsModel.ASPECT_GOOGLERESOURCE, policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT)); GoogleDocsModel.ASPECT_GOOGLERESOURCE,
policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME, new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT));
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)); // Copy behaviours
this.policyComponent.bindClassBehaviour(
// Copy behaviours QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
this.policyComponent.bindClassBehaviour( GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), new JavaBehaviour(this, "getGoogleEditableCopyCallback"));
GoogleDocsModel.ASPECT_GOOGLEEDITABLE, this.policyComponent.bindClassBehaviour(
new JavaBehaviour(this, "getGoogleEditableCopyCallback")); QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
this.policyComponent.bindClassBehaviour( GoogleDocsModel.ASPECT_GOOGLERESOURCE,
QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), new JavaBehaviour(this, "getGoogleResourceCopyCallback"));
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "getGoogleResourceCopyCallback"));
}
} }
/** /**
@@ -166,7 +152,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
*/ */
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) 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 // Can only make cm:content descendant google editable
QName type = nodeService.getType(nodeRef); QName type = nodeService.getType(nodeRef);
@@ -183,7 +169,7 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
*/ */
public void onCheckOut(NodeRef workingCopy) 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 // Upload the content of the working copy to google docs
googleDocsService.createGoogleDoc(workingCopy, GoogleDocsPermissionContext.SHARE_WRITE); googleDocsService.createGoogleDoc(workingCopy, GoogleDocsPermissionContext.SHARE_WRITE);
@@ -205,7 +191,8 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
Map<String, Serializable> versionProperties, String contentUrl, Map<String, Serializable> versionProperties, String contentUrl,
boolean keepCheckedOut) boolean keepCheckedOut)
{ {
if (nodeService.exists(workingCopyNodeRef) == true && if (googleDocsService.isEnabled() == true &&
nodeService.exists(workingCopyNodeRef) == true &&
nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true && nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true &&
isUpload() == false) isUpload() == false)
{ {
@@ -220,6 +207,18 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true); ContentWriter writer = contentService.getWriter(workingCopyNodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(is); 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) 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 // Delete the associated google resource
googleDocsService.deleteGoogleResource(nodeRef); googleDocsService.deleteGoogleResource(nodeRef);
@@ -271,10 +272,4 @@ public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPoli
return Collections.emptyMap(); return Collections.emptyMap();
} }
} }
@Override
public void onCheckIn(NodeRef nodeRef)
{
nodeService.removeAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE);
}
} }