diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index 0ac2642858..deca0b7235 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -575,15 +575,6 @@ true - - - diff --git a/config/alfresco/slingshot-context.xml b/config/alfresco/slingshot-context.xml index 274be16aba..c0280730b8 100644 --- a/config/alfresco/slingshot-context.xml +++ b/config/alfresco/slingshot-context.xml @@ -41,8 +41,6 @@ - - slingshotDocLib @@ -52,9 +50,6 @@ - - - diff --git a/config/alfresco/subsystems/googledocs/default/googledocs-context.xml b/config/alfresco/subsystems/googledocs/default/googledocs-context.xml deleted file mode 100755 index 05ffc3a7f8..0000000000 --- a/config/alfresco/subsystems/googledocs/default/googledocs-context.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - alfresco/subsystems/googledocs/default/googledocs-model.xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/alfresco/subsystems/googledocs/default/googledocs-model.xml b/config/alfresco/subsystems/googledocs/default/googledocs-model.xml deleted file mode 100755 index d8b650348e..0000000000 --- a/config/alfresco/subsystems/googledocs/default/googledocs-model.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - Google Docs Model - unknown - 1.0 - - - - - - - - - - - - - - - - Google Editable - - - Property who's only purpose is to allow the marker aspect to be automatically added. - d:boolean - true - true - - - - - - Google Document - - - GoogleDocs URL - d:text - false - - - GoogleDocs id - d:text - false - - - GoogleDocs Type - d:text - false - - - - - - - - - \ No newline at end of file diff --git a/config/alfresco/subsystems/googledocs/default/googledocs.properties b/config/alfresco/subsystems/googledocs/default/googledocs.properties deleted file mode 100755 index fcafc00d4d..0000000000 --- a/config/alfresco/subsystems/googledocs/default/googledocs.properties +++ /dev/null @@ -1,18 +0,0 @@ - -# Enables GoogleDocsV1 functionality -googledocs.googleeditable.enabled=false - -# Google docs application name -googledocs.application.name=Alfresco ECM system - -# Google docs URL -googledocs.url=https://docs.google.com/feeds/default/private/full -googledocs.downloadurl=https://docs.google.com/feeds/download - -# System google docs authentication credentials -googledocs.username= -googledocs.password= - -# Google docs spreadsheet service name -googledocs.spreadsheet.service.name=wise -googledocs.spreadsheet.downloadurl=https://spreadsheet.google.com/feeds/download \ No newline at end of file diff --git a/config/alfresco/subsystems/googledocs/default/test.docx b/config/alfresco/subsystems/googledocs/default/test.docx deleted file mode 100755 index e04a931e44..0000000000 Binary files a/config/alfresco/subsystems/googledocs/default/test.docx and /dev/null differ diff --git a/config/alfresco/subsystems/googledocs/default/test.xlsx b/config/alfresco/subsystems/googledocs/default/test.xlsx deleted file mode 100644 index 64d4a40495..0000000000 Binary files a/config/alfresco/subsystems/googledocs/default/test.xlsx and /dev/null differ diff --git a/config/alfresco/subsystems/googledocs/default/testBook.xls b/config/alfresco/subsystems/googledocs/default/testBook.xls deleted file mode 100644 index 15d493339d..0000000000 Binary files a/config/alfresco/subsystems/googledocs/default/testBook.xls and /dev/null differ diff --git a/config/alfresco/templates/following-email-templates.xml b/config/alfresco/templates/following-email-templates.xml index 7fe18b5870..2890f12552 100644 --- a/config/alfresco/templates/following-email-templates.xml +++ b/config/alfresco/templates/following-email-templates.xml @@ -1,7 +1,7 @@ - + ${spaces.templates.email.following.name} ${spaces.templates.email.following.name} diff --git a/config/alfresco/templates/invite-email-templates.xml b/config/alfresco/templates/invite-email-templates.xml index 89c8719290..ccc6afaa37 100644 --- a/config/alfresco/templates/invite-email-templates.xml +++ b/config/alfresco/templates/invite-email-templates.xml @@ -3,7 +3,7 @@ /app:company_home/app:dictionary/app:email_templates/cm:invite - + @@ -19,7 +19,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -99,7 +99,7 @@ - + diff --git a/config/alfresco/templates/new-user-templates.xml b/config/alfresco/templates/new-user-templates.xml index 2bd4c2217b..238e0b05da 100644 --- a/config/alfresco/templates/new-user-templates.xml +++ b/config/alfresco/templates/new-user-templates.xml @@ -3,7 +3,7 @@ /app:company_home/app:dictionary/app:email_templates/cm:invite - + @@ -19,7 +19,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -51,7 +51,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -99,7 +99,7 @@ - + diff --git a/config/alfresco/templates/notify_email_templates.xml b/config/alfresco/templates/notify_email_templates.xml index bae5de53d2..83f0799ca5 100644 --- a/config/alfresco/templates/notify_email_templates.xml +++ b/config/alfresco/templates/notify_email_templates.xml @@ -1,6 +1,6 @@ - + @@ -15,7 +15,7 @@ - + @@ -30,7 +30,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -90,7 +90,7 @@ - + diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsModel.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsModel.java deleted file mode 100755 index bd13306260..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsModel.java +++ /dev/null @@ -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 . -*/ -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"); -} diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsPermissionContext.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsPermissionContext.java deleted file mode 100644 index d5e13def06..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsPermissionContext.java +++ /dev/null @@ -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 . -*/ -package org.alfresco.repo.googledocs; - -/** - * Google docs permission context - */ -public enum GoogleDocsPermissionContext -{ - PRIVATE, - SHARE_READ, - SHARE_WRITE, - SHARE_READWRITE -} diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java deleted file mode 100755 index 12b473aac0..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsService.java +++ /dev/null @@ -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 . -*/ -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); - -} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java deleted file mode 100755 index c5d27e5c87..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceImpl.java +++ /dev/null @@ -1,1347 +0,0 @@ -/* -* Copyright (C) 2005-2014 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 . -*/ -package org.alfresco.repo.googledocs; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.model.ContentModel; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.AlfrescoTransactionSupport; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.TransactionListener; -import org.alfresco.repo.transaction.TransactionListenerAdapter; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.ContentData; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.MimetypeService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.AccessPermission; -import org.alfresco.service.cmr.security.AuthorityService; -import org.alfresco.service.cmr.security.AuthorityType; -import org.alfresco.service.cmr.security.OwnableService; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.ParameterCheck; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.google.gdata.client.GoogleAuthTokenFactory.UserToken; -import com.google.gdata.client.docs.DocsService; -import com.google.gdata.client.media.MediaService; -import com.google.gdata.data.IEntry; -import com.google.gdata.data.MediaContent; -import com.google.gdata.data.PlainTextConstruct; -import com.google.gdata.data.acl.AclEntry; -import com.google.gdata.data.acl.AclFeed; -import com.google.gdata.data.acl.AclRole; -import com.google.gdata.data.acl.AclScope; -import com.google.gdata.data.docs.DocumentEntry; -import com.google.gdata.data.docs.DocumentListEntry; -import com.google.gdata.data.docs.FolderEntry; -import com.google.gdata.data.docs.PdfEntry; -import com.google.gdata.data.docs.PresentationEntry; -import com.google.gdata.data.docs.SpreadsheetEntry; -import com.google.gdata.data.docs.DocumentListEntry.MediaType; -import com.google.gdata.data.media.MediaSource; -import com.google.gdata.data.media.MediaStreamSource; -import com.google.gdata.util.AuthenticationException; -import com.google.gdata.util.ContentType; -import com.google.gdata.util.ServiceException; - -/** - * Google docs integration service implementation - */ -public class GoogleDocsServiceImpl extends TransactionListenerAdapter - implements GoogleDocsService, GoogleDocsModel -{ - /** Log */ - private static Log logger = LogFactory.getLog(GoogleDocsServiceImpl.class); - - /** Google document types */ - public static final String TYPE_DOCUMENT = "document"; - public static final String TYPE_SPREADSHEET = "spreadsheet"; - public static final String TYPE_PRESENTATION = "presentation"; - 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 */ - private NodeService nodeService; - private ContentService contentService; - private PersonService personService; - private MimetypeService mimetypeService; - private PermissionService permissionService; - private OwnableService ownableService; - 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 = "https://docs.google.com/feeds/default/private/full"; - private String downloadUrl = "https://docs.google.com/feeds/download"; - private String spreadsheetDownloadUrl = "https://spreadsheet.google.com/feeds/download"; - - /** Authentication credentials */ - private String applicationName; - private String spreadSheetServiceName; - private String username; - private String password; - - /** Cached service tokens */ - private Map serviceTokens = new HashMap(2); - - /** Permission map */ - private Map permissionMap; - - // TODO: need a way of indicating if a customer is a premium user or not - - /** - * List of supported GoogleDoc supported mimetypes. - * Taken from list found at http://code.google.com/apis/documents/faq.html#WhatKindOfFilesCanIUpload - * NOTE: this restriction only applies to non-premium users. - */ - // TODO make this list configurable - private List supportedMimetypes = Arrays.asList( - "text/csv", - "text/tab-separated-values", - "text/html", - "application/msword", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "application/x-vnd.oasis.opendocument.spreadsheet", - "application/vnd.oasis.opendocument.text", - "application/rtf", - "application/vnd.sun.xml.writer", - "text/plain", - "application/vnd.ms-excel", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "application/pdf", - "application/vnd.ms-powerpoint", - "image/x-wmf" - ); - - /** - * Get a new instance of the spread sheet service - * - * @return spreadsheet service - */ - public MediaService getSpreadSheetService() - { - if (spreadSheetServiceName == null) - { - throw new GoogleDocsServiceInitException("No Google Docs spreadsheet service has been specified."); - } - - return getMediaService(spreadSheetServiceName); - } - - /** - * Get a new instance of a document service - * - * @return document service - */ - public DocsService getDocumentService() - { - return (DocsService)getMediaService(DocsService.DOCS_SERVICE); - } - - /** - * - * @param serviceName - * @return - */ - public MediaService getMediaService(String serviceName) - { - if (applicationName == null) - { - throw new GoogleDocsServiceInitException("Google Docs service " + serviceName + " could not be initialised, because no Google Doc application name has been specified."); - } - - MediaService service = null; - if (serviceName.equals(DocsService.DOCS_SERVICE) == true) - { - service = new DocsService(applicationName); - } - else - { - service = new MediaService(serviceName, applicationName); - - // MNT-11647: Changes in Google Docs API lead to setting 'Domain: .docs.google.com' cookie. This setting is causing the following exception: - // 'java.lang.IllegalArgumentException: Trying to set foreign cookie'. Operations with spreadsheets cannot be completed - if (serviceName.equals(spreadSheetServiceName) == true) - { - if (logger.isDebugEnabled()) - { - logger.debug("Disabling handling cookies for '" + serviceName + "' Google Docs service"); - } - - service.setHandlesCookies(false); - } - } - service.setChunkedMediaUpload(-1); - - String token = serviceTokens.get(serviceName); - if (token == null) - { - try - { - if (username == null ||username.length() == 0 || password == null) - { - throw new GoogleDocsServiceInitException("No Google Docs credentials found. Please set the Google Docs authentication configuration."); - } - - if (logger.isDebugEnabled() == true) - { - logger.debug("Setting user credentials for GDoc service. (serviceName=" + serviceName + ", userName=" + username + ", password=" + password + ")"); - } - - service.setUserCredentials(username, password); - serviceTokens.put(serviceName, ((UserToken)service.getAuthTokenFactory().getAuthToken()).getValue()); - } - catch (AuthenticationException e) - { - throw new GoogleDocsServiceInitException("Unable to connect to Google Docs. Please check the Google Docs authentication configuration.", e); - } - } - else - { - service.setUserToken(token); - } - - return service; - } - - /** - * @param nodeService node service - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - - /** - * @param contentService content service - */ - public void setContentService(ContentService contentService) - { - this.contentService = contentService; - } - - /** - * @param personService person service - */ - public void setPersonService(PersonService personService) - { - this.personService = personService; - } - - /** - * @param mimetypeService mime type service - */ - public void setMimetypeService(MimetypeService mimetypeService) - { - this.mimetypeService = mimetypeService; - } - - /** - * @param permissionService permission service - */ - public void setPermissionService(PermissionService permissionService) - { - this.permissionService = permissionService; - } - - /** - * @param ownableService ownable service - */ - public void setOwnableService(OwnableService ownableService) - { - this.ownableService = ownableService; - } - - /** - * @param authorityService authority service - */ - public void setAuthorityService(AuthorityService authorityService) - { - this.authorityService = authorityService; - } - - /** - * @param dictionaryService dictionary service - */ - public void setDictionaryService(DictionaryService dictionaryService) - { - this.dictionaryService = dictionaryService; - } - - /** - * @param url root googleDoc URL - */ - public void setUrl(String url) - { - this.url = url; - } - - /** - * @param downloadUrl root download URL - */ - public void setDownloadUrl(String downloadUrl) - { - this.downloadUrl = downloadUrl; - } - - /** - * @param spreadsheetDownloadUrl root spreadsheet download URL - */ - public void setSpreadsheetDownloadUrl(String spreadsheetDownloadUrl) - { - this.spreadsheetDownloadUrl = spreadsheetDownloadUrl; - } - - /** - * @param applicationName GDoc application name - */ - public void setApplicationName(String applicationName) - { - this.applicationName = applicationName; - } - - /** - * @param spreadSheetServiceName GDoc spread sheet service name - */ - public void setSpreadSheetServiceName(String spreadSheetServiceName) - { - this.spreadSheetServiceName = spreadSheetServiceName; - } - - /** - * @param username google service user name - */ - public void setUsername(String username) - { - this.username = username; - updatedAuthenticationCredentials(); - } - - /** - * @param password google service password - */ - public void setPassword(String password) - { - this.password = password; - updatedAuthenticationCredentials(); - } - - /** - * @param permissionMap permission map - */ - public void setPermissionMap(Map 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; - updatedAuthenticationCredentials(); - } - - /** - * @see org.alfresco.repo.googledocs.GoogleDocsService#isEnabled() - */ - public boolean isEnabled() - { - return enabled; - } - - /** - * @see org.alfresco.repo.googledocs.GoogleDocsService#isSupportedMimetype(java.lang.String) - */ - @Override - public boolean isSupportedMimetype(String mimetype) - { - return supportedMimetypes.contains(mimetype); - } - - /** - * @throws GoogleDocsUnsupportedMimetypeException - * @see org.alfresco.google.docs.GoogleDocsService#upload(org.alfresco.service.cmr.repository.NodeRef) - */ - public void createGoogleDoc(NodeRef nodeRef, GoogleDocsPermissionContext permissionContext) - { - // Check for mandatory parameters - ParameterCheck.mandatory("nodeRef", nodeRef); - - // Get property values - String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); - - // TODO should be checking to make sure this doesn't already have an associated google doc - - // Get content reader - String mimetype = null; - InputStream is = null; - ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); - if (contentReader == null) - { - // Determine the mimetype from the file extension only - // (We've no content so we can't include that in our check) - mimetype = mimetypeService.guessMimetype(name); - } - else - { - // Get the mime type and input stream from the content reader - mimetype = contentReader.getMimetype(); - if (contentReader.getSize() != 0) - { - is = contentReader.getContentInputStream(); - } - } - - // Hack to modify the mimetype of ods file so GDoc upload works - if ("application/vnd.oasis.opendocument.spreadsheet".equals(mimetype) == true) - { - mimetype = "application/x-vnd.oasis.opendocument.spreadsheet"; - } - - // Check that we support the mimetype - if (isSupportedMimetype(mimetype) == false) - { - throw new GoolgeDocsUnsupportedMimetypeException(nodeRef, ContentModel.PROP_CONTENT, mimetype); - } - - // Get the parent folder id - DocumentListEntry parentFolder = getParentFolder(nodeRef); - - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating google document (" + name + "," + mimetype + ")"); - } - - // Create the new google document - DocumentListEntry document = createGoogleDocument(name, mimetype, parentFolder, is); - - // Set permissions - setGoogleResourcePermissions(nodeRef, document, permissionContext); - - // Set the google document details - setResourceDetails(nodeRef, document); - } - - /** - * @see org.alfresco.google.docs.GoogleDocsService#deleteGoogleResource(org.alfresco.service.cmr.repository.NodeRef) - */ - public void deleteGoogleResource(NodeRef nodeRef) - { - // Check for mandatory parameters - ParameterCheck.mandatory("nodeRef", nodeRef); - - if (nodeService.hasAspect(nodeRef, ASPECT_GOOGLERESOURCE) == true) - { - // Get the entry - DocumentListEntry entry = getDocumentListEntry(nodeRef); - if (entry != null) - { - // Mark the resource for deletion upon completion of the transaction - markResource(KEY_MARKED_DELETE, entry.getResourceId()); - } - - // Remove the aspect from the node - nodeService.removeAspect(nodeRef, ASPECT_GOOGLERESOURCE); - } - } - - /** - * Set a google permission on a specified resource - * - * @param nodeRef node reference - * @param resource document resource - * @param permissionContext permission context - */ - private void setGoogleResourcePermissions(NodeRef nodeRef, DocumentListEntry resource, GoogleDocsPermissionContext permissionContext) - { - if (GoogleDocsPermissionContext.PRIVATE.equals(permissionContext) == false) - { - Set accessPermissions = permissionService.getAllSetPermissions(nodeRef); - for (AccessPermission accessPermission : accessPermissions) - { - String authorityName = accessPermission.getAuthority(); - AuthorityType authorityType = accessPermission.getAuthorityType(); - String permission = accessPermission.getPermission(); - if (permissionMap.containsKey(permission) == true) - { - String aclRole = permissionMap.get(permission); - if (GoogleDocsPermissionContext.SHARE_READ.equals(permissionContext) == true && - ("reader".equals(aclRole) == true || "writer".equals(aclRole) == true)) - { - // Set the permission to read - setGoogleResourcePermission(resource, authorityType, authorityName, "reader"); - } - else if (GoogleDocsPermissionContext.SHARE_WRITE.equals(permissionContext) == true && - "writer".equals(aclRole) == true) - { - // Set the permission to write - setGoogleResourcePermission(resource, authorityType, authorityName, "writer"); - } - else if (GoogleDocsPermissionContext.SHARE_READWRITE.equals(permissionContext) == true && - ("reader".equals(aclRole) == true || "writer".equals(aclRole) == true)) - { - // Set the permission to the current acl - setGoogleResourcePermission(resource, authorityType, authorityName, aclRole); - } - } - } - } - - // Always make sure the owner has write permissions on the document - String owner = ownableService.getOwner(nodeRef); - setGoogleResourcePermission(resource, AuthorityType.USER, owner, "writer"); - } - - /** - * Set a google permission on a specified resource - * - * @param resource document resource - * @param authorityType authority type - * @param authorityName authority name - * @param role role - */ - private void setGoogleResourcePermission(DocumentListEntry resource, AuthorityType authorityType, String authorityName, String role) - { - if (AuthorityType.USER.equals(authorityType) == true) - { - // Set the user permissions on the resource - String userEMail = getUserEMail(authorityName); - if (userEMail != null && userEMail.length() != 0) - { - setGoogleResourcePermission(resource, userEMail, role); - } - } - else if (AuthorityType.GROUP.equals(authorityType) == true) - { - Set childAuthorities = authorityService.getContainedAuthorities(AuthorityType.USER, authorityName, false); - for (String childAuthority : childAuthorities) - { - setGoogleResourcePermission(resource, AuthorityType.USER, childAuthority, role); - } - } - } - - /** - * Gets the users email used to identify their google account. - * - * @param userName user name - * @return String google account email, null if none - */ - private String getUserEMail(String userName) - { - String email = null; - NodeRef personNodeRef = personService.getPerson(userName); - if (personNodeRef != null) - { - // First see if the google user information has been set - email = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_GOOGLEUSERNAME); - - // If no google user information then default back to the user's email - if (email == null || email.length() == 0) - { - email = (String) nodeService.getProperty(personNodeRef, ContentModel.PROP_EMAIL); - } - } - return email; - } - - /** - * Gets the nodes parent folder google resource. - * - * @param nodeRef node reference - * @return DocumentList Entry folder resource - */ - private DocumentListEntry getParentFolder(final NodeRef nodeRef) - { - DocumentListEntry folder = null; - - NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); - if (parentNodeRef != null) - { - if (nodeService.hasAspect(parentNodeRef, ASPECT_GOOGLERESOURCE) == true) - { - String resourceType = (String)nodeService.getProperty(parentNodeRef, PROP_RESOURCE_TYPE); - String resourceId = (String)nodeService.getProperty(parentNodeRef, PROP_RESOURCE_ID); - folder = getDocumentListEntry(resourceType + ":" + resourceId); - - if (logger.isDebugEnabled() == true) - { - logger.debug("Found existing google folder + " + resourceId); - } - } - else - { - // Get the parent folder - DocumentListEntry parentFolder = getParentFolder(parentNodeRef); - - // Determine the name of the new google folder - String name = null; - QName parentNodeType = nodeService.getType(parentNodeRef); - if (dictionaryService.isSubClass(parentNodeType, ContentModel.TYPE_STOREROOT) == true) - { - name = parentNodeRef.getStoreRef().getIdentifier(); - } - else - { - name = (String)nodeService.getProperty(parentNodeRef, ContentModel.PROP_NAME); - } - - // Create the folder and set the meta data in Alfresco - folder = createGoogleFolder(name, parentFolder); - setResourceDetails(parentNodeRef, folder); - } - } - - return folder; - } - - /** - * Sets the resource details on the node reference - * - * @param nodeRef node reference - * @param documentListEntry document list entry - */ - private void setResourceDetails(final NodeRef nodeRef, final DocumentListEntry documentListEntry) - { - AuthenticationUtil.RunAsWork runAsWork = new AuthenticationUtil.RunAsWork() - { - public Object doWork() throws Exception - { - // Create a map of the property values - Map props = new HashMap(1); - props.put(GoogleDocsModel.PROP_RESOURCE_ID, documentListEntry.getDocId()); - props.put(GoogleDocsModel.PROP_RESOURCE_TYPE, documentListEntry.getType()); - props.put(GoogleDocsModel.PROP_URL, documentListEntry.getDocumentLink().getHref()); - - // Add the google resource aspect - nodeService.addAspect(nodeRef, GoogleDocsModel.ASPECT_GOOGLERESOURCE, props); - return null; - } - }; - - // Run as admin - AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName()); - } - - /** - * @see org.alfresco.google.docs.GoogleDocsService#getGoogleDocContent(org.alfresco.service.cmr.repository.NodeRef) - */ - public InputStream getGoogleDocContent(NodeRef nodeRef) - { - InputStream result = null; - - // Check for mandatory parameters - ParameterCheck.mandatory("nodeRef", nodeRef); - - try - { - if (nodeService.hasAspect(nodeRef, ASPECT_GOOGLERESOURCE) == true) - { - String downloadUrl = null; - DocumentListEntry document = getDocumentListEntry(nodeRef); - if (document != null) - { - String docType = document.getType(); - - ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); - String fileExtension = mimetypeService.getExtension(contentData.getMimetype()); - - if (docType.equals(TYPE_DOCUMENT) || docType.equals(TYPE_PRESENTATION)) - { - StringBuffer buffer = new StringBuffer(this.downloadUrl); - buffer.append("/"). - append(docType).append("s"). - append("/Export?id=").append(document.getDocId()). - append("&exportFormat=").append(fileExtension); - - downloadUrl = buffer.toString(); - } - else if (docType.equals(TYPE_SPREADSHEET)) - { - StringBuffer buffer = new StringBuffer(spreadsheetDownloadUrl); - buffer.append("/"). - append(docType).append("s"). - append("/Export?key=").append(document.getDocId()). - append("&exportFormat=").append(fileExtension); - - // If exporting to .csv or .tsv, add the gid parameter to specify which sheet to export - if (fileExtension.equals("csv") || fileExtension.equals("tsv")) - { - buffer.append("&gid=0"); // gid=0 will download only the first sheet - } - - downloadUrl = buffer.toString(); - - } - else if (docType.equals(TYPE_PDF)) - { - MediaContent mc = (MediaContent)document.getContent(); - downloadUrl = mc.getUri(); - } - else - { - throw new AlfrescoRuntimeException("Unsupported document type: " + docType); - } - - // Log the download URI - if (logger.isDebugEnabled() == true) - { - logger.debug("Download URL for " + docType + " is " + downloadUrl); - } - - MediaService service = null; - if (docType.equals(TYPE_SPREADSHEET) == true) - { - service = getSpreadSheetService(); - } - else - { - service = getDocumentService(); - } - - MediaContent mc = new MediaContent(); - mc.setUri(downloadUrl); - MediaSource ms = service.getMedia(mc); - - result = ms.getInputStream(); - } - else - { - throw new AlfrescoRuntimeException("Can not download google doc content since no corresponsing google resource could be found"); - } - } - else - { - // error since we are trying to download a non-google resource - throw new AlfrescoRuntimeException("Can not download google doc content since no corresponsing google resource could be found"); - } - } - catch (ServiceException e) - { - throw new AlfrescoRuntimeException("Unable to get google document stream.", e); - } - catch (IOException e) - { - throw new AlfrescoRuntimeException("Unable to get google document stream.", e); - } - - return result; - } - - /** - * Gets the document list entry that corresponds to the google resource - * related to the node reference provided. - * - * @param docNodeRef node reference - * @return DocumentListEntry document list entry - */ - private DocumentListEntry getDocumentListEntry(NodeRef docNodeRef) - { - DocumentListEntry result = null; - String docType = (String)nodeService.getProperty(docNodeRef, PROP_RESOURCE_TYPE); - String docId = (String)nodeService.getProperty(docNodeRef, PROP_RESOURCE_ID); - if (docType != null && docId != null) - { - result = getDocumentListEntry(docType + ":" + docId); - } - return result; - } - - /** - * Gets the document resource entry for a document resource id - * - * @param docResourceId document resource id - * @return DocumentListEntry document list entry - */ - private DocumentListEntry getDocumentListEntry(String docResourceId) - { - return getEntry(docResourceId, DocumentListEntry.class); - } - - /** - * Gets the entry for a given resource id. - * - * @param Entry class - * @param resourceId resource id - * @param entryClass entry class - * @return E entry instance - */ - private E getEntry(String resourceId, Class entryClass) - { - E result = null; - try - { - URL docEntryURL = new URL(url + "/" + resourceId); - result = getDocumentService().getEntry(docEntryURL, entryClass); - } - catch (ServiceException e) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to get document list entry for resource " + resourceId + " because " + e.getMessage()); - } - result = null; - } - catch (IOException e) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to get document list entry for resource " + resourceId + " because " + e.getMessage()); - } - result = null; - } - return result; - } - - /** - * Create a google document - * - * @param name document name - * @param mimetype mime type - * @param parentFolder parent folder resource - * @param is input stream for content - * @return DocumentListEntry resource for created document - */ - private DocumentListEntry createGoogleDocument(String name, String mimetype, DocumentListEntry parentFolder, InputStream is) - { - DocumentListEntry document = null; - - // Log details - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating google document with name " + name); - } - - try - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating media content object for mimetype " + mimetype); - } - - // Create the media content object - MediaContent mediaContent = new MediaContent(); - mediaContent.setMimeType(new ContentType(mimetype)); - - if (is != null) - { - if (logger.isDebugEnabled() == true) - { - logger.debug(" ... input stream has been set"); - } - mediaContent.setMediaSource(new MediaStreamSource(is, mimetype)); - } - - // Parent folder url - String parentFolderUrl = url; - if (parentFolder != null) - { - parentFolderUrl = ((MediaContent)parentFolder.getContent()).getUri(); - if (logger.isDebugEnabled() == true) - { - logger.debug(" ... parent folder URL is " + parentFolderUrl); - } - } - - // Create the document entry object - DocumentListEntry docEntry = null; - if (MediaType.XLS.getMimeType().equals(mimetype) == true || - MediaType.XLSX.getMimeType().equals(mimetype) == true || - MediaType.ODS.getMimeType().equals(mimetype) == true) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating SpreadsheetEntry for mimetype " + mimetype); - } - docEntry = new SpreadsheetEntry(); - } - else if (MediaType.PPS.getMimeType().equals(mimetype) == true || - MediaType.PPT.getMimeType().equals(mimetype) == true) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating PresentationEntry for mimetype " + mimetype); - } - docEntry = new PresentationEntry(); - } - else if (MediaType.PDF.getMimeType().equals(mimetype) == true) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating PdfEntry for mimetype " + mimetype); - } - docEntry = new PdfEntry(); - } - else - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating DocumentEntry for mimetype " + mimetype); - } - docEntry = new DocumentEntry(); - } - - // Set the content and the title of the document - docEntry.setContent(mediaContent); - docEntry.setTitle(new PlainTextConstruct(name)); - - // Upload the document into the parent folder - document = getDocumentService().insert( - new URL(parentFolderUrl), - docEntry); - - // Mark create entry - markResource(KEY_MARKED_CREATE, document.getResourceId()); - } - catch (IOException e) - { - // Log details of exception - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to create google document with name " + name + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to create google document", e); - } - catch (ServiceException e) - { - // Log details of exception - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to create google document with name " + name + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to create google document", e); - } - - return document; - } - - /** - * Updates the content of a google document - * - * @param document document resource - * @param mimeType mimetype - * @param is input stream - */ - @SuppressWarnings("unused") - private void updateGoogleDocContent(DocumentListEntry document, String mimeType, InputStream is) - { - // Log details - if (logger.isDebugEnabled() == true) - { - logger.debug("Updating content of document " + document.getResourceId()); - } - - try - { - // Update the existing content - DocsService service = getDocumentService(); - service.getRequestFactory().setHeader("If-Match", "*"); - document.setMediaSource(new MediaStreamSource(is, mimeType)); - document.updateMedia(false); - } - catch (ServiceException e) - { - // Log details of the error - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to update the content of document " + document.getResourceId() + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to update documents content in google docs", e); - } - catch (IOException e) - { - // Log details of the error - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to update the content of document " + document.getResourceId() + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to update documents content in google docs", e); - } - } - - /** - * Creates a google folder, returning the folder resource. - * - * @param folderName folder name - * @param parentFolder parent folder resource - * @return DocumentListEntry created folder resource - */ - private DocumentListEntry createGoogleFolder(String folderName, DocumentListEntry parentFolder) - { - DocumentListEntry folderEntry = null; - - try - { - // Log details - if (logger.isDebugEnabled() == true) - { - logger.debug("Creating folder " + folderName); - } - - // Parent folder url - String parentFolderUrl = url; - if (parentFolder != null) - { - parentFolderUrl = ((MediaContent)parentFolder.getContent()).getUri(); - } - - // Create the folder entry - FolderEntry folder = new FolderEntry(); - folder.setTitle(new PlainTextConstruct(folderName)); - - // Create the folder - folderEntry = getDocumentService().insert( - new URL(parentFolderUrl), - folder); - - // Mark create entry - markResource(KEY_MARKED_CREATE, folderEntry.getResourceId()); - } - catch (IOException e) - { - // Log details of the failure - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to create folder " + folderName + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to create Google Folder", e); - } - catch (ServiceException e) - { - // Log details of the failure - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to create folder " + folderName + ", because " + e.getMessage()); - } - - // Rethrow as runtime exception - throw new AlfrescoRuntimeException("Unable to create Google Folder", e); - } - - return folderEntry; - } - - /** - * Set permissions on a googleDoc resource - * - * @param resourceId - * @param email - * @param role - */ - private void setGoogleResourcePermission(DocumentListEntry resource, String email, String role) - { - // Check mandatory parameters have been set - ParameterCheck.mandatory("resource", resource); - ParameterCheck.mandatory("email", email); - ParameterCheck.mandatory("role", role); - - // Log details - if (logger.isDebugEnabled() == true) - { - logger.debug("Setting the role " + role + " on the google resource " + resource.getResourceId() + " for email " + email + "."); - } - - try - { - AclRole aclRole = new AclRole(role); - AclScope scope = new AclScope(AclScope.Type.USER, email); - - // Get the URL - URL aclFeedLinkURL = new URL(resource.getAclFeedLink().getHref()); - - // See if we have already set this permission or not - AclEntry aclEntry = null; - AclFeed aclFeed = getDocumentService().getFeed(aclFeedLinkURL, AclFeed.class); - if (aclFeed != null) - { - List aclEntries = aclFeed.getEntries(); - for (AclEntry tempAclEntry : aclEntries) - { - AclScope tempScope = tempAclEntry.getScope(); - if (tempScope.equals(scope) == true) - { - // Existing ACL entry found - aclEntry = tempAclEntry; - break; - } - } - } - - // Set the permission details - if (aclEntry == null) - { - aclEntry = new AclEntry(); - aclEntry.setRole(aclRole); - aclEntry.setScope(scope); - getDocumentService().insert(aclFeedLinkURL, aclEntry); - } - else - { - // Log details of failure - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to the role " + role + " on the google resource " + resource.getResourceId() + " for email " + email + "." + - " This user already has a role on this document."); - } - } - - // TODO for now we will not 'update' the permissions if they have already been set .... - // - //else - //{ - // AclRole currentAclRole = aclEntry.getRole(); - // if (currentAclRole.toString().equals(aclRole.toString()) == false) - // { - // aclEntry.setRole(aclRole); - // googleDocumentService.update(new URL(aclEntry.getEditLink().getHref()), aclEntry); - // } - //} - } - catch (ServiceException e) - { - // Ignore this exception since we don't want to roll back the entire transaction because - // a single users permissions can not be set. - // It seems the google API will return a server exception if the email does not correspond to - // a google account, so catching this exception in this indiscriminate way is the best thing to - // do for now. - - // Log details of failure - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to the role " + role + " on the google resource " + resource.getResourceId() + " for email " + email + "." + - " Check that this is a valid google account."); - } - } - catch (IOException e) - { - throw new AlfrescoRuntimeException("Unable to set premissions on google document", e); - } - } - - /** - * Marks a resource as created in this transaction - * - * @param resourceId resource id of created resource - */ - @SuppressWarnings("unchecked") - private void markResource(String key, String resourceId) - { - List resources = (List)AlfrescoTransactionSupport.getResource(key); - if (resources == null) - { - // bind pending rules to the current transaction - resources = new ArrayList(); - AlfrescoTransactionSupport.bindResource(key, resources); - // bind the rule transaction listener - AlfrescoTransactionSupport.bindListener(this); - } - - if (resources.contains(resourceId) == false) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Marking resource " + resourceId + " with key " + key); - } - - resources.add(resourceId); - } - } - - /** - * @see org.alfresco.repo.transaction.TransactionListenerAdapter#afterCommit() - */ - @SuppressWarnings("unchecked") - @Override - public void afterCommit() - { - List resources = (List)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); - if (entry != null) - { - getDocumentService().delete(new URL(entry.getEditLink().getHref() + "?delete=true"), entry.getEtag()); - } - else - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to delete resource " + resourceId + " during commit."); - } - } - } - 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") - @Override - public void afterRollback() - { - List resources = (List)AlfrescoTransactionSupport.getResource(KEY_MARKED_CREATE); - if (resources != null) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Transaction rolled back, manually deleting created Google Resources"); - } - - for (String resourceId : resources) - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Deleting created resource " + resourceId); - } - - // Delete resource - try - { - DocumentListEntry entry = getDocumentListEntry(resourceId); - if (entry != null) - { - getDocumentService().delete(new URL(entry.getEditLink().getHref() + "?delete=true"), entry.getEtag()); - } - else - { - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to delete resource " + resourceId + " during rollback."); - } - } - } - catch (Throwable e) - { - // Ignore, but log - if (logger.isDebugEnabled() == true) - { - logger.debug("Unable to delete resource " + resourceId + " during rollback.", e); - } - } - } - } - } - - private TransactionListener validateCredentials = new TransactionListener() - { - - @Override - public void afterCommit() - { - } - - @Override - public void afterRollback() - { - } - - @Override - public void beforeCommit(boolean readOnly) - { - if (enabled == true) - { - if (username == null || username.length() == 0 || password == null) - { - throw new GoogleDocsServiceInitException("No Google Docs credentials found. Please set the Google Docs authentication configuration."); - } - } - } - - @Override - public void beforeCompletion() - { - } - - @Override - public void flush() - { - } - }; - - private void updatedAuthenticationCredentials() - { - // Reset the token map - serviceTokens = new HashMap(2); - if (RetryingTransactionHelper.getActiveUserTransaction() != null) - { - AlfrescoTransactionSupport.bindListener(validateCredentials); - } - } -} diff --git a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceInitException.java b/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceInitException.java deleted file mode 100644 index 85b1e4c101..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleDocsServiceInitException.java +++ /dev/null @@ -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 . -*/ -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); - } -} diff --git a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java b/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java deleted file mode 100755 index 785ddcc536..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoogleEditableAspect.java +++ /dev/null @@ -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 . -*/ -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> 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>(); - // 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 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 getCopyProperties(QName classQName, CopyDetails copyDetails, Map 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 getCopyProperties(QName classQName, CopyDetails copyDetails, Map properties) - { - return Collections.emptyMap(); - } - } - - @Override - public void destroy() throws Exception - { - for(BehaviourDefinition definition : behaviours) - { - policyComponent.removeClassDefinition(definition); - } - } -} diff --git a/source/java/org/alfresco/repo/googledocs/GoolgeDocsUnsupportedMimetypeException.java b/source/java/org/alfresco/repo/googledocs/GoolgeDocsUnsupportedMimetypeException.java deleted file mode 100644 index 274810c870..0000000000 --- a/source/java/org/alfresco/repo/googledocs/GoolgeDocsUnsupportedMimetypeException.java +++ /dev/null @@ -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())); - } - } - -} diff --git a/source/java/org/alfresco/repo/jscript/app/GoogleDocsCustomResponse.java b/source/java/org/alfresco/repo/jscript/app/GoogleDocsCustomResponse.java deleted file mode 100644 index 8162aef528..0000000000 --- a/source/java/org/alfresco/repo/jscript/app/GoogleDocsCustomResponse.java +++ /dev/null @@ -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 . - */ - -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 jsonObj = new LinkedHashMap(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; - } -} diff --git a/source/test-java/org/alfresco/repo/googledocs/GoogleDocumentServiceSystemTest.java b/source/test-java/org/alfresco/repo/googledocs/GoogleDocumentServiceSystemTest.java deleted file mode 100644 index 59e0ba316d..0000000000 --- a/source/test-java/org/alfresco/repo/googledocs/GoogleDocumentServiceSystemTest.java +++ /dev/null @@ -1,371 +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 . -*/ -package org.alfresco.repo.googledocs; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; - -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.content.transform.AbstractContentTransformerTest; -import org.alfresco.repo.management.subsystems.ApplicationContextFactory; -import org.alfresco.repo.node.archive.NodeArchiveService; -import org.alfresco.repo.rendition.executer.AbstractRenderingEngine; -import org.alfresco.repo.rendition.executer.ReformatRenderingEngine; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.site.SiteServiceImpl; -import org.alfresco.service.cmr.coci.CheckOutCheckInService; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.rendition.RenditionDefinition; -import org.alfresco.service.cmr.rendition.RenditionService; -import org.alfresco.service.cmr.repository.ContentReader; -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.cmr.security.MutableAuthenticationService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.cmr.site.SiteInfo; -import org.alfresco.service.cmr.site.SiteService; -import org.alfresco.service.cmr.site.SiteVisibility; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.GUID; -import org.alfresco.util.PropertyMap; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; - -import com.google.gdata.util.ServiceException; - -public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleDocsModel -{ - private NodeService nodeService; - private GoogleDocsService googleDocsService; - private SiteService siteService; - private TransactionService transactionService; - private FileFolderService fileFolderService; - private ContentService contentService; - private CheckOutCheckInService checkOutCheckInService; - private MutableAuthenticationService authenticationService; - private PersonService personService; - private ApplicationContextFactory subsystem; - private RenditionService renditionService; - private NodeArchiveService nodeArchiveService; - - private static final String USER_ONE = "GoogleDocUserOne"; - private static final String USER_TWO = "GoogleDocUserTwo"; - private static final String USER_THREE = "GoogleDocUserThree"; - private static final String USER_FOUR = "GoogleDocUserFour"; - private static final String USER_FIVE = "GoogleDocUserFive"; - private static final String USER_SIX = "GoogleDocUserSix"; - private static final String USER_SEVEN = "GoogleDocUserSeven"; - - private NodeRef folder; - private NodeRef nodeRefDoc; - private NodeRef nodeRefSpread; - private NodeRef nodeRefPres; - private NodeRef nodeRefPdf; - private NodeRef nodeRef2; - private UserTransaction userTransaction; - private String siteId; - - @Override - protected void setUp() throws Exception - { - ApplicationContext appContext = ApplicationContextHelper.getApplicationContext(); - - nodeService = (NodeService)appContext.getBean("nodeService"); - siteService = (SiteService)appContext.getBean("siteService"); - transactionService = (TransactionService)appContext.getBean("transactionService"); - fileFolderService = (FileFolderService)appContext.getBean("fileFolderService"); - contentService = (ContentService)appContext.getBean("contentService"); - checkOutCheckInService = (CheckOutCheckInService)appContext.getBean("checkOutCheckInService"); - authenticationService = (MutableAuthenticationService)appContext.getBean("authenticationService"); - personService = (PersonService)appContext.getBean("personService"); - renditionService = (RenditionService)appContext.getBean("renditionService"); - nodeArchiveService = (NodeArchiveService)appContext.getBean("nodeArchiveService"); - - // Start the user transaction - userTransaction = transactionService.getUserTransaction(); - userTransaction.begin(); - - // Get the sub-system and make sure the googleeditable feature is turned on - subsystem = (ApplicationContextFactory)appContext.getBean("googledocs"); - if (subsystem.getProperty("googledocs.googleeditable.enabled").equals("false") == true) - { - subsystem.stop(); - subsystem.setProperty("googledocs.googleeditable.enabled", "true"); - subsystem.start(); - } - - // Get the google docs service - ConfigurableApplicationContext childContext = (ConfigurableApplicationContext)subsystem.getApplicationContext(); - googleDocsService = (GoogleDocsService)childContext.getBean("googleDocsService"); - - // Create the test users - createUser(USER_ONE, "rwetherall@alfresco.com", null); - createUser(USER_TWO, "admin@alfresco.com", "rwetherall@activiti.com"); - createUser(USER_THREE, "roy.wetherall@alfresco.com", null); - createUser(USER_FOUR, "roy.wetherall@activiti.com", null); - createUser(USER_FIVE, "admin@alfresco.com", "admin@alfresco.com"); - createUser(USER_SIX, "admin@alfresco.com", null); - createUser(USER_SEVEN, null, null); - - // Authenticate as user one - AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE); - - siteId = GUID.generate(); - - // Create a site to use as holder for our test google documents - siteService.createSite("sitePreset", siteId, "My Title", "My Description", SiteVisibility.PUBLIC); - NodeRef container = siteService.createContainer(siteId, "testComponent", null, null); - - // Add some memberships to the site - siteService.setMembership(siteId, USER_TWO, SiteServiceImpl.SITE_COLLABORATOR); - siteService.setMembership(siteId, USER_THREE, SiteServiceImpl.SITE_CONTRIBUTOR); - siteService.setMembership(siteId, USER_FOUR, SiteServiceImpl.SITE_CONSUMER); - siteService.setMembership(siteId, USER_FIVE, SiteServiceImpl.SITE_COLLABORATOR); - siteService.setMembership(siteId, USER_SIX, SiteServiceImpl.SITE_COLLABORATOR); - siteService.setMembership(siteId, USER_SEVEN, SiteServiceImpl.SITE_COLLABORATOR); - - // Create a folder in our site container - folder = fileFolderService.create(container, "myfolder" + GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef(); - - // Create test documents - nodeRefDoc = createTestDocument("mydoc.docx", "alfresco/subsystems/googledocs/default/test.docx", MimetypeMap.MIMETYPE_WORD); - nodeRefSpread = createTestDocument("mydoc.xls", "alfresco/subsystems/googledocs/default/testBook.xls", MimetypeMap.MIMETYPE_EXCEL); - //nodeRefSpread = createTestDocument("mydoc2.xlsx", "alfresco/subsystems/googledocs/default/test.xlsx", MimetypeMap.MIMETYPE_EXCEL); - - // Create an empty content node (simulate creation of a new google doc in UI) - nodeRef2 = fileFolderService.create(folder, "mygoogledoc.xls", ContentModel.TYPE_CONTENT).getNodeRef(); - nodeService.addAspect(nodeRef2, ASPECT_GOOGLEEDITABLE, null); - ContentWriter contentWriter = contentService.getWriter(nodeRef2, ContentModel.PROP_CONTENT, true); - contentWriter.setEncoding("UTF-8"); - contentWriter.setMimetype(MimetypeMap.MIMETYPE_EXCEL); - contentWriter.putContent(""); - } - - private NodeRef createTestDocument(String name, String contentPath, String mimetype) - { - NodeRef nodeRef = fileFolderService.create(folder, name, ContentModel.TYPE_CONTENT).getNodeRef(); - ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); - writer.setEncoding("UTF-8"); - writer.setMimetype(mimetype); - InputStream is = getClass().getClassLoader().getResourceAsStream(contentPath); - writer.putContent(is); - return nodeRef; - } - - private void createUser(String userName, String email, String googleEmail) - { - if (authenticationService.authenticationExists(userName) == false) - { - authenticationService.createAuthentication(userName, "PWD".toCharArray()); - - PropertyMap ppOne = new PropertyMap(4); - ppOne.put(ContentModel.PROP_USERNAME, userName); - ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); - ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); - ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); - - if (email != null) - { - ppOne.put(ContentModel.PROP_EMAIL, email); - } - - if (googleEmail != null) - { - ppOne.put(ContentModel.PROP_GOOGLEUSERNAME, googleEmail); - } - - personService.createPerson(ppOne); - } - } - - @Override - protected void tearDown() throws Exception - { - SiteInfo siteInfo = siteService.getSite(siteId); - siteService.deleteSite(siteId); - - if (userTransaction != null) - { - userTransaction.commit(); - } - nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef())); - } - - private boolean isGoogleServiceAvailable() - { - return googleDocsService.isEnabled(); - } - - public void testGoogleDocUploadDownload() throws Exception - { - if (isGoogleServiceAvailable() == true) - { - googleDocsService.createGoogleDoc(nodeRefDoc, GoogleDocsPermissionContext.SHARE_WRITE); - - assertTrue(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE)); - assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_URL)); - assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID)); - assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE)); - - System.out.println("For node ref " + nodeRefDoc.toString()); - System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefDoc, PROP_URL)); - System.out.println("Google doc type: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE)); - System.out.println("Google doc id: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID)); - String downloadFile = downloadFile(googleDocsService.getGoogleDocContent(nodeRefDoc), ".doc"); - System.out.println("Download file: " + downloadFile); - - googleDocsService.createGoogleDoc(nodeRefSpread, GoogleDocsPermissionContext.SHARE_WRITE); - - assertTrue(nodeService.hasAspect(nodeRefSpread, ASPECT_GOOGLERESOURCE)); - assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_URL)); - assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID)); - assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE)); - - System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefSpread, PROP_URL)); - System.out.println("Google doc type: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE)); - System.out.println("Google doc id: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID)); - downloadFile = downloadFile(googleDocsService.getGoogleDocContent(nodeRefSpread), ".xls"); - System.out.println("Download file: " + downloadFile); - - googleDocsService.createGoogleDoc(nodeRef2, GoogleDocsPermissionContext.SHARE_WRITE); - } - - } - - public void testCheckOutCheckIn() throws Exception - { - if (isGoogleServiceAvailable() == true) - { - // Check out the empty google document - NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef2); - - assertTrue(nodeService.hasAspect(workingCopy, ASPECT_GOOGLERESOURCE)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_URL)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_ID)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE)); - - System.out.println("Google doc URL: " + nodeService.getProperty(workingCopy, PROP_URL)); - System.out.println("Google doc type: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE)); - System.out.println("Google doc id: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_ID)); - - checkOutCheckInService.checkin(workingCopy, null); - - assertFalse(nodeService.hasAspect(nodeRef2, ASPECT_GOOGLERESOURCE)); - ContentReader contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT); - assertNotNull(contentReader); - - // Lets try and delete the checked in node reference - nodeService.deleteNode(nodeRef2); - } - } - - /** - * http://issues.alfresco.com/jira/browse/ALF-5060 - */ - public void testALF5060() throws Exception - { - if (isGoogleServiceAvailable() == true) - { - // Create a rendition definition (doc -> pdf) - RenditionDefinition def = renditionService.createRenditionDefinition( - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDef"), - ReformatRenderingEngine.NAME); - def.setExecuteAsynchronously(false); - def.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_FLASH); - - // Create a word document - File fileDoc = AbstractContentTransformerTest.loadQuickTestFile("doc"); - NodeRef nodeRef = fileFolderService.create(folder, "testing.doc", ContentModel.TYPE_CONTENT).getNodeRef(); - nodeService.addAspect(nodeRef, ASPECT_GOOGLEEDITABLE, null); - ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); - contentWriter.setEncoding("UTF-8"); - contentWriter.setMimetype(MimetypeMap.MIMETYPE_WORD); - contentWriter.putContent(fileDoc); - - renditionService.render(nodeRef, def); - - NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef); - assertTrue(nodeService.hasAspect(workingCopy, ASPECT_GOOGLERESOURCE)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_URL)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_ID)); - assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE)); - System.out.println("Google doc URL: " + nodeService.getProperty(workingCopy, PROP_URL)); - System.out.println("Google doc type: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE)); - System.out.println("Google doc id: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_ID)); - checkOutCheckInService.checkin(workingCopy, null); - - renditionService.render(nodeRef, def); - - } - } - - /** - * Utility method to download input stream to a file for inspection - * - * @param inStream - * @param ext - * @return - * @throws IOException - * @throws MalformedURLException - * @throws ServiceException - */ - private String downloadFile(InputStream inStream, String ext) throws IOException, MalformedURLException, ServiceException - { - File file = File.createTempFile("googleDocTest", ext); - String filePath = file.getAbsolutePath(); - FileOutputStream outStream = null; - try - { - outStream = new FileOutputStream(filePath); - - int c; - while ((c = inStream.read()) != -1) - { - outStream.write(c); - } - } - finally - { - if (inStream != null) - { - inStream.close(); - } - if (outStream != null) - { - outStream.flush(); - outStream.close(); - } - } - - return filePath; - } -}