From 2051b0709a7dadcf005f5309469a8120dee17353 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 10 Jun 2009 17:04:09 +0000 Subject: [PATCH] MOB-690 - WCM PreviewURIService - checkpoint git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14642 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/model/wcmAppModel.xml | 7 +- config/alfresco/wcm-services-context.xml | 70 ++++++++ .../java/org/alfresco/model/WCMAppModel.java | 1 + .../java/org/alfresco/repo/jscript/AVM.java | 32 +--- .../service/ServiceDescriptorRegistry.java | 9 + .../java/org/alfresco/repo/template/AVM.java | 32 +--- .../org/alfresco/service/ServiceRegistry.java | 25 ++- .../wcm/AbstractWCMServiceImplTest.java | 9 +- .../java/org/alfresco/wcm/WCMTestSuite.java | 4 +- .../AbstractPreviewURIServiceProvider.java | 64 +++++++ .../wcm/preview/NullPreviewURIService.java | 46 ++++++ .../alfresco/wcm/preview/PreviewContext.java | 63 +++++++ .../wcm/preview/PreviewURIService.java | 76 +++++++++ .../wcm/preview/PreviewURIServiceImpl.java | 136 +++++++++++++++ .../preview/PreviewURIServiceImplTest.java | 104 ++++++++++++ .../preview/PreviewURIServiceProvider.java | 57 +++++++ .../preview/PreviewURIServiceRegistry.java | 53 ++++++ .../PreviewURIServiceRegistryImpl.java | 79 +++++++++ .../preview/URITemplatePreviewURIService.java | 91 ++++++++++ ...VirtualisationServerPreviewURIService.java | 156 ++++++++++++++++++ .../wcm/sandbox/SandboxConstants.java | 3 +- .../wcm/sandbox/SandboxServiceImpl.java | 37 +---- .../java/org/alfresco/wcm/util/WCMUtil.java | 110 ++++++------ .../wcm/webproject/WebProjectInfo.java | 21 ++- .../wcm/webproject/WebProjectInfoImpl.java | 32 +++- .../wcm/webproject/WebProjectService.java | 67 +++++++- .../wcm/webproject/WebProjectServiceImpl.java | 134 ++++++++++++--- .../webproject/WebProjectServiceImplTest.java | 2 +- .../wcm/wcm-test-preview-context.xml | 22 +++ 29 files changed, 1344 insertions(+), 198 deletions(-) create mode 100644 source/java/org/alfresco/wcm/preview/AbstractPreviewURIServiceProvider.java create mode 100644 source/java/org/alfresco/wcm/preview/NullPreviewURIService.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewContext.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIService.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIServiceImpl.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIServiceImplTest.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIServiceProvider.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistry.java create mode 100644 source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistryImpl.java create mode 100644 source/java/org/alfresco/wcm/preview/URITemplatePreviewURIService.java create mode 100644 source/java/org/alfresco/wcm/preview/VirtualisationServerPreviewURIService.java create mode 100644 source/test-resources/wcm/wcm-test-preview-context.xml diff --git a/config/alfresco/model/wcmAppModel.xml b/config/alfresco/model/wcmAppModel.xml index 6f26c7e8aa..1b7a1e1f16 100644 --- a/config/alfresco/model/wcmAppModel.xml +++ b/config/alfresco/model/wcmAppModel.xml @@ -39,7 +39,7 @@ - AVM Website Folder + WCM Web Project Folder wcm:avmfolder @@ -76,6 +76,11 @@ Used as a template website d:boolean + + + Preview Provider + d:text + diff --git a/config/alfresco/wcm-services-context.xml b/config/alfresco/wcm-services-context.xml index 0905175503..a349a38fb8 100644 --- a/config/alfresco/wcm-services-context.xml +++ b/config/alfresco/wcm-services-context.xml @@ -53,6 +53,7 @@ + @@ -233,4 +234,73 @@ + + + + + + org.alfresco.wcm.preview.PreviewURIService + + + + + + + + + + + + + + + + + + + + + + ${server.transaction.mode.readOnly} + ${server.transaction.mode.default} + + + + + + + + + + + + + + + + Virtualisation Server Preview + + + + + + + + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/model/WCMAppModel.java b/source/java/org/alfresco/model/WCMAppModel.java index e884674334..e94374f08e 100644 --- a/source/java/org/alfresco/model/WCMAppModel.java +++ b/source/java/org/alfresco/model/WCMAppModel.java @@ -40,6 +40,7 @@ public interface WCMAppModel static final QName PROP_SELECTEDDEPLOYTO = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "selecteddeployto"); static final QName PROP_SELECTEDDEPLOYVERSION = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "selecteddeployversion"); static final QName PROP_ISSOURCE = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "issource"); + static final QName PROP_PREVIEW_PROVIDER = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "previewprovidername"); static final QName ASSOC_WEBUSER = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "webuser"); static final QName ASSOC_WEBFORM = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "webform"); static final QName ASSOC_WEBWORKFLOWDEFAULTS = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "webworkflowdefaults"); diff --git a/source/java/org/alfresco/repo/jscript/AVM.java b/source/java/org/alfresco/repo/jscript/AVM.java index 411893b40c..baaa8dc986 100644 --- a/source/java/org/alfresco/repo/jscript/AVM.java +++ b/source/java/org/alfresco/repo/jscript/AVM.java @@ -198,7 +198,7 @@ public final class AVM extends BaseScopableProcessorExtension */ public String websiteStagingUrl(String storeId) { - return WCMUtil.buildStoreUrl(this.services.getAVMService(), storeId, getVServerDomain(), getVServerPort()); + return this.services.getPreviewURIService().getPreviewURI(storeId, null); } /** @@ -220,9 +220,9 @@ public final class AVM extends BaseScopableProcessorExtension * * @return the preview URL to the specified store asset */ - public String assetUrl(String store, String assetPath) + public String assetUrl(String storeId, String assetPath) { - return WCMUtil.buildAssetUrl(assetPath, getVServerDomain(), getVServerPort(), WCMUtil.lookupStoreDNS(this.services.getAVMService(), store)); + return this.services.getPreviewURIService().getPreviewURI(storeId, assetPath); } /** @@ -241,32 +241,6 @@ public final class AVM extends BaseScopableProcessorExtension return assetUrl(s[0], s[1]); } - /** - * @return VServer Port - */ - private String getVServerPort() - { - Integer port = this.services.getVirtServerRegistry().getVirtServerHttpPort(); - if (port == null) - { - port = JNDIConstants.DEFAULT_VSERVER_PORT; - } - return port.toString(); - } - - /** - * @return VServer Domain - */ - private String getVServerDomain() - { - String domain = this.services.getVirtServerRegistry().getVirtServerFQDN(); - if (domain == null) - { - domain = JNDIConstants.DEFAULT_VSERVER_IP; - } - return domain; - } - /** * @return the path to the webapps folder in a standard web store. */ diff --git a/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java b/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java index 60802a815f..b6d62dd6c9 100644 --- a/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java +++ b/source/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java @@ -75,6 +75,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.wcm.asset.AssetService; +import org.alfresco.wcm.preview.PreviewURIService; import org.alfresco.wcm.sandbox.SandboxService; import org.alfresco.wcm.webproject.WebProjectService; import org.springframework.beans.BeansException; @@ -493,6 +494,14 @@ public class ServiceDescriptorRegistry return (AssetService)getService(ASSET_SERVICE); } + /* (non-Javadoc) + * @see org.alfresco.service.ServiceRegistry#getPreviewURIService() + */ + public PreviewURIService getPreviewURIService() + { + return (PreviewURIService)getService(PREVIEW_URI_SERVICE); + } + /* (non-Javadoc) * @see org.alfresco.service.ServiceRegistry#getFormService() */ diff --git a/source/java/org/alfresco/repo/template/AVM.java b/source/java/org/alfresco/repo/template/AVM.java index 8979bf6d19..a3194d1d72 100644 --- a/source/java/org/alfresco/repo/template/AVM.java +++ b/source/java/org/alfresco/repo/template/AVM.java @@ -188,7 +188,7 @@ public class AVM extends BaseTemplateProcessorExtension */ public String websiteStagingUrl(String storeId) { - return WCMUtil.buildStoreUrl(this.services.getAVMService(), storeId, getVServerDomain(), getVServerPort()); + return this.services.getPreviewURIService().getPreviewURI(storeId, null); } /** @@ -210,9 +210,9 @@ public class AVM extends BaseTemplateProcessorExtension * * @return the preview URL to the specified store asset */ - public String assetUrl(String store, String assetPath) + public String assetUrl(String storeId, String assetPath) { - return WCMUtil.buildAssetUrl(assetPath, getVServerDomain(), getVServerPort(), WCMUtil.lookupStoreDNS(this.services.getAVMService(), store)); + return this.services.getPreviewURIService().getPreviewURI(storeId, assetPath); } /** @@ -231,32 +231,6 @@ public class AVM extends BaseTemplateProcessorExtension return assetUrl(s[0], s[1]); } - /** - * @return VServer Port - */ - private String getVServerPort() - { - Integer port = this.services.getVirtServerRegistry().getVirtServerHttpPort(); - if (port == null) - { - port = JNDIConstants.DEFAULT_VSERVER_PORT; - } - return port.toString(); - } - - /** - * @return VServer Domain - */ - private String getVServerDomain() - { - String domain = this.services.getVirtServerRegistry().getVirtServerFQDN(); - if (domain == null) - { - domain = JNDIConstants.DEFAULT_VSERVER_IP; - } - return domain; - } - /** * @return the path to the webapps folder in a standard web store. */ diff --git a/source/java/org/alfresco/service/ServiceRegistry.java b/source/java/org/alfresco/service/ServiceRegistry.java index 57b3e8db51..73a87f4d25 100644 --- a/source/java/org/alfresco/service/ServiceRegistry.java +++ b/source/java/org/alfresco/service/ServiceRegistry.java @@ -74,6 +74,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.wcm.asset.AssetService; +import org.alfresco.wcm.preview.PreviewURIService; import org.alfresco.wcm.sandbox.SandboxService; import org.alfresco.wcm.webproject.WebProjectService; @@ -125,21 +126,26 @@ public interface ServiceRegistry static final QName OWNABLE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "OwnableService"); static final QName PERSON_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "PersonService"); static final QName SITE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "SiteService"); + static final QName ATTRIBUTE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AttributeService"); + static final QName THUMBNAIL_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "ThumbnailService"); + static final QName TAGGING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "TaggingService"); + static final QName FORM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "FormService"); + static final QName INVITATION_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "InvitationService"); + + // WCM / AVM static final QName AVM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMService"); static final QName AVM_LOCKING_AWARE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMLockingAwareService"); static final QName AVM_SYNC_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMSyncService"); static final QName CROSS_REPO_COPY_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "CrossRepositoryCopyService"); - static final QName ATTRIBUTE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AttributeService"); static final QName AVM_LOCKING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMLockingService"); static final QName VIRT_SERVER_REGISTRY = QName.createQName(NamespaceService.ALFRESCO_URI, "VirtServerRegistry"); - static final QName THUMBNAIL_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "ThumbnailService"); - static final QName TAGGING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "TaggingService"); static final QName DEPLOYMENT_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "DeploymentService"); static final QName WEBPROJECT_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "WebProjectService"); static final QName SANDBOX_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "SandboxService"); static final QName ASSET_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AssetService"); - static final QName FORM_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "FormService"); - static final QName INVITATION_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "InvitationService"); + static final QName PREVIEW_URI_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "WCMPreviewURIService"); + + // CMIS static final QName CMIS_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "CMISService"); static final QName CMIS_DICTIONARY_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "CMISDictionaryService"); static final QName CMIS_QUERY_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "CMISQueryService"); @@ -432,7 +438,7 @@ public interface ServiceRegistry TaggingService getTaggingService(); /** - * Get the Deployment Service + * Get the WCM Deployment Service * @return the deployment service (or null, if one is not provided) */ @NotAuditable @@ -459,6 +465,13 @@ public interface ServiceRegistry @NotAuditable AssetService getAssetService(); + /** + * Get the WCM Preview URI Service + * @return + */ + @NotAuditable + PreviewURIService getPreviewURIService(); + /** * Get the form service (or null if one is not provided) * @return diff --git a/source/java/org/alfresco/wcm/AbstractWCMServiceImplTest.java b/source/java/org/alfresco/wcm/AbstractWCMServiceImplTest.java index 38056a3908..cdd89fbb05 100644 --- a/source/java/org/alfresco/wcm/AbstractWCMServiceImplTest.java +++ b/source/java/org/alfresco/wcm/AbstractWCMServiceImplTest.java @@ -49,14 +49,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; */ public class AbstractWCMServiceImplTest extends TestCase { + private static final String PREVIEW_CONFIG_LOCATION = "classpath:wcm/wcm-test-preview-context.xml"; + // override jbpm.job.executor idleInterval to 5s (was 1.5m) for WCM unit tests private static final String SUBMIT_CONFIG_LOCATION = "classpath:wcm/wcm-jbpm-context.xml"; protected static final long SUBMIT_DELAY = 15000L; // (in millis) 15s - to allow async submit direct workflow to complete (as per 5s idleInterval above) - - protected static ApplicationContext ctx =new ClassPathXmlApplicationContext( - new String[] {ApplicationContextHelper.CONFIG_LOCATIONS[0], SUBMIT_CONFIG_LOCATION} - ); + // note: all tests share same context (when run via WCMTestSuite) + protected static ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {ApplicationContextHelper.CONFIG_LOCATIONS[0], SUBMIT_CONFIG_LOCATION, PREVIEW_CONFIG_LOCATION});; // // test data @@ -94,7 +94,6 @@ public class AbstractWCMServiceImplTest extends TestCase protected PersonService personService; private TransactionService transactionService; - @Override protected void setUp() throws Exception diff --git a/source/java/org/alfresco/wcm/WCMTestSuite.java b/source/java/org/alfresco/wcm/WCMTestSuite.java index cf9235914f..7997dbea09 100644 --- a/source/java/org/alfresco/wcm/WCMTestSuite.java +++ b/source/java/org/alfresco/wcm/WCMTestSuite.java @@ -28,6 +28,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.alfresco.wcm.asset.AssetServiceImplTest; +import org.alfresco.wcm.preview.PreviewURIServiceImplTest; import org.alfresco.wcm.sandbox.SandboxServiceImplTest; import org.alfresco.wcm.webproject.WebProjectServiceImplTest; import org.alfresco.wcm.webproject.script.ScriptWebProjectsTest; @@ -52,7 +53,8 @@ public class WCMTestSuite extends TestSuite suite.addTestSuite(AssetServiceImplTest.class); suite.addTestSuite(SandboxServiceImplTest.class); suite.addTestSuite(ScriptWebProjectsTest.class); - + suite.addTestSuite(PreviewURIServiceImplTest.class); + return suite; } } diff --git a/source/java/org/alfresco/wcm/preview/AbstractPreviewURIServiceProvider.java b/source/java/org/alfresco/wcm/preview/AbstractPreviewURIServiceProvider.java new file mode 100644 index 0000000000..be5ee4e909 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/AbstractPreviewURIServiceProvider.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Abstract Preview URI Service Provider + * + * @author janv + * + * @since 3.2 + */ +public abstract class AbstractPreviewURIServiceProvider implements PreviewURIServiceProvider +{ + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIServiceProvider#getPreviewURI(java.lang.String, java.lang.String, org.alfresco.wcm.preview.PreviewContext) + */ + abstract public String getPreviewURI(String sbStoreId, String relativePath, PreviewContext previewContext); + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIServiceProvider#getPreviewURIs(java.lang.String, java.util.List, org.alfresco.wcm.preview.PreviewContext) + */ + public List getPreviewURIs(String sbStoreId, List relativePaths, PreviewContext previewContext) + { + List previewURIs = null; + + if (relativePaths != null) + { + previewURIs = new ArrayList(relativePaths.size()); + for (String relativePath : relativePaths) + { + previewURIs.add(getPreviewURI(sbStoreId, relativePath, previewContext)); + } + } + + return previewURIs; + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/wcm/preview/NullPreviewURIService.java b/source/java/org/alfresco/wcm/preview/NullPreviewURIService.java new file mode 100644 index 0000000000..7fd8cb137f --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/NullPreviewURIService.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + + +/** + * A PreviewURIService that always returns null (no preview URI). + * + * @author Peter Monks, janv + * + * @since 3.2 + */ +public class NullPreviewURIService extends AbstractPreviewURIServiceProvider +{ + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIServiceProvider#getPreviewURI(java.lang.String, java.lang.String, org.alfresco.wcm.preview.PreviewContext) + */ + @Override + public String getPreviewURI(final String storeId, final String webapp, final PreviewContext previewContext) + { + return(null); + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/wcm/preview/PreviewContext.java b/source/java/org/alfresco/wcm/preview/PreviewContext.java new file mode 100644 index 0000000000..1848e2a098 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewContext.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + + +/** + * Additional context Preview URI Service Providers + * + * @author janv + * + * @since 3.2 + */ +public class PreviewContext +{ + private String wpStoreId; + private String webApp; // can be null + private String authenticatedUser; + + /* package */ PreviewContext(String wpStoreId, String webApp, String authenticatedUser) + { + this.wpStoreId = wpStoreId; + this.webApp = webApp; + this.authenticatedUser = authenticatedUser; + } + + public String getWpStoreId() + { + return wpStoreId; + } + + public String getWebApp() + { + return webApp; + } + + public String getAuthenticatedUser() + { + return authenticatedUser; + } +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIService.java b/source/java/org/alfresco/wcm/preview/PreviewURIService.java new file mode 100644 index 0000000000..a370b59169 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIService.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + +import java.util.List; +import java.util.Set; + +/** + * Client API for retrieving/generating preview URIs + * + * @author janv + * + * @since 3.2 + */ +public interface PreviewURIService +{ + /** + * @param sbStoreId The sandbox store id to generate the preview URI for. + * @param pathToAsset The path to the asset to generate the preview URI for (can be null or empty, to return preview URL to store). + * + * @return The Preview URI for the given sandbox and/or asset (may be null). + */ + public String getPreviewURI(String sbStoreId, String pathToAsset); + + /** + * @param sbStoreId The sandbox store id to generate the preview URI for. + * @param pathsToAssets List of paths to the assets to generate the preview URI for. + * + * @return The Preview URI for the given assets (may be null). + */ + public List getPreviewURIs(String sbStoreId, List pathsToAssets); + + /** + * Return list of registered Preview URI service providers + * + * @return + */ + public Set getProviderNames(); + + /** + * Return default Preview URI service provider + * + * @return + */ + public String getDefaultProviderName(); + + /** + * Return Preview URI service provider configured for web project + * + * @return + */ + public String getProviderName(String wpStoreId); +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIServiceImpl.java b/source/java/org/alfresco/wcm/preview/PreviewURIServiceImpl.java new file mode 100644 index 0000000000..656c504f45 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIServiceImpl.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.wcm.preview; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.util.ParameterCheck; +import org.alfresco.wcm.util.WCMUtil; +import org.alfresco.wcm.webproject.WebProjectService; + + +/** + * Preview URI Service fundamental API. + *

