Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

76635: Merged EOL2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud)
      76545: ACE-2016: EOL Google Docs v1 in 5.0


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77670 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2014-07-22 16:13:06 +00:00
parent fe4f92b653
commit 017af1a65c
21 changed files with 22 additions and 2526 deletions

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.googledocs;
import org.alfresco.service.namespace.QName;
/**
* Google docs model constants
*/
public interface GoogleDocsModel
{
static final String GOOGLE_DOCS_PREFIX = "gd";
static final String GOOGLE_DOCS_MODEL_1_0_URI = "http://www.alfresco.org/model/googledocs/1.0";
static final QName ASPECT_GOOGLEEDITABLE = QName.createQName(GOOGLE_DOCS_MODEL_1_0_URI, "googleEditable");
static final QName ASPECT_GOOGLERESOURCE = QName.createQName(GOOGLE_DOCS_MODEL_1_0_URI, "googleResource");
static final QName PROP_URL = QName.createQName(GOOGLE_DOCS_MODEL_1_0_URI, "url");
static final QName PROP_RESOURCE_ID = QName.createQName(GOOGLE_DOCS_MODEL_1_0_URI, "resourceId");
static final QName PROP_RESOURCE_TYPE = QName.createQName(GOOGLE_DOCS_MODEL_1_0_URI, "resourceType");
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.googledocs;
/**
* Google docs permission context
*/
public enum GoogleDocsPermissionContext
{
PRIVATE,
SHARE_READ,
SHARE_WRITE,
SHARE_READWRITE
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.googledocs;
import java.io.InputStream;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Google docs integration service interface
*/
public interface GoogleDocsService
{
/**
* Indicates whether the GoogleDocs service is enabled or not.
* @return boolean true if enabled, false otherwise
*/
boolean isEnabled();
/**
* Indicates whether the mimetype is supported for creation in google docs.
*
* NOTE: This method presumes that the account being used is not for a "premium" customer
*
* @param mimetype mimetype
* @return boolean true if mimetype is supported, false otherwise
*/
boolean isSupportedMimetype(String mimetype);
/**
* Create a google doc from a given node. The content of the node will be used
* as a basis of the associated google doc. If the node has no content a new, empty google
* doc of the correct type will be created.
*
* The permission context provides information about how google sharing permissions should be
* set on the created google doc.
*
* @param nodeRef node reference
* @param permissionContext permission context
* @throws GoogleDocsUnsupportedMimetypeException
*/
void createGoogleDoc(NodeRef nodeRef, GoogleDocsPermissionContext permissionContext);
/**
* Deletes the google resource associated with the node reference. This could be a folder or
* document.
*
* @param nodeRef node reference
*/
void deleteGoogleResource(NodeRef nodeRef);
/**
* Gets the content as an input stream of google doc associated with the given node. The
* node must have the google resource aspect and the associated resource should not be a
* folder.
*
* @param nodeRef node reference
* @return InputStream the content of the associated google doc
*/
InputStream getGoogleDocContent(NodeRef nodeRef);
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.googledocs;
import org.alfresco.error.AlfrescoRuntimeException;
/**
* Google docs service initialisation exception class.
*/
public class GoogleDocsServiceInitException extends AlfrescoRuntimeException
{
/** Serial version UUID */
private static final long serialVersionUID = -2104024155137888545L;
/**
* @param message error message
*/
public GoogleDocsServiceInitException(String message)
{
super(message);
}
/**
* @param message error message
* @param cause causing exception
*/
public GoogleDocsServiceInitException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@@ -1,294 +0,0 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.googledocs;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.coci.CheckOutCheckInServicePolicies;
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.copy.CopyBehaviourCallback;
import org.alfresco.repo.copy.CopyDetails;
import org.alfresco.repo.copy.DefaultCopyBehaviourCallback;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy;
import org.alfresco.repo.policy.BehaviourDefinition;
import org.alfresco.repo.policy.ClassBehaviourBinding;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.springframework.beans.factory.DisposableBean;
/**
* Behaviour associated with google editable documents
*
*/
public class GoogleEditableAspect implements NodeServicePolicies.OnAddAspectPolicy,
CheckOutCheckInServicePolicies.OnCheckOut,
CheckOutCheckInServicePolicies.BeforeCheckIn,
CheckOutCheckInServicePolicies.OnCheckIn,
NodeServicePolicies.BeforeDeleteNodePolicy,
DisposableBean
{
/** Policy component */
private PolicyComponent policyComponent;
/** Google docs service */
private GoogleDocsService googleDocsService;
/** Node service */
private NodeService nodeService;
/** Dictionary service */
private DictionaryService dictionaryService;
/** Content service */
private ContentService contentService;
/** binded behaviours definitions*/
private Set<BehaviourDefinition<ClassBehaviourBinding>> behaviours;
/**
* @param policyComponent policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* @param googleDocsService google docs service
*/
public void setGoogleDocsService(GoogleDocsService googleDocsService)
{
this.googleDocsService = googleDocsService;
}
/**
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param contentService content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Initialise method
*/
public void init()
{
behaviours = new HashSet<BehaviourDefinition<ClassBehaviourBinding>>();
// GoogleEditable resource behaviours
behaviours.add(policyComponent.bindClassBehaviour(OnAddAspectPolicy.QNAME,
GoogleDocsModel.ASPECT_GOOGLEEDITABLE ,
new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT)));
behaviours.add(policyComponent.bindClassBehaviour(OnCheckOut.QNAME,
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
new JavaBehaviour(this, "onCheckOut", NotificationFrequency.FIRST_EVENT)));
// Google resource behaviours
behaviours.add(policyComponent.bindClassBehaviour(BeforeCheckIn.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "beforeCheckIn", NotificationFrequency.FIRST_EVENT)));
behaviours.add(policyComponent.bindClassBehaviour(OnCheckIn.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "onCheckIn", NotificationFrequency.FIRST_EVENT)));
behaviours.add(policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)));
// Copy behaviours
behaviours.add(policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
GoogleDocsModel.ASPECT_GOOGLEEDITABLE,
new JavaBehaviour(this, "getGoogleEditableCopyCallback")));
behaviours.add(policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
GoogleDocsModel.ASPECT_GOOGLERESOURCE,
new JavaBehaviour(this, "getGoogleResourceCopyCallback")));
}
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
{
if (googleDocsService.isEnabled() == true && nodeService.exists(nodeRef) == true)
{
// Can only make cm:content descendant google editable
QName type = nodeService.getType(nodeRef);
if (dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) == false)
{
// Prevent aspect from being applied
throw new AlfrescoRuntimeException("The node (" + nodeRef.toString() + ") can not be made google editable, because it is not a sub type of cm:content.");
}
}
}
/**
* @see org.alfresco.repo.coci.CheckOutCheckInServicePolicies.OnCheckOut#onCheckOut(org.alfresco.service.cmr.repository.NodeRef)
*/
public void onCheckOut(NodeRef workingCopy)
{
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);
}
}
private boolean isUpload()
{
boolean result = false;
String value = (String)AlfrescoTransactionSupport.getResource("checkoutforupload");
if (value != null)
{
result = Boolean.parseBoolean(value);
}
return result;
}
public void beforeCheckIn(NodeRef workingCopyNodeRef,
Map<String, Serializable> versionProperties, String contentUrl,
boolean keepCheckedOut)
{
if (googleDocsService.isEnabled() == true &&
nodeService.exists(workingCopyNodeRef) == true &&
nodeService.hasAspect(workingCopyNodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE) == true &&
isUpload() == false)
{
// Get input stream for the google doc
InputStream is = googleDocsService.getGoogleDocContent(workingCopyNodeRef);
if (is == null)
{
throw new AlfrescoRuntimeException("Unable to complete check in, because the working copy content could not be retrieved from google docs.");
}
// Write the google content into the node
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);
}
}
/**
* @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef)
*/
public void beforeDeleteNode(NodeRef nodeRef)
{
if (googleDocsService.isEnabled() == true &&
nodeService.exists(nodeRef) == true &&
isUpload() == false)
{
// Delete the associated google resource
googleDocsService.deleteGoogleResource(nodeRef);
}
}
public CopyBehaviourCallback getGoogleEditableCopyCallback(QName classRef, CopyDetails copyDetails)
{
return GoogleEditableCopyBehaviourCallback.INSTANCE;
}
private static class GoogleEditableCopyBehaviourCallback extends DefaultCopyBehaviourCallback
{
private static final CopyBehaviourCallback INSTANCE = new GoogleEditableCopyBehaviourCallback();
/**
* @return Returns an empty map
*/
@Override
public Map<QName, Serializable> getCopyProperties(QName classQName, CopyDetails copyDetails, Map<QName, Serializable> properties)
{
return Collections.emptyMap();
}
}
public CopyBehaviourCallback getGoogleResourceCopyCallback(QName classRef, CopyDetails copyDetails)
{
return GoogleResourceCopyBehaviourCallback.INSTANCE;
}
private static class GoogleResourceCopyBehaviourCallback extends DefaultCopyBehaviourCallback
{
private static final CopyBehaviourCallback INSTANCE = new GoogleEditableCopyBehaviourCallback();
/**
* @return Returns an empty map
*/
@Override
public Map<QName, Serializable> getCopyProperties(QName classQName, CopyDetails copyDetails, Map<QName, Serializable> properties)
{
return Collections.emptyMap();
}
}
@Override
public void destroy() throws Exception
{
for(BehaviourDefinition<ClassBehaviourBinding> definition : behaviours)
{
policyComponent.removeClassDefinition(definition);
}
}
}

