/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
*/
package org.alfresco.web.bean.wcm;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMAppModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.ExpiringValueCache;
import org.alfresco.wcm.preview.PreviewURIService;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.wcm.webproject.WebProjectInfo;
import org.alfresco.wcm.webproject.WebProjectInfoImpl;
import org.alfresco.wcm.webproject.WebProjectService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.BaseWizardBean;
import org.alfresco.web.bean.wizard.BaseInviteUsersWizard.UserGroupRole;
import org.alfresco.web.forms.Form;
import org.alfresco.web.forms.FormNotFoundException;
import org.alfresco.web.forms.FormsService;
import org.alfresco.web.forms.RenderingEngineTemplate;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.common.component.UIListItem;
import org.alfresco.web.ui.common.component.UISelectList;
import org.alfresco.web.ui.wcm.WebResources;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Backing bean for the Create Web Project wizard.
*
* @author Kevin Roast
* @author Arseny Kovalchuk (The fixer of the issue https://issues.alfresco.com/jira/browse/ETWOTWO-600,601)
*/
public class CreateWebsiteWizard extends BaseWizardBean
{
private static final long serialVersionUID = 6480869380508635173L;
private static final String MSG_USERROLES = "create_website_summary_users";
private static final String MSG_SERVER_ALREADY_EXIST = "server_already_exist";
private static final String COMPONENT_FORMLIST = "form-list";
private static final String COMPONENT_WORKFLOWLIST = "workflow-list";
// wizard step names (that are referenced)
private static final String STEP_DETAILS = "details";
private static final String STEP_DEPLOYMENT = "deployment";
private static final String MATCH_DEFAULT = ".*";
private static final String WEBAPP_DEFAULT = "ROOT";
// Create From drop-down control selection values
private static final String CREATE_EMPTY = "empty";
private static final String CREATE_EXISTING = "existing";
protected final static Log logger = LogFactory.getLog(CreateWebsiteWizard.class);
protected boolean editMode = false;
// TODO refactor to WebProjectInfo
protected String dnsName;
protected String title;
protected String name;
protected String description;
protected String webapp = WEBAPP_DEFAULT;
protected String createFrom = null;
protected boolean isSource;
protected String previewProvider;
protected NodeRef wpNodeRef;
protected String[] sourceWebProject = null;
protected ExpiringValueCache> webProjectsList;
protected List webappsList;
protected List previewProvidersList;
protected boolean showAllSourceProjects;
protected String websiteDescriptionAttribute;
transient private WorkflowService workflowService;
transient private PersonService personService;
transient private FormsService formsService;
transient private WebProjectService wpService;
transient private PreviewURIService previewURIService;
/** set true when an option in the Create From screen is changed - this is used as an
indicator to reload the wizard data model from the selected source web project */
private boolean createFromValueChanged;
/** datamodel for table of selected forms */
transient private DataModel formsDataModel = null;
/** transient list of form UIListItem objects */
protected List formsList = null;
/** list of form wrapper objects */
protected List forms = null;
/** Current form for dialog context */
protected FormWrapper actionForm = null;
/** datamodel for table of selected workflows */
transient private DataModel workflowsDataModel = null;
/** list of workflow wrapper objects */
protected List workflows = null;
/** Current workflow for dialog context */
protected WorkflowConfiguration actionWorkflow = null;
/** Map and list of deployment servers */
protected Map deployServersMap = null;
protected List deployServersList = null;
/** Current state of deploy server editing */
protected DeploymentServerConfig currentDeployServer = null;
protected Map editedDeployServerProps = null;
protected boolean inAddDeployServerMode = false;
protected String addDeployServerType = WCMAppModel.CONSTRAINT_FILEDEPLOY;
// ------------------------------------------------------------------------------
// Wizard implementation
/**
* Initialises the wizard
*/
public void init(Map parameters)
{
super.init(parameters);
this.name = null;
this.dnsName = null;
this.title = null;
this.description = null;
this.isSource = false;
clearFormsWorkflowsDeploymentAndUsers();
this.createFrom = CREATE_EMPTY;
// requry existing web projects list every 10 seconds
this.webProjectsList = new ExpiringValueCache>(1000L*10L);
this.sourceWebProject = null;
this.createFromValueChanged = false;
this.showAllSourceProjects = false;
this.websiteDescriptionAttribute = null;
}
private void clearFormsWorkflowsDeploymentAndUsers()
{
this.formsDataModel = null;
this.forms = new ArrayList(8);
this.workflowsDataModel = null;
this.workflows = new ArrayList(4);
// reset all deployment data
this.deployServersMap = new HashMap(4, 1.0f);
this.deployServersList = new ArrayList(4);
this.currentDeployServer = null;
this.editedDeployServerProps = new HashMap(12, 1.0f);
this.inAddDeployServerMode = false;
this.addDeployServerType = WCMAppModel.CONSTRAINT_FILEDEPLOY;
// init the dependant bean we are using for the invite users pages
InviteWebsiteUsersWizard wiz = getInviteUsersWizard();
wiz.init(null);
}
/**
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// the Finish button can be pressed early in the steps - ensure the model is up-to-date
updateModelOnCreateFromChange();
// if the user selected Create From existing web project we will branch from it
NodeRef sourceNodeRef = null;
if (CREATE_EXISTING.equals(this.createFrom) &&
(this.sourceWebProject != null && this.sourceWebProject.length != 0))
{
sourceNodeRef = new NodeRef(this.sourceWebProject[0]);
}
WebProjectInfo wpInfo = getWebProjectService().createWebProject(new WebProjectInfoImpl(this.dnsName, this.name, this.title, this.description, this.webapp, this.isSource, sourceNodeRef, this.previewProvider));
String avmStore = wpInfo.getStoreId();
NodeRef wpNodeRef = wpInfo.getNodeRef();
final NodeRef websiteParent = getWebProjectService().getWebProjectsRoot();
// call a delegate wizard bean to provide invite user functionality
InviteWebsiteUsersWizard wiz = getInviteUsersWizard();
wiz.reset();
wiz.setNode(new Node(wpNodeRef));
wiz.setAvmStore(avmStore);
wiz.setStandalone(false);
// the wizard is responsible for notifying the invited users, setting the appropriate
// node permissions and also for creating user sandboxes and associations to the web folder node
outcome = wiz.finishImpl(context, outcome);
if (outcome != null)
{
// persist the forms, templates, workflows, workflow defaults and deployment
// config to the model for this web project
saveWebProjectModel(wpNodeRef);
// navigate to the Websites folder so we can see the newly created folder
this.navigator.setCurrentNodeId(websiteParent.getId());
outcome = AlfrescoNavigationHandler.CLOSE_WIZARD_OUTCOME;
}
return outcome;
}
@Override
public boolean getFinishButtonDisabled()
{
// allow finish from any step other than the initial details page
String stepName = Application.getWizardManager().getCurrentStepName();
return (STEP_DETAILS.equals(stepName));
}
/**
* Persist the forms, templates, workflows, workflow defaults and deployment config
* to the model for this web project
*
* @param nodeRef NodeRef to the web project
*/
protected void saveWebProjectModel(NodeRef nodeRef)
{
Map props = new HashMap(4, 1.0f);
// first walk each form object, saving templates and workflow defaults for each
for (FormWrapper form : this.forms)
{
// create web form with name as per the name of the form object in the DD
props.put(WCMAppModel.PROP_FORMNAME, form.getName());
NodeRef formRef = getNodeService().createNode(nodeRef,
WCMAppModel.ASSOC_WEBFORM,
WCMAppModel.ASSOC_WEBFORM,
WCMAppModel.TYPE_WEBFORM,
props).getChildRef();
// add title aspect for user defined title and description labels
props.clear();
props.put(ContentModel.PROP_TITLE, form.getTitle());
props.put(ContentModel.PROP_DESCRIPTION, form.getDescription());
getNodeService().addAspect(formRef, ContentModel.ASPECT_TITLED, props);
// add filename pattern aspect if a filename pattern has been applied
if (form.getOutputPathPattern() != null)
{
props.clear();
props.put(WCMAppModel.PROP_OUTPUT_PATH_PATTERN, form.getOutputPathPattern());
getNodeService().addAspect(formRef, WCMAppModel.ASPECT_OUTPUT_PATH_PATTERN, props);
}
// associate to workflow defaults if any are present
if (form.getWorkflow() != null)
{
WorkflowWrapper workflow = form.getWorkflow();
props.clear();
props.put(WCMAppModel.PROP_WORKFLOW_NAME, workflow.getName());
NodeRef workflowRef = getNodeService().createNode(formRef,
WCMAppModel.ASSOC_WORKFLOWDEFAULTS,
WCMAppModel.ASSOC_WORKFLOWDEFAULTS,
WCMAppModel.TYPE_WORKFLOW_DEFAULTS,
props).getChildRef();
// persist workflow default params
if (workflow.getParams() != null)
{
AVMWorkflowUtil.serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef);
}
}
// associate to a web form template for each template applied to the form
for (PresentationTemplate template : form.getTemplates())
{
props.clear();
props.put(WCMAppModel.PROP_BASE_RENDERING_ENGINE_TEMPLATE_NAME,
template.getRenderingEngineTemplate().getName());
NodeRef templateRef = getNodeService().createNode(formRef,
WCMAppModel.ASSOC_WEBFORMTEMPLATE,
WCMAppModel.ASSOC_WEBFORMTEMPLATE,
WCMAppModel.TYPE_WEBFORMTEMPLATE,
props).getChildRef();
// add filename pattern aspect if a filename pattern has been applied
if (template.getOutputPathPattern() != null)
{
props.clear();
props.put(WCMAppModel.PROP_OUTPUT_PATH_PATTERN, template.getOutputPathPattern());
getNodeService().addAspect(templateRef, WCMAppModel.ASPECT_OUTPUT_PATH_PATTERN, props);
}
}
}
// walk each web project workflow definition and save defaults for each
for (WorkflowWrapper workflow : this.workflows)
{
props.clear();
props.put(WCMAppModel.PROP_WORKFLOW_NAME, workflow.getName());
NodeRef workflowRef = getNodeService().createNode(nodeRef,
WCMAppModel.ASSOC_WEBWORKFLOWDEFAULTS,
WCMAppModel.ASSOC_WEBWORKFLOWDEFAULTS,
WCMAppModel.TYPE_WEBWORKFLOWDEFAULTS,
props).getChildRef();
// persist workflow default params
if (workflow.getParams() != null)
{
AVMWorkflowUtil.serializeWorkflowParams((Serializable)workflow.getParams(), workflowRef);
}
// add filename pattern aspect if a filename pattern has been applied
if (workflow.getFilenamePattern() != null)
{
props.clear();
props.put(WCMAppModel.PROP_FILENAMEPATTERN, workflow.getFilenamePattern());
getNodeService().addAspect(workflowRef, WCMAppModel.ASPECT_FILENAMEPATTERN, props);
}
}
// finally walk through the deployment config and save
for (DeploymentServerConfig server : this.deployServersList)
{
Map repoProps = server.getRepoProps();
getNodeService().createNode(nodeRef, WCMAppModel.ASSOC_DEPLOYMENTSERVER,
WCMAppModel.ASSOC_DEPLOYMENTSERVER, WCMAppModel.TYPE_DEPLOYMENTSERVER,
repoProps);
if (logger.isDebugEnabled())
{
// overwrite the password property before logging
Map tempProps = new HashMap(repoProps.size());
tempProps.putAll(repoProps);
tempProps.put(WCMAppModel.PROP_DEPLOYSERVERPASSWORD, "*****");
logger.debug("Saved deploymentserver node using repo props: " + tempProps);
}
}
}
/**
* Restore the forms, templates, workflows and deployment config from the model for a web project.
* Can also optionally restore the basic node propetries and user details.
*
* @param nodeRef NodeRef to the web project to load model from
* @param loadProperties Load the basic properties such as name, title, DNS.
* @param loadUsers Load the user details.
*/
@SuppressWarnings("unchecked")
protected void loadWebProjectModel(NodeRef nodeRef, boolean loadProperties, boolean loadUsers)
{
// simple properties are optionally loaded
if (loadProperties)
{
WebProjectInfo wpInfo = getWebProjectService().getWebProject(nodeRef);
this.name = wpInfo.getName();
this.title = wpInfo.getTitle();
this.description = wpInfo.getDescription();
this.dnsName = wpInfo.getStoreId();
this.webapp = wpInfo.getDefaultWebApp();
this.isSource = wpInfo.isTemplate();
this.wpNodeRef = wpInfo.getNodeRef();
this.previewProvider = wpInfo.getPreviewProviderName();
}
if (loadUsers)
{
InviteWebsiteUsersWizard wiz = getInviteUsersWizard();
wiz.reset();
// load the users assigned to the web project
Map userRoles = getWebProjectService().listWebUsers(nodeRef);
for (Map.Entry userRole : userRoles.entrySet())
{
String username = userRole.getKey();
String userrole = userRole.getValue();
wiz.addAuthorityWithRole(username, userrole);
}
}
// load the form templates
List webFormRefs = getNodeService().getChildAssocs(
nodeRef, WCMAppModel.ASSOC_WEBFORM, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : webFormRefs)
{
NodeRef formRef = ref.getChildRef();
String name = (String)getNodeService().getProperty(formRef, WCMAppModel.PROP_FORMNAME);
try
{
Form formImpl = getFormsService().getWebForm(name);
FormWrapper form = new FormWrapper(formImpl);
form.setTitle((String)getNodeService().getProperty(formRef, ContentModel.PROP_TITLE));
form.setDescription((String)getNodeService().getProperty(formRef, ContentModel.PROP_DESCRIPTION));
form.setOutputPathPattern((String)getNodeService().getProperty(formRef, WCMAppModel.PROP_OUTPUT_PATH_PATTERN));
// the single workflow attached to the form
List workflowRefs = getNodeService().getChildAssocs(
formRef, WCMAppModel.ASSOC_WORKFLOWDEFAULTS, RegexQNamePattern.MATCH_ALL);
if (workflowRefs.size() == 1)
{
NodeRef wfRef = workflowRefs.get(0).getChildRef();
String wfName = (String)getNodeService().getProperty(wfRef, WCMAppModel.PROP_WORKFLOW_NAME);
WorkflowDefinition wfDef = getWorkflowService().getDefinitionByName(wfName);
if (wfDef != null)
{
WorkflowWrapper wfWrapper = new WorkflowWrapper(wfName, wfDef.getTitle(), wfDef.getDescription());
wfWrapper.setParams((Map)AVMWorkflowUtil.deserializeWorkflowParams(wfRef));
if (wfDef.getStartTaskDefinition() != null)
{
wfWrapper.setType(wfDef.getStartTaskDefinition().metadata.getName());
}
form.setWorkflow(wfWrapper);
}
}
// the templates attached to the form
List templateRefs = getNodeService().getChildAssocs(
formRef, WCMAppModel.ASSOC_WEBFORMTEMPLATE, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef tChildRef : templateRefs)
{
NodeRef templateRef = tChildRef.getChildRef();
String renderingEngineTemplateName = (String)getNodeService().getProperty(
templateRef, WCMAppModel.PROP_BASE_RENDERING_ENGINE_TEMPLATE_NAME);
RenderingEngineTemplate ret = formImpl.getRenderingEngineTemplate(renderingEngineTemplateName);
if (ret != null)
{
String outputPathPattern = (String)getNodeService().getProperty(
templateRef, WCMAppModel.PROP_OUTPUT_PATH_PATTERN);
form.addTemplate(new PresentationTemplate(ret, outputPathPattern));
}
}
this.forms.add(form);
}
catch (FormNotFoundException fnfe)
{
// ignore as we cannot do anything about a missing form
if (logger.isDebugEnabled())
logger.debug("Unable to find Web Form named '" + fnfe.getFormName() +
"' as referenced in web project: " + nodeRef.toString());
}
}
// load the workflows associated with the website
List workflowRefs = getNodeService().getChildAssocs(
nodeRef, WCMAppModel.ASSOC_WEBWORKFLOWDEFAULTS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef wChildRef : workflowRefs)
{
NodeRef wfRef = wChildRef.getChildRef();
String wfName = (String)getNodeService().getProperty(wfRef, WCMAppModel.PROP_WORKFLOW_NAME);
WorkflowDefinition wfDef = getWorkflowService().getDefinitionByName(wfName);
if (wfDef != null)
{
WorkflowWrapper wfWrapper = new WorkflowWrapper(wfName, wfDef.getTitle(), wfDef.getDescription());
wfWrapper.setParams((Map)AVMWorkflowUtil.deserializeWorkflowParams(wfRef));
wfWrapper.setFilenamePattern((String)getNodeService().getProperty(wfRef,
WCMAppModel.PROP_FILENAMEPATTERN));
if (wfDef.getStartTaskDefinition() != null)
{
wfWrapper.setType(wfDef.getStartTaskDefinition().metadata.getName());
}
this.workflows.add(wfWrapper);
}
}
// load the deployment server config objects
List serverRefs = getNodeService().getChildAssocs(
nodeRef, WCMAppModel.ASSOC_DEPLOYMENTSERVER, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef sChildRef : serverRefs)
{
NodeRef serverRef = sChildRef.getChildRef();
DeploymentServerConfig server = new DeploymentServerConfig(
serverRef, getNodeService().getProperties(serverRef));
this.deployServersList.add(server);
this.deployServersMap.put(server.getId(), server);
if (logger.isDebugEnabled())
logger.debug("Loaded deploy server config: " + server);
}
}
// ------------------------------------------------------------------------------
// Service setters
/**
* @param workflowService The WorkflowService to set.
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
protected WorkflowService getWorkflowService()
{
if (workflowService == null)
{
workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return workflowService;
}
/**
* @param personService The PersonService to set.
*/
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
protected PersonService getPersonService()
{
if (personService == null)
{
personService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPersonService();
}
return personService;
}
/**
* @param formsService The FormsService to set.
*/
public void setFormsService(final FormsService formsService)
{
this.formsService = formsService;
}
protected FormsService getFormsService()
{
if (formsService == null)
{
formsService = (FormsService) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "FormsService");
}
return formsService;
}
/**
* @param wpService The WebProjectService to set.
*/
public void setWebProjectService(final WebProjectService wpService)
{
this.wpService = wpService;
}
protected WebProjectService getWebProjectService()
{
if (wpService == null)
{
wpService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWebProjectService();
}
return wpService;
}
/**
* @param previewURIService The PreviewURIService to set.
*/
public void setPreviewURIService(final PreviewURIService previewURIService)
{
this.previewURIService = previewURIService;
}
protected PreviewURIService getPreviewURIService()
{
if (previewURIService == null)
{
previewURIService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getPreviewURIService();
}
return previewURIService;
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @return Returns the wizard Edit Mode.
*/
public boolean getEditMode()
{
return this.editMode;
}
/**
* @param editMode The wizard Edit Mode to set.
*/
public void setEditMode(boolean editMode)
{
this.editMode = editMode;
}
/**
* @return Returns the web project node ref.
*/
protected NodeRef getWebProjectNodeRef()
{
return wpNodeRef;
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return DNS name
*/
public String getDnsName()
{
return this.dnsName;
}
/**
* @param dnsName DNS name
*/
public void setDnsName(String dnsName)
{
this.dnsName = dnsName;
}
/**
* @return Returns the title.
*/
public String getTitle()
{
return title;
}
/**
* @param title The title to set.
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @return Returns the description.
*/
public String getDescription()
{
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return the default webapp name for the project
*/
public String getWebapp()
{
return this.webapp;
}
/**
* @param webapp The default webapp name for the project
*/
public void setWebapp(String webapp)
{
this.webapp = webapp;
}
public String getPreviewProvider()
{
return this.previewProvider;
}
public void setPreviewProvider(String previewProvider)
{
this.previewProvider = previewProvider;
}
/**
* @return the create from selection value
*/
public String getCreateFrom()
{
return this.createFrom;
}
/**
* @param createFrom the create from selection value
*/
public void setCreateFrom(String createFrom)
{
if (createFrom != null && createFrom.equals(this.createFrom) == false)
{
this.createFromValueChanged = true;
}
this.createFrom = createFrom;
}
/**
* @return the existing Web Project to use
*/
public String[] getSourceWebProject()
{
return this.sourceWebProject;
}
/**
* @param existingWebProject the existing Web Project to set
*/
public void setSourceWebProject(String[] existingWebProject)
{
if (this.sourceWebProject != null && this.sourceWebProject.length != 0)
{
if ((existingWebProject == null || existingWebProject.length == 0) ||
(existingWebProject[0].equals(this.sourceWebProject[0]) == false))
{
this.createFromValueChanged = true;
}
}
else
{
if (existingWebProject != null && existingWebProject.length != 0)
{
this.createFromValueChanged = true;
}
}
this.sourceWebProject = existingWebProject;
}
/**
* @return name of the source web project selected - or null if none set
*/
public String getSourceWebProjectName()
{
String name = null;
if (CREATE_EXISTING.equals(this.createFrom) &&
(this.sourceWebProject != null && this.sourceWebProject.length != 0))
{
NodeRef sourceNodeRef = new NodeRef(this.sourceWebProject[0]);
name = (String)getNodeService().getProperty(sourceNodeRef, ContentModel.PROP_NAME);
}
return name;
}
/**
* @return true if this website is set to be a template source website for future web projects
*/
public boolean isSource()
{
return this.isSource;
}
/**
* @param isSource true if this website is set to be a template source website for future web projects
*/
public void setSource(boolean isSource)
{
this.isSource = isSource;
}
/**
* @return the existingWebProjects
*/
public List getWebProjectsList()
{
List webProjects = this.webProjectsList.get();
if (webProjects == null)
{
List wps = getWebProjectService().listWebProjects();
webProjects = new ArrayList(wps.size());
for (WebProjectInfo wpInfo : wps)
{
if ((this.showAllSourceProjects == false) && (! wpInfo.isTemplate()))
{
// only query for web project templates by default
continue;
}
UIListItem item = new UIListItem();
item.setLabel(wpInfo.getName());
item.setDescription(wpInfo.getDescription());
item.setValue(wpInfo.getNodeRef().toString());
item.setImage(WebResources.IMAGE_WEBPROJECT_32);
webProjects.add(item);
}
this.webProjectsList.put(webProjects);
}
return webProjects;
}
/**
* Action handler called when toggle Show All/Show Template Web Projects link is clicked
*/
public void toggleWebProjectsList(ActionEvent event)
{
this.showAllSourceProjects = !this.showAllSourceProjects;
this.webProjectsList.clear();
this.createFromValueChanged = true;
}
/**
* @return true to show all Web Projects in the Create From list,
* false to only show those marked as templates
*/
public boolean getShowAllSourceProjects()
{
return this.showAllSourceProjects;
}
/**
* @return List of SelectItem objects representing the webapp folders present in the project
*/
public List getWebappsList()
{
if (this.webappsList == null)
{
this.webappsList = new ArrayList(1);
this.webappsList.add(new SelectItem(WEBAPP_DEFAULT, WEBAPP_DEFAULT));
}
return this.webappsList;
}
public List getPreviewProvidersList()
{
if (this.previewProvidersList == null)
{
// create list of preview providers
String defaultPreviewProvider = getPreviewURIService().getDefaultProviderName();
Set previewProviders = getPreviewURIService().getProviderNames();
this.previewProvidersList = new ArrayList(previewProviders.size());
this.previewProvidersList.add(new SelectItem(defaultPreviewProvider, defaultPreviewProvider));
for (String previewProvider : previewProviders)
{
if (! previewProvider.equals(defaultPreviewProvider))
{
this.previewProvidersList.add(new SelectItem(previewProvider, previewProvider));
}
}
}
return this.previewProvidersList;
}
/**
* @see org.alfresco.web.bean.wizard.BaseWizardBean#next()
*/
@Override
public String next()
{
String stepName = Application.getWizardManager().getCurrentStepName();
if (STEP_DEPLOYMENT.equals(stepName))
{
// if we have just entered the deployment page and the Create From page data has changed
// then we need to pre-populate the Forms etc. from the template web project
updateModelOnCreateFromChange();
}
return super.next();
}
/**
* Update the wizard model when the value in the Create From page changes
*/
private void updateModelOnCreateFromChange()
{
if (this.createFromValueChanged)
{
if (CREATE_EXISTING.equals(this.createFrom))
{
if (this.sourceWebProject != null && this.sourceWebProject.length != 0)
{
clearFormsWorkflowsDeploymentAndUsers();
loadWebProjectModel(new NodeRef(this.sourceWebProject[0]), false, true);
}
}
else
{
clearFormsWorkflowsDeploymentAndUsers();
}
this.createFromValueChanged = false;
}
}
/**
* @return summary text for the wizard
*/
@SuppressWarnings("unchecked")
public String getSummary()
{
FacesContext fc = FacesContext.getCurrentInstance();
// build a summary section to list the invited users and there roles
StringBuilder buf = new StringBuilder(128);
List invitedUserRoles =
(List)getInviteUsersWizard().getUserRolesDataModel().getWrappedData();
String currentUser = Application.getCurrentUser(fc).getUserName();
boolean foundCurrentUser = false;
for (UserGroupRole userRole : invitedUserRoles)
{
if (currentUser.equals(userRole.getAuthority()))
{
foundCurrentUser = true;
}
buf.append(Utils.encode(userRole.getLabel()));
buf.append("
");
}
if (foundCurrentUser == false)
{
buf.append(getInviteUsersWizard().buildLabelForUserAuthorityRole(
currentUser, WCMUtil.ROLE_CONTENT_MANAGER));
}
return buildSummary(
new String[] {Application.getMessage(fc, MSG_USERROLES)},
new String[] {buf.toString()});
}
/**
* @return the invited users for the project - as UserWrapper instances
*/
@SuppressWarnings("unchecked")
public List getInvitedUsers()
{
final FacesContext fc = FacesContext.getCurrentInstance();
List invitedUserRoles = (List)
getInviteUsersWizard().getUserRolesDataModel().getWrappedData();
List result = new LinkedList();
String currentUser = Application.getCurrentUser(fc).getUserName();
boolean foundCurrentUser = false;
for (UserGroupRole userRole : invitedUserRoles)
{
if (currentUser.equals(userRole.getAuthority()))
{
foundCurrentUser = true;
}
result.add(new UserWrapper(userRole.getAuthority(), userRole.getRole()));
}
if (foundCurrentUser == false)
{
result.add(new UserWrapper(currentUser, WCMUtil.ROLE_CONTENT_MANAGER));
}
return result;
}
// ------------------------------------------------------------------------------
// Deployment server configuration
/**
* @return Determines whether a deployment server is being added
*/
public boolean isInAddDeployServerMode()
{
return this.inAddDeployServerMode;
}
/**
* @return The type of server receiver to add, either 'alfresco' or 'file'
*/
public String getAddDeployServerType()
{
return this.addDeployServerType;
}
/**
* @return The deploy server currently being added or edited
*/
public DeploymentServerConfig getCurrentDeployServer()
{
return this.currentDeployServer;
}
/**
* @return The properties of the deploy server currently being added or edited
*/
public Map getEditedDeployServerProperties()
{
return this.editedDeployServerProps;
}
/**
* @return Map of the deployment servers currently configured for the web project
*/
public List getDeployServers()
{
return this.deployServersList;
}
/**
* Sets up the wizard for adding a new Alfresco Server Receiver
*
* @return null outcome to stay on same page
*/
public String addAlfrescoServerReceiver()
{
this.addDeployServerType = WCMAppModel.CONSTRAINT_ALFDEPLOY;
this.inAddDeployServerMode = true;
// create an empty server config
this.currentDeployServer = new DeploymentServerConfig(this.addDeployServerType);
this.editedDeployServerProps.clear();
// refresh the current page
return null;
}
/**
* Sets up the wizard for adding a new File System Receiver
*
* @return null outcome to stay on same page
*/
public String addFileSystemReceiver()
{
this.addDeployServerType = WCMAppModel.CONSTRAINT_FILEDEPLOY;
this.inAddDeployServerMode = true;
// create an empty server config
this.currentDeployServer = new DeploymentServerConfig(this.addDeployServerType);
this.editedDeployServerProps.clear();
// refresh the current page
return null;
}
public void editDeploymentServerConfig(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0)
{
this.inAddDeployServerMode = false;
// setup the config object to edit
this.currentDeployServer = this.deployServersMap.get(id);
this.editedDeployServerProps.clear();
this.editedDeployServerProps.putAll(this.currentDeployServer.getProperties());
if (logger.isDebugEnabled())
logger.debug("Set current deploy server to: " + this.currentDeployServer);
}
}
public void deleteDeploymentServerConfig(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0)
{
this.currentDeployServer = null;
this.editedDeployServerProps.clear();
this.inAddDeployServerMode = false;
// remove the config object from the list and map
DeploymentServerConfig dsc = this.deployServersMap.get(id);
if (dsc != null)
{
this.deployServersList.remove(dsc);
this.deployServersMap.remove(dsc.getId());
if (logger.isDebugEnabled())
logger.debug("Removed deploy server config with id: " + id);
}
}
}
public String addDeploymentServerConfig()
{
// add the new config to the list and map
this.deployServersList.add(this.currentDeployServer);
this.deployServersMap.put(this.currentDeployServer.getId(),
this.currentDeployServer);
// save the changes
return saveDeploymentServerConfig();
}
public String saveDeploymentServerConfig()
{
String currentServerName = (String) editedDeployServerProps.get(DeploymentServerConfig.PROP_NAME);
if (currentServerName == null ||currentServerName.length() == 0)
{
currentServerName = "" + editedDeployServerProps.get(DeploymentServerConfig.PROP_HOST)+ ":" + editedDeployServerProps.get(DeploymentServerConfig.PROP_PORT);
}
for (DeploymentServerConfig server: deployServersList)
{
if (!server.getId().equals(currentDeployServer.getId()))
{
Map serverProps = server.getProperties();
String serverName = (String) serverProps.get(DeploymentServerConfig.PROP_NAME);
if (serverName == null ||serverName.length() == 0)
{
serverName = "" + serverProps.get(DeploymentServerConfig.PROP_HOST)+ ":" + serverProps.get(DeploymentServerConfig.PROP_PORT);
}
if (currentServerName.equals(serverName))
{
if (this.inAddDeployServerMode)
{
this.deployServersList.remove(this.currentDeployServer);
this.deployServersMap.remove(this.currentDeployServer.getId());
}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_SERVER_ALREADY_EXIST), currentServerName));
return null;
}
}
}
// set the edited properties
this.currentDeployServer.setProperties(this.editedDeployServerProps);
if (logger.isDebugEnabled())
logger.debug("Saved transient deploy server config: " + this.currentDeployServer);
// reset state
this.currentDeployServer = null;
this.editedDeployServerProps.clear();
this.inAddDeployServerMode = false;
// refresh the current page
return null;
}
public String cancelDeploymentServerConfig()
{
this.currentDeployServer = null;
this.editedDeployServerProps.clear();
this.inAddDeployServerMode = false;
return null;
}
// ------------------------------------------------------------------------------
// Define Web Content Workflows page
/**
* @return JSF data model for the Form templates
*/
public DataModel getFormsDataModel()
{
if (this.formsDataModel == null)
{
this.formsDataModel = new ListDataModel();
}
// only set the wrapped data once otherwise the row index gets reset
if (this.formsDataModel.getWrappedData() == null)
{
this.formsDataModel.setWrappedData(this.forms);
}
return this.formsDataModel;
}
/**
* @return the List of selected and configured Form objects (for summary screen)
*/
public List getForms()
{
return this.forms;
}
/**
* @param formsDataModel JSF data model for the Form templates
*/
public void setFormsDataModel(DataModel formsDataModel)
{
this.formsDataModel = formsDataModel;
}
/**
* @return List of UI items to represent the available Web Forms for all websites
*/
public List getFormsList()
{
Collection