+ * This service API is designed to support the Preview URI API + * + * @author janv + * + * @since 3.2 + */ +public class PreviewURIServiceImpl implements PreviewURIService +{ + private PreviewURIServiceRegistry previewURIProviderRegistry; + private WebProjectService wpService; + + public void setPreviewURIServiceRegistry(PreviewURIServiceRegistry previewURIProviderRegistry) + { + this.previewURIProviderRegistry = previewURIProviderRegistry; + } + + public void setWebProjectService(WebProjectService wpService) + { + this.wpService = wpService; + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIService#getPreviewURI(java.lang.String, java.lang.String) + */ + public String getPreviewURI(String sbStoreId, String pathToAsset) + { + ParameterCheck.mandatoryString("sbStoreId", sbStoreId); + + String wpStoreId = WCMUtil.getWebProjectStoreId(sbStoreId); + String authenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser(); + + String webApp = null; + if (pathToAsset != null) + { + webApp = WCMUtil.getWebapp(WCMUtil.buildPath(sbStoreId, pathToAsset)); + } + + PreviewContext prevCtx = new PreviewContext(wpStoreId, webApp, authenticatedUser); + + return getProvider(wpStoreId).getPreviewURI(sbStoreId, pathToAsset, prevCtx); + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIService#getPreviewURIs(java.lang.String, java.util.List) + */ + public List getPreviewURIs(String sbStoreId, List pathsToAssets) + { + ParameterCheck.mandatoryString("sbStoreId", sbStoreId); + ParameterCheck.mandatory("pathsToAssets", pathsToAssets); + + String wpStoreId = WCMUtil.getWebProjectStoreId(sbStoreId); + String authenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser(); + + String webApp = WCMUtil.getCommonWebApp(sbStoreId, pathsToAssets); + + PreviewContext prevCtx = new PreviewContext(wpStoreId, webApp, authenticatedUser); + + return getProvider(wpStoreId).getPreviewURIs(sbStoreId, pathsToAssets, prevCtx); + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIService#getProviderNames() + */ + public Set getProviderNames() + { + Map previewProviders = previewURIProviderRegistry.getPreviewURIServiceProviders(); + return previewProviders.keySet(); + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIService#getDefaultProviderName() + */ + public String getDefaultProviderName() + { + // delegate + return previewURIProviderRegistry.getDefaultProviderName(); + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIService#getProviderName(java.lang.String) + */ + public String getProviderName(String wpStoreId) + { + // delegate + return wpService.getPreviewProvider(wpStoreId); + } + + private PreviewURIServiceProvider getProvider(String wpStoreId) + { + PreviewURIServiceProvider previewProvider = previewURIProviderRegistry.getPreviewURIServiceProviders().get(getProviderName(wpStoreId)); + if (previewProvider == null) + { + previewProvider = previewURIProviderRegistry.getPreviewURIServiceProviders().get(previewURIProviderRegistry.getDefaultProviderName()); + } + return previewProvider; + } +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIServiceImplTest.java b/source/java/org/alfresco/wcm/preview/PreviewURIServiceImplTest.java new file mode 100644 index 0000000000..1056eea920 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIServiceImplTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.wcm.preview; + +import java.text.MessageFormat; +import java.util.Map; + +import org.alfresco.wcm.AbstractWCMServiceImplTest; +import org.alfresco.wcm.webproject.WebProjectInfo; + +/** + * Preview URI Service implementation unit test + * + * @author janv + */ +public class PreviewURIServiceImplTest extends AbstractWCMServiceImplTest +{ + // + // services + // + private PreviewURIServiceRegistry previewURIServiceRegistry; + private PreviewURIService prevService; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + // Get the required services + previewURIServiceRegistry = (PreviewURIServiceRegistry)ctx.getBean("previewURIServiceRegistry"); + prevService = (PreviewURIService)ctx.getBean("WCMPreviewURIService"); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + } + + public void testSetup() + { + Map prevURIServiceProviders = previewURIServiceRegistry.getPreviewURIServiceProviders(); + + System.out.println(prevURIServiceProviders.keySet()); + } + + public void testDefaultAndNOOP() + { + // Create a web project + WebProjectInfo wpInfo = wpService.createWebProject(TEST_WEBPROJ_DNS+"-previewSimple", TEST_WEBPROJ_NAME+"-previewSimple", TEST_WEBPROJ_TITLE, TEST_WEBPROJ_DESCRIPTION); + assertNotNull(wpInfo); + + String stagingPreviewURL = prevService.getPreviewURI(wpInfo.getStagingStoreName(), null); + assertNotNull(stagingPreviewURL); + + String expectedURL = MessageFormat.format(VirtualisationServerPreviewURIService.PREVIEW_SANDBOX_URL, + wpInfo.getStoreId(), + VirtualisationServerPreviewURIService.DEFAULT_VSERVER_IP, + ""+VirtualisationServerPreviewURIService.DEFAULT_VSERVER_PORT); + + assertEquals(expectedURL, stagingPreviewURL); + + String nullProvName = null; + Map prevURIServiceProviders = previewURIServiceRegistry.getPreviewURIServiceProviders(); + for (Map.Entry entry : prevURIServiceProviders.entrySet()) + { + PreviewURIServiceProvider prov = entry.getValue(); + if (prov instanceof NullPreviewURIService) + { + nullProvName = entry.getKey(); + break; + } + } + assertNotNull(nullProvName); + + wpInfo.setPreviewProviderName(nullProvName); + wpService.updateWebProject(wpInfo); + + stagingPreviewURL = prevService.getPreviewURI(wpInfo.getStagingStoreName(), null); // fails - returns 2 ? + assertNull(stagingPreviewURL); + } +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIServiceProvider.java b/source/java/org/alfresco/wcm/preview/PreviewURIServiceProvider.java new file mode 100644 index 0000000000..8d0a7214f0 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIServiceProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + +import java.util.List; + + +/** + * SPI (Service Provider Interface) abstraction for generating preview URLs. + * + * @author janv + * + * @since 3.2 + */ +public interface PreviewURIServiceProvider +{ + /** + * @param sbStoreId The sandbox store id to generate the preview URI for. + * @param pathToAsset The path to the asset to generate the preview URI for (can be null or empty, to return preview URL to store). + * @param previewContext Additional preview context + * + * @return The Preview URI for the given sandbox and/or asset (may be null). + */ + public String getPreviewURI(String sbStoreId, String pathToAsset, PreviewContext previewContext); + + /** + * @param sbStoreId The sandbox store id to generate the preview URI for. + * @param pathsToAssets The paths to the assets to generate the preview URI for. + * @param previewContext Additional preview context + * + * @return The Preview URIs for the given asset paths (may be null). + */ + public List getPreviewURIs(String sbStoreId, List pathsToAssets, PreviewContext previewContext); +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistry.java b/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistry.java new file mode 100644 index 0000000000..3a5fad6d3c --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistry.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + +import java.util.Map; + + +/** + * Preview URI Service Provider Registry + * + * @author janv + * + * @since 3.2 + */ +public interface PreviewURIServiceRegistry +{ + /** + * Return list of registered PreviewURI service providers + * + * @return + */ + public Map getPreviewURIServiceProviders(); + + /** + * Return default PreviewURI service provider + * + * @return + */ + public String getDefaultProviderName(); +} diff --git a/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistryImpl.java b/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistryImpl.java new file mode 100644 index 0000000000..57a1cc1fcd --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/PreviewURIServiceRegistryImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.wcm.preview; + +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.util.PropertyCheck; +import org.springframework.beans.factory.InitializingBean; + + +/** + * Preview URI Service Provider Registry Implementation + * + * @author janv + * + * @since 3.2 + */ +public class PreviewURIServiceRegistryImpl implements PreviewURIServiceRegistry, InitializingBean +{ + private static final String ERR_INVALID_DEFAULT_PREVIEW_URI_SERVICE = "preview.err.invalid_default_preview_uri_service"; + + private Map previewURIServicesByName; + private String defaultPreviewURIServiceName; + + public void setPreviewURIServiceProvidersByName(Map previewURIServicesByName) + { + this.previewURIServicesByName = previewURIServicesByName; + } + + public Map getPreviewURIServiceProviders() + { + return this.previewURIServicesByName; + } + + public void setDefaultProviderName(String defaultPreviewURIServiceName) + { + this.defaultPreviewURIServiceName = defaultPreviewURIServiceName; + } + + public String getDefaultProviderName() + { + return this.defaultPreviewURIServiceName; + } + + public void afterPropertiesSet() throws Exception + { + PropertyCheck.mandatory(this, "previewURIServicesByName", previewURIServicesByName); + PropertyCheck.mandatory(this, "defaultName", defaultPreviewURIServiceName); + + // Check that the default preview URI service provider name is valid + if ((defaultPreviewURIServiceName.length() == 0) || (previewURIServicesByName.get(defaultPreviewURIServiceName) == null)) + { + AlfrescoRuntimeException.create(ERR_INVALID_DEFAULT_PREVIEW_URI_SERVICE, defaultPreviewURIServiceName, previewURIServicesByName.keySet()); + } + } +} diff --git a/source/java/org/alfresco/wcm/preview/URITemplatePreviewURIService.java b/source/java/org/alfresco/wcm/preview/URITemplatePreviewURIService.java new file mode 100644 index 0000000000..5b05879fd7 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/URITemplatePreviewURIService.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + + +/** + * A PreviewURIService that takes a URI template and replaces the following parameters per request: + *

    + *
  • {storeId} - the store Id of the preview request
  • + *
  • {pathToAsset} - the full path and filename of the asset being previewed (including a leading '/')
  • + *
+ * + * @author Peter Monks, janv + * + * @since 3.2 + */ +public class URITemplatePreviewURIService extends AbstractPreviewURIServiceProvider +{ + private final static String URI_TEMPLATE_PARAMETER_STORE_ID = "{storeId}"; + private final static String URI_TEMPLATE_PARAMETER_PATH_TO_ASSET = "{pathToAsset}"; + + protected String uriTemplate; + + public void setUriTemplate(String uriTemplate) + { + this.uriTemplate = uriTemplate; + } + + public URITemplatePreviewURIService() + { + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIServiceProvider#getPreviewURI(java.lang.String, java.lang.String, org.alfresco.wcm.preview.PreviewContext) + */ + public String getPreviewURI(final String storeId, final String pathToAsset, final PreviewContext ignored) + { + String result = uriTemplate; + + if (uriTemplate.contains(URI_TEMPLATE_PARAMETER_STORE_ID)) + { + if (storeId != null && storeId.trim().length() > 0) + { + result = result.replace(URI_TEMPLATE_PARAMETER_STORE_ID, storeId); + } + else + { + // Shouldn't ever happen (store ids are always provided), but better to be safe than sorry + result = result.replace(URI_TEMPLATE_PARAMETER_STORE_ID, ""); + } + } + + if (uriTemplate.contains(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET)) + { + if (pathToAsset != null && pathToAsset.trim().length() > 0) + { + result = result.replace(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET, pathToAsset); + } + else + { + result = result.replace(URI_TEMPLATE_PARAMETER_PATH_TO_ASSET, ""); + } + } + + return(result); + } + +} diff --git a/source/java/org/alfresco/wcm/preview/VirtualisationServerPreviewURIService.java b/source/java/org/alfresco/wcm/preview/VirtualisationServerPreviewURIService.java new file mode 100644 index 0000000000..3509fb4f18 --- /dev/null +++ b/source/java/org/alfresco/wcm/preview/VirtualisationServerPreviewURIService.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ + +package org.alfresco.wcm.preview; + +import java.text.MessageFormat; + +import org.alfresco.config.JNDIConstants; +import org.alfresco.mbeans.VirtServerRegistry; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.util.ParameterCheck; +import org.alfresco.wcm.util.WCMUtil; + + +/** + * A PreviewURIService that constructs a virtualisation server URI. + * + * @author Peter Monks, janv + * + * @since 3.2 + */ +public class VirtualisationServerPreviewURIService extends AbstractPreviewURIServiceProvider +{ + // TODO - remove deprecated constants from JNDIConstants + + /** + * Default virtualization server IP address + */ + public final static String DEFAULT_VSERVER_IP = "127-0-0-1.ip.alfrescodemo.net"; + + /** + * Default virtualization server port number + */ + public final static int DEFAULT_VSERVER_PORT = 8180; + + /** + * Virtualization server sandbox URL pattern + */ + public final static String PREVIEW_SANDBOX_URL = "http://{0}.www--sandbox.{1}:{2}"; + + /** + * Virtualization server asset URL pattern + */ + public final static String PREVIEW_ASSET_URL = "http://{0}.www--sandbox.{1}:{2}{3}"; + + + private AVMService avmService; + private VirtServerRegistry virtSvrRegistry; + + public void setAvmService(AVMService avmService) + { + this.avmService = avmService; + } + + public void setVirtServerRegistry(VirtServerRegistry virtSvrRegistry) + { + this.virtSvrRegistry = virtSvrRegistry; + } + + /* (non-Javadoc) + * @see org.alfresco.wcm.preview.PreviewURIServiceProvider#getPreviewURI(java.lang.String, java.lang.String, org.alfresco.wcm.preview.PreviewContext) + */ + public String getPreviewURI(String sbStoreId, String pathToAsset, PreviewContext ignored) + { + ParameterCheck.mandatoryString("sbStoreId", sbStoreId); + + if ((pathToAsset == null) || (pathToAsset.length() == 0)) + { + return buildPreviewStoreUrl(sbStoreId, getVServerDomain(), getVServerPort(), WCMUtil.lookupStoreDNS(avmService, sbStoreId)); + } + + // Sanity checking + if (!pathToAsset.startsWith('/' + JNDIConstants.DIR_DEFAULT_WWW + '/' + JNDIConstants.DIR_DEFAULT_APPBASE)) + { + throw new IllegalStateException("Invalid asset path in AVM node ref: " + sbStoreId + ":" + pathToAsset); + } + + return buildPreviewAssetUrl(pathToAsset, getVServerDomain(), getVServerPort(), WCMUtil.lookupStoreDNS(avmService, sbStoreId)); + } + + private String buildPreviewStoreUrl(String sbStoreId, String domain, String port, String dns) + { + return MessageFormat.format(PREVIEW_SANDBOX_URL, dns, domain, port); + } + + private String buildPreviewAssetUrl(String assetPath, String domain, String port, String dns) + { + ParameterCheck.mandatoryString("assetPath", assetPath); + + if (domain == null || port == null || dns == null) + { + throw new IllegalArgumentException("Domain, port and dns name are mandatory."); + } + + if (assetPath.startsWith(JNDIConstants.DIR_DEFAULT_WWW_APPBASE)) + { + assetPath = assetPath.substring((JNDIConstants.DIR_DEFAULT_WWW_APPBASE).length()); + } + if (assetPath.startsWith(WCMUtil.PATH_SEPARATOR + WCMUtil.DIR_ROOT)) + { + assetPath = assetPath.substring((WCMUtil.PATH_SEPARATOR + WCMUtil.DIR_ROOT).length()); + } + + assetPath = WCMUtil.addLeadingSlash(assetPath); + + return MessageFormat.format(PREVIEW_ASSET_URL, dns, domain, port, assetPath); + } + + /** + * @return VServer Port + */ + private String getVServerPort() + { + Integer port = (virtSvrRegistry != null ? virtSvrRegistry.getVirtServerHttpPort() : null); + if (port == null) + { + port = DEFAULT_VSERVER_PORT; + } + return port.toString(); + } + + /** + * @return VServer Domain + */ + private String getVServerDomain() + { + String domain = (virtSvrRegistry != null ? virtSvrRegistry.getVirtServerFQDN() : null); + if (domain == null) + { + domain = DEFAULT_VSERVER_IP; + } + return domain; + } +} diff --git a/source/java/org/alfresco/wcm/sandbox/SandboxConstants.java b/source/java/org/alfresco/wcm/sandbox/SandboxConstants.java index c4afed6536..c327379807 100644 --- a/source/java/org/alfresco/wcm/sandbox/SandboxConstants.java +++ b/source/java/org/alfresco/wcm/sandbox/SandboxConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -56,6 +56,7 @@ public class SandboxConstants public final static QName PROP_WEBSITE_NAME = QName.createQName(null, ".website.name"); public final static QName PROP_AUTHOR_NAME = QName.createQName(null, ".author.name"); public final static QName PROP_WEB_PROJECT_NODE_REF = QName.createQName(null, ".web_project.noderef"); + public final static QName PROP_WEB_PROJECT_PREVIEW_PROVIDER = QName.createQName(null, ".web_project.previewprovider"); public final static QName PROP_LINK_VALIDATION_REPORT = QName.createQName(null, ".link.validation.report"); public final static QName PROP_LAST_DEPLOYMENT_ID = QName.createQName(null, ".deployment.id"); diff --git a/source/java/org/alfresco/wcm/sandbox/SandboxServiceImpl.java b/source/java/org/alfresco/wcm/sandbox/SandboxServiceImpl.java index 1932658ad5..e64809e687 100644 --- a/source/java/org/alfresco/wcm/sandbox/SandboxServiceImpl.java +++ b/source/java/org/alfresco/wcm/sandbox/SandboxServiceImpl.java @@ -466,8 +466,8 @@ public class SandboxServiceImpl implements SandboxService getSandbox(srcSandboxStoreId); // ignore result getSandbox(dstSandboxStoreId); // ignore result - String avmSrcPath = srcSandboxStoreId + WCMUtil.AVM_STORE_SEPARATOR + srcRelativePath; - String avmDstPath = dstSandboxStoreId + WCMUtil.AVM_STORE_SEPARATOR + dstRelativePath; + String avmSrcPath = WCMUtil.buildPath(srcSandboxStoreId, srcRelativePath); + String avmDstPath = WCMUtil.buildPath(dstSandboxStoreId, dstRelativePath); return listChanged(-1, avmSrcPath, -1, avmDstPath, includeDeleted); } @@ -635,34 +635,13 @@ public class SandboxServiceImpl implements SandboxService RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); final List srcPaths = new ArrayList(relativePaths.size()); - - String derivedWebApp = null; - boolean multiWebAppsFound = false; - for (String relativePath : relativePaths) { - // Example srcPath: - // mysite--alice:/www/avm_webapps/ROOT/foo.txt - String srcPath = sbStoreId + WCMUtil.AVM_STORE_SEPARATOR + relativePath; - srcPaths.add(srcPath); - - // derive webapp for now (TODO check usage) - String srcWebApp = WCMUtil.getWebapp(srcPath); - if (srcWebApp != null) - { - if (derivedWebApp == null) - { - derivedWebApp = srcWebApp; - } - else if (! derivedWebApp.equals(srcWebApp)) - { - multiWebAppsFound = true; - } - } + srcPaths.add(WCMUtil.buildPath(sbStoreId, relativePath)); } - final String webApp = (multiWebAppsFound == false ? derivedWebApp : null); - + final String webApp = WCMUtil.getCommonWebApp(sbStoreId, relativePaths); + RetryingTransactionCallback> sandboxCallback = new RetryingTransactionCallback>() { public Pair execute() throws Throwable @@ -671,10 +650,10 @@ public class SandboxServiceImpl implements SandboxService return createWorkflowSandbox(finalWorkflowName, finalWorkflowParams, stagingSandboxId, srcPaths, expirationDates); } }; - + // create the workflow sandbox firstly final Pair workflowInfo = txnHelper.doInTransaction(sandboxCallback, false, true); - + if (workflowInfo != null) { final SandboxInfo wfSandboxInfo = workflowInfo.getFirst(); @@ -685,7 +664,7 @@ public class SandboxServiceImpl implements SandboxService { WCMUtil.updateVServerWebapp(virtServerRegistry, virtUpdatePath, true); } - + try { RetryingTransactionCallback workflowCallback = new RetryingTransactionCallback() diff --git a/source/java/org/alfresco/wcm/util/WCMUtil.java b/source/java/org/alfresco/wcm/util/WCMUtil.java index 09a9f57b6c..089fff4013 100644 --- a/source/java/org/alfresco/wcm/util/WCMUtil.java +++ b/source/java/org/alfresco/wcm/util/WCMUtil.java @@ -24,7 +24,6 @@ */ package org.alfresco.wcm.util; -import java.text.MessageFormat; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -54,11 +53,8 @@ import org.apache.commons.logging.LogFactory; /** * Helper methods and constants related to WCM directories, paths and store name manipulation. - * - * TODO refactor ... - * - * @author Ariel Backenroth - * @author Kevin Roast + * + * @author Ariel Backenroth, Kevin Roast, janv */ public class WCMUtil { @@ -425,60 +421,6 @@ public class WCMUtil return WCMUtil.buildSandboxRootPath(storeName) + '/' + webApp; } - public static String buildStoreUrl(AVMService avmService, String storeName, String domain, String port) - { - ParameterCheck.mandatoryString("storeName", storeName); - - if (domain == null || port == null) - { - throw new IllegalArgumentException("Domain and port are mandatory."); - } - - // NOTE: for backwards compatibility - avmPath is converted to storeName (path is ignored) - if (storeName.indexOf(AVM_STORE_SEPARATOR) != -1) - { - storeName = storeName.substring(0, storeName.indexOf(AVM_STORE_SEPARATOR)); - } - - return MessageFormat.format(JNDIConstants.PREVIEW_SANDBOX_URL, - lookupStoreDNS(avmService, storeName), - domain, - port); - } - - protected static String buildWebappUrl(AVMService avmService, final String storeName, final String webApp, String domain, String port) - { - ParameterCheck.mandatoryString("webApp", webApp); - return (webApp.equals(DIR_ROOT) - ? buildStoreUrl(avmService, storeName, domain, port) - : buildStoreUrl(avmService, storeName, domain, port) + '/' + webApp); - } - - public static String buildAssetUrl(String assetPath, String domain, String port, String dns) - { - ParameterCheck.mandatoryString("assetPath", assetPath); - - if (domain == null || port == null || dns == null) - { - throw new IllegalArgumentException("Domain, port and dns name are mandatory."); - } - - if (assetPath.startsWith(JNDIConstants.DIR_DEFAULT_WWW_APPBASE)) - { - assetPath = assetPath.substring((JNDIConstants.DIR_DEFAULT_WWW_APPBASE).length()); - } - if (assetPath.startsWith('/' + DIR_ROOT)) - { - assetPath = assetPath.substring(('/' + DIR_ROOT).length()); - } - if (assetPath.length() == 0 || assetPath.charAt(0) != '/') - { - assetPath = '/' + assetPath; - } - - return MessageFormat.format(JNDIConstants.PREVIEW_ASSET_URL, dns, domain, port, assetPath); - } - public static String lookupStoreDNS(AVMService avmService, String store) { ParameterCheck.mandatoryString("store", store); @@ -761,11 +703,59 @@ public class WCMUtil return storePath; } + public static String buildPath(String sbStoreId, String relativePath) + { + return sbStoreId + AVM_STORE_SEPARATOR + addLeadingSlash(relativePath); + } + + public static String addLeadingSlash(String relativePath) + { + if ((relativePath.length() == 0) || (relativePath.charAt(0) != PATH_SEPARATOR)) + { + relativePath = PATH_SEPARATOR + relativePath; + } + + return relativePath; + } + + // return common web app or null if paths span multiple web apps (or no web app) + public static String getCommonWebApp(String sbStoreId, List storeRelativePaths) + { + String derivedWebApp = null; + boolean multiWebAppsFound = false; + + for (String storeRelativePath : storeRelativePaths) + { + // Example srcPath: + // mysite--alice:/www/avm_webapps/ROOT/foo.txt + String srcPath = WCMUtil.buildPath(sbStoreId, storeRelativePath); + + // TODO - don't really need the sbStoreId + // derive webapp for now + String srcWebApp = WCMUtil.getWebapp(srcPath); + if (srcWebApp != null) + { + if (derivedWebApp == null) + { + derivedWebApp = srcWebApp; + } + else if (! derivedWebApp.equals(srcWebApp)) + { + multiWebAppsFound = true; + } + } + } + + return (multiWebAppsFound == false ? derivedWebApp : null); + } + // Component Separator. protected static final String STORE_SEPARATOR = "--"; public static final String AVM_STORE_SEPARATOR = ":"; + public static final char PATH_SEPARATOR = '/'; + // names of the stores representing the layers for an AVM website //XXXarielb this should be private protected final static String STORE_WORKFLOW = "workflow"; diff --git a/source/java/org/alfresco/wcm/webproject/WebProjectInfo.java b/source/java/org/alfresco/wcm/webproject/WebProjectInfo.java index aa4c98dd0b..a3973a8a25 100644 --- a/source/java/org/alfresco/wcm/webproject/WebProjectInfo.java +++ b/source/java/org/alfresco/wcm/webproject/WebProjectInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -119,4 +119,23 @@ public interface WebProjectInfo * @param isTemplate set to true if this web project can also be used as a template */ public void setIsTemplate(boolean isTemplate); + + /** + * Get the preview URI service provider name + * + * @since 3.2 + * + * @return the preview URI service provider name + * + */ + public String getPreviewProviderName(); + + /** + * Set the preview URI service provider name + * + * @since 3.2 + * + * @param previewURIServiceProviderName the preview URI service provider name to set + */ + public void setPreviewProviderName(String previewURIServiceProviderName); } diff --git a/source/java/org/alfresco/wcm/webproject/WebProjectInfoImpl.java b/source/java/org/alfresco/wcm/webproject/WebProjectInfoImpl.java index dc33711a31..f8db6c72dc 100644 --- a/source/java/org/alfresco/wcm/webproject/WebProjectInfoImpl.java +++ b/source/java/org/alfresco/wcm/webproject/WebProjectInfoImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -54,24 +54,30 @@ public class WebProjectInfoImpl implements WebProjectInfo /** Web Project true if the web project can also be used as template */ private boolean isTemplate; - + + /** Web Project preview provider name (if null then default preview provider will be used) */ + private String previewURIServiceProviderName; /** * Constructor - * - * @param name name - * @param description description - * @param nodeRef web project node reference */ - /*package*/ WebProjectInfoImpl(String name, String title, String description, String wpStoreId, String defaultWebApp, boolean isTemplate, NodeRef nodeRef) + public WebProjectInfoImpl(String wpStoreId, + String name, + String title, + String description, + String defaultWebApp, + boolean isTemplate, + NodeRef nodeRef, + String previewProvider) { + this.wpStoreId = wpStoreId; this.name = name; this.title = title; this.description = description; - this.wpStoreId = wpStoreId; this.defaultWebApp = defaultWebApp; this.isTemplate = isTemplate; this.nodeRef = nodeRef; + this.previewURIServiceProviderName = previewProvider; } /** @@ -187,4 +193,14 @@ public class WebProjectInfoImpl implements WebProjectInfo { this.isTemplate = isTemplate; } + + public String getPreviewProviderName() + { + return previewURIServiceProviderName; + } + + public void setPreviewProviderName(String previewURIServiceProviderName) + { + this.previewURIServiceProviderName = previewURIServiceProviderName; + } } diff --git a/source/java/org/alfresco/wcm/webproject/WebProjectService.java b/source/java/org/alfresco/wcm/webproject/WebProjectService.java index 7139d76d2a..e32c2e72a6 100644 --- a/source/java/org/alfresco/wcm/webproject/WebProjectService.java +++ b/source/java/org/alfresco/wcm/webproject/WebProjectService.java @@ -1,3 +1,27 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ package org.alfresco.wcm.webproject; import java.util.List; @@ -25,7 +49,7 @@ public interface WebProjectService * Note: the DNS name will be used to generate the web project store id, which can be subsequently retrieved via WebProjectInfo.getStoreId() * * @param dnsName DNS name (required, must be unique) - * @param name name (require, must be unique) + * @param name name (required, must be unique) * @param title title * @param description description * @return WebProjectInfo the created web project info @@ -43,6 +67,8 @@ public interface WebProjectService * @param description description * @param sourceNodeRef web project node ref to branch from (can be null) * @return WebProjectInfo the created web project info + * + * @deprecated see createWebProject(String dnsName, WebProjectInfo wpInfo) */ public WebProjectInfo createWebProject(String dnsName, String name, String title, String description, NodeRef sourceNodeRef); @@ -51,8 +77,8 @@ public interface WebProjectService *

* Note: the DNS name will be used to generate the web project store id, which can be subsequently retrieved via WebProjectInfo.getStoreId() * - * @param dnsName DNS name (must be unique) - * @param name name (must be unique) + * @param dnsName DNS name (required, must be unique) + * @param name name (required, must be unique) * @param title title * @param description description * @param defaultWebApp default webapp (if null, will default to ROOT webapp) @@ -62,6 +88,28 @@ public interface WebProjectService */ public WebProjectInfo createWebProject(String dnsName, String name, String title, String description, String defaultWebApp, boolean useAsTemplate, NodeRef sourceNodeRef); + /** + * Create a new web project (with given web project info) + *

+ * Note: the DNS name will be used to generate the web project store id, which can be subsequently retrieved via WebProjectInfo.getStoreId() + * + * @param wpInfo web project info + * + * Note: + * + * @param dnsName DNS name (required, must be unique) + * @param name name (required, must be unique) + * @param title title + * @param description description + * @param defaultWebApp default webapp (if null, will default to ROOT webapp) + * @param useAsTemplate true if this web project can be used as a template to branch from + * @param sourceNodeRef web project node ref to branch from (can be null) + * @param previewProvider preview URI service provider name (must correspond to registered name, if null will be set to default provider) + * + * @return WebProjectInfo the created web project info + */ + public WebProjectInfo createWebProject(WebProjectInfo wpInfo); + /** * Returns the Web Projects container * @@ -136,6 +184,13 @@ public interface WebProjectService */ public WebProjectInfo getWebProject(NodeRef wpNodeRef); + /** + * Get preview provider name configured for given web project (if not configured then return default preview provider) + * @param wpStoreId web project store id + * @return previewProviderName preview URI service provide name + */ + public String getPreviewProvider(String wpStoreId); + /** * Update the web project info *

@@ -178,9 +233,9 @@ public interface WebProjectService *

* Current user must be a content manager for the web project * - * @param wpStoreId web project store id - * @param name webapp name (must be unique within a web project) - * @param description webapp description + * @param wpStoreId web project store id + * @param name webapp name (must be unique within a web project) + * @param description webapp description */ public void createWebApp(String wpStoreId, String name, String description); diff --git a/source/java/org/alfresco/wcm/webproject/WebProjectServiceImpl.java b/source/java/org/alfresco/wcm/webproject/WebProjectServiceImpl.java index c2f4fff474..88ac71cd98 100644 --- a/source/java/org/alfresco/wcm/webproject/WebProjectServiceImpl.java +++ b/source/java/org/alfresco/wcm/webproject/WebProjectServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,6 +47,7 @@ import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.TransactionListenerAdapter; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.locking.AVMLockingService; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; @@ -67,6 +68,8 @@ import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.DNSNameMangler; import org.alfresco.util.ParameterCheck; +import org.alfresco.wcm.preview.PreviewURIServiceRegistry; +import org.alfresco.wcm.sandbox.SandboxConstants; import org.alfresco.wcm.sandbox.SandboxFactory; import org.alfresco.wcm.sandbox.SandboxInfo; import org.alfresco.wcm.sandbox.SandboxFactory.UserRoleWrapper; @@ -101,6 +104,7 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService private SandboxFactory sandboxFactory; private VirtServerRegistry virtServerRegistry; + private PreviewURIServiceRegistry previewURIProviderRegistry; public void setNodeService(NodeService nodeService) { @@ -141,13 +145,17 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService { this.sandboxFactory = sandboxFactory; } - + public void setVirtServerRegistry(VirtServerRegistry virtServerRegistry) { this.virtServerRegistry = virtServerRegistry; } - + public void setPreviewURIServiceRegistry(PreviewURIServiceRegistry previewURIProviderRegistry) + { + this.previewURIProviderRegistry = previewURIProviderRegistry; + } + /* (non-Javadoc) * @see org.alfresco.wcm.WebProjectService#createWebProject(java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @@ -169,8 +177,25 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService */ public WebProjectInfo createWebProject(String dnsName, String name, String title, String description, String defaultWebApp, boolean useAsTemplate, NodeRef sourceNodeRef) { + return createWebProject(new WebProjectInfoImpl(dnsName, name, title, description, defaultWebApp, useAsTemplate, sourceNodeRef, null)); + } + + public WebProjectInfo createWebProject(WebProjectInfo wpInfo) + { + String wpStoreId = wpInfo.getStoreId(); + String name = wpInfo.getName(); + String title = wpInfo.getTitle(); + String description = wpInfo.getDescription(); + boolean useAsTemplate = wpInfo.isTemplate(); + NodeRef sourceNodeRef = wpInfo.getNodeRef(); + String defaultWebApp = wpInfo.getDefaultWebApp(); + String previewProviderName = wpInfo.getPreviewProviderName(); + + ParameterCheck.mandatoryString("wpStoreId", wpStoreId); + ParameterCheck.mandatoryString("name", name); + // Generate web project store id (an AVM store name) - String wpStoreId = DNSNameMangler.MakeDNSName(dnsName); + wpStoreId = DNSNameMangler.MakeDNSName(wpStoreId); if (wpStoreId.indexOf(WCMUtil.STORE_SEPARATOR) != -1) { @@ -182,9 +207,26 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService throw new IllegalArgumentException("Unexpected store id '"+wpStoreId+"' - should not contain '"+WCMUtil.AVM_STORE_SEPARATOR+"'"); } + if (previewProviderName == null) + { + // default preview URI service provider + previewProviderName = previewURIProviderRegistry.getDefaultProviderName(); + } + else if (! previewURIProviderRegistry.getPreviewURIServiceProviders().keySet().contains(previewProviderName)) + { + throw new AlfrescoRuntimeException("Cannot update web project '" + wpInfo.getStoreId() + "' - unknown preview URI service provider ("+previewProviderName+")"); + } + + // default webapp name + defaultWebApp = (defaultWebApp != null && defaultWebApp.length() != 0) ? defaultWebApp : WCMUtil.DIR_ROOT; + // create the website space in the correct parent folder Map props = new HashMap(1); props.put(ContentModel.PROP_NAME, name); + props.put(WCMAppModel.PROP_ISSOURCE, useAsTemplate); + props.put(WCMAppModel.PROP_DEFAULTWEBAPP, defaultWebApp); + props.put(WCMAppModel.PROP_AVMSTORE, wpStoreId); // reference to the root AVM store + props.put(WCMAppModel.PROP_PREVIEW_PROVIDER, previewProviderName); ChildAssociationRef childAssocRef = nodeService.createNode( getWebProjectsRoot(), @@ -203,16 +245,6 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, description); nodeService.addAspect(wpNodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps); - // use as template source flag - nodeService.setProperty(wpNodeRef, WCMAppModel.PROP_ISSOURCE, useAsTemplate); - - // set the default webapp name for the project - defaultWebApp = (defaultWebApp != null && defaultWebApp.length() != 0) ? defaultWebApp : WCMUtil.DIR_ROOT; - nodeService.setProperty(wpNodeRef, WCMAppModel.PROP_DEFAULTWEBAPP, defaultWebApp); - - // set the property on the node to reference the root AVM store - nodeService.setProperty(wpNodeRef, WCMAppModel.PROP_AVMSTORE, wpStoreId); - // branch from source web project, if supplied String branchStoreId = null; if (sourceNodeRef != null) @@ -223,10 +255,11 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService // create the AVM staging store to represent the newly created location website sandboxFactory.createStagingSandbox(wpStoreId, wpNodeRef, branchStoreId); // ignore return, fails if web project already exists + String stagingStore = WCMUtil.buildStagingStoreName(wpStoreId); + // create the default webapp folder under the hidden system folders if (branchStoreId == null) { - String stagingStore = WCMUtil.buildStagingStoreName(wpStoreId); String stagingStoreRoot = WCMUtil.buildSandboxRootPath(stagingStore); avmService.createDirectory(stagingStoreRoot, defaultWebApp); avmService.addAspect(AVMNodeConverter.ExtendAVMPath(stagingStoreRoot, defaultWebApp), WCMAppModel.ASPECT_WEBAPP); @@ -235,8 +268,10 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService // now the sandbox is created set the permissions masks for the store sandboxFactory.setStagingPermissionMasks(wpStoreId); - // set the property on the node to reference the root AVM store - nodeService.setProperty(wpNodeRef, WCMAppModel.PROP_AVMSTORE, wpStoreId); + // set preview provider on staging store (used for preview lookup) + avmService.setStoreProperty(stagingStore, + SandboxConstants.PROP_WEB_PROJECT_PREVIEW_PROVIDER, + new PropertyValue(DataTypeDefinition.TEXT, previewProviderName)); // inform the locking service about this new instance avmLockingService.addWebProject(wpStoreId); @@ -261,8 +296,7 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService } // Return created web project info - WebProjectInfo wpInfo = new WebProjectInfoImpl(name, title, description, wpStoreId, defaultWebApp, useAsTemplate, wpNodeRef); - return wpInfo; + return new WebProjectInfoImpl(wpStoreId, name, title, description, defaultWebApp, useAsTemplate, wpNodeRef, previewProviderName); } /* (non-Javadoc) @@ -371,6 +405,8 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService // get AVM store name of the staging sandbox final String wpStoreId = wpInfo.getStoreId(); + WCMUtil.removeVServerWebapp(virtServerRegistry, WCMUtil.buildStoreWebappPath(wpStoreId, webAppName), true); + AuthenticationUtil.runAs(new RunAsWork() { public Object doWork() throws Exception @@ -525,6 +561,38 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService return result; } + /* (non-Javadoc) + * @see org.alfresco.wcm.webproject.WebProjectService#getPreviewProvider(java.lang.String) + */ + public String getPreviewProvider(String wpStoreId) + { + ParameterCheck.mandatoryString("wpStoreId", wpStoreId); + + String previewProviderName = null; + + try + { + String stagingStoreId = WCMUtil.buildStagingStoreName(wpStoreId); + PropertyValue pValue = avmService.getStoreProperty(stagingStoreId, SandboxConstants.PROP_WEB_PROJECT_PREVIEW_PROVIDER); + + if (pValue != null) + { + previewProviderName = (String)pValue.getValue(DataTypeDefinition.TEXT); + } + } + catch (AVMNotFoundException nfe) + { + logger.warn(wpStoreId + " is not a web project: " + nfe); + } + + if (previewProviderName == null) + { + previewProviderName = previewURIProviderRegistry.getDefaultProviderName(); + } + + return previewProviderName; + } + /* (non-Javadoc) * @see org.alfresco.wcm.webproject.WebProjectService#getWebProject(org.alfresco.service.cmr.repository.NodeRef) */ @@ -544,9 +612,10 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService String wpStoreId = (String)properties.get(WCMAppModel.PROP_AVMSTORE); String defaultWebApp = (String)properties.get(WCMAppModel.PROP_DEFAULTWEBAPP); Boolean useAsTemplate = (Boolean)properties.get(WCMAppModel.PROP_ISSOURCE); + String previewProvider = (String)properties.get(WCMAppModel.PROP_PREVIEW_PROVIDER); // Create and return the web project info - WebProjectInfo wpInfo = new WebProjectInfoImpl(name, title, description, wpStoreId, defaultWebApp, useAsTemplate, wpNodeRef); + WebProjectInfo wpInfo = new WebProjectInfoImpl(wpStoreId, name, title, description, defaultWebApp, useAsTemplate, wpNodeRef, previewProvider); return wpInfo; } @@ -558,7 +627,21 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService NodeRef wpNodeRef = getWebProjectNodeFromStore(wpInfo.getStoreId()); if (wpNodeRef == null) { - throw new AlfrescoRuntimeException("Cannot update web project '" + wpInfo.getStoreId() + "' because it does not exist."); + throw new AlfrescoRuntimeException("Cannot update web project '" + wpInfo.getStoreId() + "' - it does not exist."); + } + + if (! listWebApps(wpNodeRef).contains(wpInfo.getDefaultWebApp())) + { + throw new AlfrescoRuntimeException("Cannot update web project '" + wpInfo.getStoreId() + "' - unknown default web app ("+wpInfo.getDefaultWebApp()+")"); + } + + if (wpInfo.getPreviewProviderName() == null) + { + wpInfo.setPreviewProviderName(previewURIProviderRegistry.getDefaultProviderName()); + } + else if (! previewURIProviderRegistry.getPreviewURIServiceProviders().keySet().contains(wpInfo.getPreviewProviderName())) + { + throw new AlfrescoRuntimeException("Cannot update web project '" + wpInfo.getStoreId() + "' - unknown preview URI service provider ("+wpInfo.getPreviewProviderName()+")"); } // Note: the site preset and short name can not be updated @@ -571,9 +654,18 @@ public class WebProjectServiceImpl extends WCMUtil implements WebProjectService properties.put(ContentModel.PROP_DESCRIPTION, wpInfo.getDescription()); properties.put(WCMAppModel.PROP_DEFAULTWEBAPP, wpInfo.getDefaultWebApp()); properties.put(WCMAppModel.PROP_ISSOURCE, wpInfo.isTemplate()); + properties.put(WCMAppModel.PROP_PREVIEW_PROVIDER, wpInfo.getPreviewProviderName()); this.nodeService.setProperties(wpNodeRef, properties); + // set preview provider on staging store (used for preview lookup) + String stagingStore = WCMUtil.buildStagingStoreName(wpInfo.getStoreId()); + + avmService.deleteStoreProperty(stagingStore, SandboxConstants.PROP_WEB_PROJECT_PREVIEW_PROVIDER); + avmService.setStoreProperty(stagingStore, + SandboxConstants.PROP_WEB_PROJECT_PREVIEW_PROVIDER, + new PropertyValue(DataTypeDefinition.TEXT, wpInfo.getPreviewProviderName())); + if (logger.isDebugEnabled()) { logger.debug("Updated web project: " + wpNodeRef + " (store id: " + wpInfo.getStoreId() + ")"); diff --git a/source/java/org/alfresco/wcm/webproject/WebProjectServiceImplTest.java b/source/java/org/alfresco/wcm/webproject/WebProjectServiceImplTest.java index 52ce6473d6..b28c2f06b9 100644 --- a/source/java/org/alfresco/wcm/webproject/WebProjectServiceImplTest.java +++ b/source/java/org/alfresco/wcm/webproject/WebProjectServiceImplTest.java @@ -457,7 +457,7 @@ public class WebProjectServiceImplTest extends AbstractWCMServiceImplTest public void testUpdateWebProject() { - WebProjectInfo wpInfo = new WebProjectInfoImpl(TEST_WEBPROJ_DNS+"-update", TEST_WEBPROJ_NAME+"-update", TEST_WEBPROJ_TITLE, TEST_WEBPROJ_DESCRIPTION, TEST_WEBPROJ_DEFAULT_WEBAPP, false, null); + WebProjectInfo wpInfo = new WebProjectInfoImpl(TEST_WEBPROJ_DNS+"-update", TEST_WEBPROJ_NAME+"-update", TEST_WEBPROJ_TITLE, TEST_WEBPROJ_DESCRIPTION, TEST_WEBPROJ_DEFAULT_WEBAPP, false, null, null); try { diff --git a/source/test-resources/wcm/wcm-test-preview-context.xml b/source/test-resources/wcm/wcm-test-preview-context.xml new file mode 100644 index 0000000000..7ca496e4eb --- /dev/null +++ b/source/test-resources/wcm/wcm-test-preview-context.xml @@ -0,0 +1,22 @@ + + + + + + + + Virtualisation Server Preview + + + + + + + + + + + + + +