From 35f25777dea0a9f98e3953b5e00975d7d3047d2e Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 14 Dec 2006 16:18:32 +0000 Subject: [PATCH] . Hooks to notify virtualisation server when the following cases occur to a web project: - Import of website content - Edits/uploads to WEB-INF/web.xml, WEB-INF/lib/*, WEB-INF/classes/* - Addition of new user sandbox - Removal of a user sandbox . Fix to generation of website preview url in sandbox display when switching between root webapp folders . Fix to issue when swapping between web projects that did not contain the same webapp context git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4611 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/web/bean/wcm/AVMBrowseBean.java | 21 +++++--- .../alfresco/web/bean/wcm/AVMConstants.java | 48 +++++++++++++++---- .../alfresco/web/bean/wcm/AVMEditBean.java | 12 ++--- .../web/bean/wcm/AddAvmContentDialog.java | 5 ++ .../web/bean/wcm/DeleteSandboxDialog.java | 4 ++ .../web/bean/wcm/ImportWebsiteDialog.java | 3 ++ .../bean/wcm/InviteWebsiteUsersWizard.java | 22 +++++++++ .../alfresco/web/bean/wcm/SandboxFactory.java | 2 +- .../web/ui/wcm/component/UIUserSandboxes.java | 16 ++++++- source/web/WEB-INF/faces-config-beans.xml | 4 ++ source/web/jsp/wcm/browse-website.jsp | 4 +- 11 files changed, 113 insertions(+), 28 deletions(-) diff --git a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java index 1cfb6d4d28..ff5c0dc117 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java @@ -142,6 +142,9 @@ public class AVMBrowseBean implements IContextListener /** Current AVM Node action context */ private AVMNode avmNode = null; + /** The last displayed website node id */ + private String lastWebsiteId = null; + /** breadcrumb location */ private List location = null; @@ -306,8 +309,7 @@ public class AVMBrowseBean implements IContextListener FacesContext fc = FacesContext.getCurrentInstance(); ResourceBundle msg = Application.getBundle(fc); - Node websiteNode = this.navigator.getCurrentNode(); - String storeRoot = (String)websiteNode.getProperties().get(WCMAppModel.PROP_AVMSTORE); + String storeRoot = (String)getWebsite().getProperties().get(WCMAppModel.PROP_AVMSTORE); String stagingStore = getStagingStore(); AVMStoreDescriptor store = this.avmService.getAVMStore(stagingStore); if (store != null) @@ -335,8 +337,7 @@ public class AVMBrowseBean implements IContextListener */ public String getStagingStore() { - Node websiteNode = this.navigator.getCurrentNode(); - String storeRoot = (String)websiteNode.getProperties().get(WCMAppModel.PROP_AVMSTORE); + String storeRoot = (String)getWebsite().getProperties().get(WCMAppModel.PROP_AVMSTORE); return AVMConstants.buildAVMStagingStoreName(storeRoot); } @@ -485,7 +486,7 @@ public class AVMBrowseBean implements IContextListener } this.sandboxTitle = MessageFormat.format(Application.getMessage( FacesContext.getCurrentInstance(), MSG_SANDBOXTITLE), - this.navigator.getCurrentNode().getName(), + getWebsite().getName(), forUser); } return this.sandboxTitle; @@ -528,6 +529,13 @@ public class AVMBrowseBean implements IContextListener */ public Node getWebsite() { + // check to see if the website we are browsing has changed since the last time + if (this.navigator.getCurrentNodeId().equals(this.lastWebsiteId) == false) + { + // clear context when we are browsing a new website + this.lastWebsiteId = this.navigator.getCurrentNodeId(); + this.webapp = null; + } return this.navigator.getCurrentNode(); } @@ -631,9 +639,8 @@ public class AVMBrowseBean implements IContextListener if (user.isAdmin() == false) { String currentUser = user.getUserName(); - Node websiteNode = this.navigator.getCurrentNode(); List userInfoRefs = this.nodeService.getChildAssocs( - websiteNode.getNodeRef(), WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL); + getWebsite().getNodeRef(), WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef ref : userInfoRefs) { NodeRef userInfoRef = ref.getChildRef(); diff --git a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java index 1490214a93..b688c61e5b 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java @@ -267,7 +267,7 @@ public final class AVMConstants * * @return true if the path should require a virtualisation server reload, false otherwise */ - public static boolean requiresServerReload(String path) + public static boolean requiresVServerUpdate(String path) { if (path == null || path.length() == 0) { @@ -277,14 +277,45 @@ public final class AVMConstants return webinfPathPattern.matcher(path).matches(); } - public static void reloadServerOnPath(String path, boolean force) + /** + * Update notification on the virtualisation server webapp as required for the specified path + * + * @param path Path to match against + * @param force True to force update of server even if path does not match + */ + public static void updateVServerWebapp(String path, boolean force) { - if (force || requiresServerReload(path)) + if (force || requiresVServerUpdate(path)) { VirtServerRegistry vServerRegistry = (VirtServerRegistry)FacesContextUtils.getRequiredWebApplicationContext( FacesContext.getCurrentInstance()).getBean(BEAN_VIRT_SERVER_REGISTRY); - int webappindex = path.indexOf('/', path.indexOf(DIR_WEBAPPS) + DIR_WEBAPPS.length() + 1); - vServerRegistry.webappUpdated(-1, path.substring(0, webappindex)); + int webappIndex = path.indexOf('/', path.indexOf(DIR_WEBAPPS) + DIR_WEBAPPS.length() + 1); + if (webappIndex != -1) + { + path = path.substring(0, webappIndex); + } + vServerRegistry.webappUpdated(-1, path); + } + } + + /** + * Removal notification on the virtualisation server webapp as required for the specified path + * + * @param path Path to match against + * @param force True to force update of server even if path does not match + */ + public static void removeVServerWebapp(String path, boolean force) + { + if (force || requiresVServerUpdate(path)) + { + VirtServerRegistry vServerRegistry = (VirtServerRegistry)FacesContextUtils.getRequiredWebApplicationContext( + FacesContext.getCurrentInstance()).getBean(BEAN_VIRT_SERVER_REGISTRY); + int webappIndex = path.indexOf('/', path.indexOf(DIR_WEBAPPS) + DIR_WEBAPPS.length() + 1); + if (webappIndex != -1) + { + path = path.substring(0, webappIndex); + } + vServerRegistry.webappRemoved(-1, path); } } @@ -328,10 +359,7 @@ public final class AVMConstants // patterns for WEB-INF files that require virtualisation server reload private final static Pattern webinfPathPattern = Pattern.compile( - ".*:/" + AVMConstants.DIR_APPBASE + "/" + AVMConstants.DIR_WEBAPPS + "/.*/WEB-INF/(classes/.*)|(lib/.*)|(web.xml)", + ".*:/" + AVMConstants.DIR_APPBASE + "/" + AVMConstants.DIR_WEBAPPS + + "/.*/WEB-INF/((classes/.*)|(lib/.*)|(web.xml))", Pattern.CASE_INSENSITIVE); - //private final static Pattern webinfLibPattern = Pattern.compile( - // ".*:/" + AVMConstants.DIR_APPBASE + "/" + AVMConstants.DIR_WEBAPPS + "/.*/WEB-INF/lib/.*"); - //private final static Pattern webinfWebXmlPattern = Pattern.compile( - // ".*:/" + AVMConstants.DIR_APPBASE + "/" + AVMConstants.DIR_WEBAPPS + "/.*/WEB-INF/web.xml"); } diff --git a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java index 719a27eaa4..69bc59e236 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMEditBean.java @@ -387,30 +387,28 @@ public class AVMEditBean { return null; } - + final FormsService formsService = FormsService.getInstance(); final NodeRef avmRef = AVMNodeConverter.ToNodeRef(-1, avmNode.getPath()); try { tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); - + // get an updating writer that we can use to modify the content on the current node ContentWriter writer = this.contentService.getWriter(avmRef, ContentModel.PROP_CONTENT, true); - if (nodeService.hasAspect(avmRef, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { this.editorOutput = formsService.writeXMLToString(this.instanceDataDocument); } writer.putContent(this.editorOutput); - + // commit the transaction tx.commit(); // regenerate form content if (nodeService.hasAspect(avmRef, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { - formsService.regenerateRenditions(avmRef); NodeRef[] uploadedFiles = this.formProcessorSession.getUploadedFiles(); final List diffList = new ArrayList(uploadedFiles.length); @@ -424,7 +422,9 @@ public class AVMEditBean } this.avmSyncService.update(diffList, null, true, true, true, true, null, null); } - + + AVMConstants.updateVServerWebapp(avmNode.getPath(), false); + resetState(); return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; diff --git a/source/java/org/alfresco/web/bean/wcm/AddAvmContentDialog.java b/source/java/org/alfresco/web/bean/wcm/AddAvmContentDialog.java index 44149cb335..1b92542b1c 100644 --- a/source/java/org/alfresco/web/bean/wcm/AddAvmContentDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/AddAvmContentDialog.java @@ -100,6 +100,11 @@ public class AddAvmContentDialog extends AddContentDialog writer.putContent(strContent == null ? "" : strContent); } + // reload the virtualisation server as required + if (logger.isDebugEnabled()) + logger.debug("Reloading virtualisation server on path: " + path); + AVMConstants.updateVServerWebapp(path, false); + // remember the created node now this.createdNode = fileNodeRef; } diff --git a/source/java/org/alfresco/web/bean/wcm/DeleteSandboxDialog.java b/source/java/org/alfresco/web/bean/wcm/DeleteSandboxDialog.java index fc9e998bc0..31efbc8ddf 100644 --- a/source/java/org/alfresco/web/bean/wcm/DeleteSandboxDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/DeleteSandboxDialog.java @@ -88,6 +88,10 @@ public class DeleteSandboxDialog extends BaseDialogBean // remove the association to this web project user meta-data this.nodeService.removeChild(website.getNodeRef(), ref.getChildRef()); + // update virtualisation server for the sandbox removal + String path = AVMConstants.buildAVMStoreWebappPath(sandbox, this.avmBrowseBean.getWebapp()); + AVMConstants.removeVServerWebapp(path, true); + break; } } diff --git a/source/java/org/alfresco/web/bean/wcm/ImportWebsiteDialog.java b/source/java/org/alfresco/web/bean/wcm/ImportWebsiteDialog.java index 4f31369618..8bba851db2 100644 --- a/source/java/org/alfresco/web/bean/wcm/ImportWebsiteDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/ImportWebsiteDialog.java @@ -227,6 +227,9 @@ public class ImportWebsiteDialog // After an import it's a good idea to snapshot the staging store this.avmService.createSnapshot(store, "Import of file: " + this.fileName, null); + + // Reload virtualisation server as required + AVMConstants.updateVServerWebapp(rootPath, true); } } else diff --git a/source/java/org/alfresco/web/bean/wcm/InviteWebsiteUsersWizard.java b/source/java/org/alfresco/web/bean/wcm/InviteWebsiteUsersWizard.java index a60a2e6671..28e07c0c23 100644 --- a/source/java/org/alfresco/web/bean/wcm/InviteWebsiteUsersWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/InviteWebsiteUsersWizard.java @@ -11,6 +11,7 @@ import java.util.Set; import javax.faces.context.FacesContext; import org.alfresco.model.WCMAppModel; +import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; @@ -41,6 +42,17 @@ public class InviteWebsiteUsersWizard extends InviteUsersWizard /** assume we are launching the wizard standalone */ private boolean standalone = true; + /** AVM Browse Bean reference */ + protected AVMBrowseBean avmBrowseBean; + + + /** + * @param avmBrowseBean The AVMBrowseBean to set. + */ + public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean) + { + this.avmBrowseBean = avmBrowseBean; + } /** * @see org.alfresco.web.bean.wizard.InviteUsersWizard#init(java.util.Map) @@ -129,6 +141,7 @@ public class InviteWebsiteUsersWizard extends InviteUsersWizard { SandboxFactory.createUserSandbox( getAvmStore(), this.managers, userRole.getAuthority(), userRole.getRole()); + } } @@ -149,6 +162,15 @@ public class InviteWebsiteUsersWizard extends InviteUsersWizard props); } } + + // reload virtualisation server for the web project + if (isStandalone()) + { + String stagingStore = AVMConstants.buildAVMStagingStoreName(getAvmStore()); + String path = AVMConstants.buildAVMStoreWebappPath(stagingStore, this.avmBrowseBean.getWebapp()); + AVMConstants.updateVServerWebapp(path, true); + } + return outcome; } diff --git a/source/java/org/alfresco/web/bean/wcm/SandboxFactory.java b/source/java/org/alfresco/web/bean/wcm/SandboxFactory.java index 19b09d0370..ec9c6a83a8 100644 --- a/source/java/org/alfresco/web/bean/wcm/SandboxFactory.java +++ b/source/java/org/alfresco/web/bean/wcm/SandboxFactory.java @@ -277,7 +277,7 @@ public final class SandboxFactory */ private static void tagStoreDNSPath(AVMService avmService, String store, String... components) { - String path = store + ":/" + AVMConstants.DIR_APPBASE + '/' + AVMConstants.DIR_WEBAPPS; + String path = AVMConstants.buildAVMStoreRootPath(store); // DNS name mangle the property name - can only contain value DNS characters! String dnsProp = AVMConstants.PROP_DNS + DNSNameMangler.MakeDNSName(components); avmService.setStoreProperty(store, QName.createQName(null, dnsProp), diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java index a016b32d23..f63d7b131d 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -111,6 +111,7 @@ public class UIUserSandboxes extends SelfRenderingComponent private static final String ROLE_CONTENT_MANAGER = "ContentManager"; private static final String REQUEST_FORM_REF = "formref"; + private static final String REQUEST_PREVIEW_REF = "prevhref"; private static final String SPACE_ICON = "/images/icons/" + BrowseBean.SPACE_SMALL_DEFAULT + ".gif"; @@ -334,9 +335,12 @@ public class UIUserSandboxes extends SelfRenderingComponent // direct actions for a sandbox String websiteUrl = AVMConstants.buildAVMWebappUrl(mainStore, getWebapp()); + Map requestMap = context.getExternalContext().getRequestMap(); + requestMap.put(REQUEST_PREVIEW_REF, websiteUrl); Utils.encodeRecursive(context, aquireAction( context, mainStore, username, ACT_SANDBOX_PREVIEW, "/images/icons/preview_website.gif", - null, null, websiteUrl, null)); + null, null, "#{" + REQUEST_PREVIEW_REF + "}", null)); + requestMap.remove(REQUEST_PREVIEW_REF); out.write(" "); Utils.encodeRecursive(context, aquireAction( @@ -968,7 +972,15 @@ public class UIUserSandboxes extends SelfRenderingComponent } if (url != null) { - control.setHref(url); + if (url.startsWith("#{") == true) + { + ValueBinding vb = facesApp.createValueBinding(url); + control.setValueBinding("href", vb); + } + else + { + control.setHref(url); + } control.setTarget("new"); } diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 8c6c32b71c..e896c7a6a6 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -2284,6 +2284,10 @@ authorityService #{AuthorityService} + + avmBrowseBean + #{AVMBrowseBean} + diff --git a/source/web/jsp/wcm/browse-website.jsp b/source/web/jsp/wcm/browse-website.jsp index 28eda57489..5464fba559 100644 --- a/source/web/jsp/wcm/browse-website.jsp +++ b/source/web/jsp/wcm/browse-website.jsp @@ -78,7 +78,7 @@ <%-- More actions menu --%> - + @@ -183,7 +183,7 @@ <%-- User Sandboxes List --%> - +