View File

@@ -1,75 +0,0 @@
/**
*
*/
package org.alfresco.repo.googledocs;
import java.text.MessageFormat;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Roy Wetherall
*/
public class GoolgeDocsUnsupportedMimetypeException extends AlfrescoRuntimeException
{
private static final long serialVersionUID = 7505645425492536907L;
private static Log logger = LogFactory.getLog(GoolgeDocsUnsupportedMimetypeException.class);
/**
* @param msgId
*/
public GoolgeDocsUnsupportedMimetypeException(String msgId)
{
super(msgId);
}
/**
* @param msgId
* @param msgParams
*/
public GoolgeDocsUnsupportedMimetypeException(String msgId, Object[] msgParams)
{
super(msgId, msgParams);
}
/**
* @param msgId
* @param cause
*/
public GoolgeDocsUnsupportedMimetypeException(String msgId, Throwable cause)
{
super(msgId, cause);
}
/**
* @param msgId
* @param msgParams
* @param cause
*/
public GoolgeDocsUnsupportedMimetypeException(String msgId, Object[] msgParams, Throwable cause)
{
super(msgId, msgParams, cause);
}
/**
* @param nodeRef node reference
* @param contentProp content property
* @param mimetype mimetype
*/
public GoolgeDocsUnsupportedMimetypeException(NodeRef nodeRef, QName contentProp, String mimetype)
{
// TODO I18N
this(MessageFormat.format("The mimetype {0} is not supported by Google Docs", mimetype));
if (logger.isDebugEnabled() == true)
{
logger.debug(MessageFormat.format("The mimetype {0} is not supported by Google Docs. (nodeRef = {1}, contentProp = {2})", mimetype, nodeRef.toString(), contentProp.toString()));
}
}
}

View File

@@ -1,76 +0,0 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.jscript.app;
import org.alfresco.repo.googledocs.GoogleDocsService;
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Return current status of Google Docs subsystem
*
* @author: mikeh
*/
public class GoogleDocsCustomResponse implements CustomResponse, ApplicationContextAware
{
private static Log logger = LogFactory.getLog(GoogleDocsCustomResponse.class);
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
this.applicationContext = applicationContext;
}
/**
* Populates the DocLib webscript response with custom metadata
*
* @return JSONObject or null
*/
public Serializable populate()
{
try
{
ApplicationContextFactory subsystem = (ApplicationContextFactory)applicationContext.getBean("googledocs");
ConfigurableApplicationContext childContext = (ConfigurableApplicationContext)subsystem.getApplicationContext();
GoogleDocsService googleDocsService = (GoogleDocsService)childContext.getBean("googleDocsService");
Map<String, Serializable> jsonObj = new LinkedHashMap<String, Serializable>(4);
jsonObj.put("enabled", googleDocsService.isEnabled());
return (Serializable)jsonObj;
}
catch (Exception e)
{
logger.warn("Could not add custom Google Docs status response to DocLib webscript");
}
return null;
}
}