001/*
002 *  Copyright 2020 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.workspaces.alert;
017
018import java.util.Collections;
019import java.util.Set;
020
021import org.apache.commons.lang.StringUtils;
022
023import org.ametys.plugins.workspaces.AbstractWorkspaceModule;
024import org.ametys.plugins.workspaces.project.objects.Project;
025import org.ametys.runtime.i18n.I18nizableText;
026import org.ametys.web.repository.page.ModifiablePage;
027import org.ametys.web.repository.page.Page.PageType;
028import org.ametys.web.repository.sitemap.Sitemap;
029
030/**
031 * Workspaces module for alerts
032 */
033public class AlertWorkspaceModule extends AbstractWorkspaceModule
034{
035    /** The id of alert module */
036    public static final String ALERT_MODULE_ID = AlertWorkspaceModule.class.getName();
037    
038    /** Workspaces alerts node name */
039    private static final String __WORKSPACES_ALERTS_NODE_NAME = "alerts";
040    
041    public String getId()
042    {
043        return ALERT_MODULE_ID;
044    }
045
046    public int getOrder()
047    {
048        return ORDER_ALERTS;
049    }
050
051    public String getModuleName()
052    {
053        return __WORKSPACES_ALERTS_NODE_NAME;
054    }
055
056    public Set<String> getAllowedEventTypes()
057    {
058        return Collections.EMPTY_SET;
059    }
060
061    @Override
062    protected String getModulePageName()
063    {
064        return "alerts";
065    }
066
067    public I18nizableText getModuleTitle()
068    {
069        return new I18nizableText("plugin." + _pluginName, "PLUGINS_WORKSPACES_PROJECT_MODULE_ALERTS_LABEL");
070    }
071    public I18nizableText getModuleDescription()
072    {
073        return new I18nizableText("plugin." + _pluginName, "PLUGINS_WORKSPACES_PROJECT_MODULE_ALERTS_DESCRIPTION");
074    }
075
076    @Override
077    protected I18nizableText getModulePageTitle()
078    {
079        return new I18nizableText("plugin." + _pluginName, "PLUGINS_WORKSPACES_PROJECT_WORKSPACE_PAGE_ALERTS_TITLE");
080    }
081    
082    @Override
083    protected ModifiablePage _createModulePage(Project project, Sitemap sitemap, String name, I18nizableText pageTitle, String skinTemplate)
084    {
085        if (!sitemap.hasChild(name))
086        {
087            ModifiablePage page = sitemap.createChild(name, "ametys:defaultPage");
088            
089            // Title should not be missing, but just in case if the i18n message or the whole catalog does not exists in the requested language
090            // to prevent a non-user-friendly error and still generate the project workspace.
091            page.setTitle(StringUtils.defaultIfEmpty(_i18nUtils.translate(pageTitle, sitemap.getName()), "Missing title"));
092            page.setType(PageType.NODE);
093            page.setSiteName(sitemap.getSiteName());
094            page.setSitemapName(sitemap.getName());
095            
096            sitemap.saveChanges();
097            
098            return page;
099        }
100        else
101        {
102            return null;
103        }
104    }
105
106    @Override
107    protected void initializeModulePage(ModifiablePage modulePage)
108    {
109        modulePage.untag("SECTION");
110    }
111    
112    @Override
113    protected String getModulePageTemplate() 
114    {
115        return "page";
116    }
117
118    @Override
119    protected boolean _showActivatedStatus()
120    {
121        return false;
122    }
123}