001/*
002 *  Copyright 2023 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.web.live;
017
018import java.util.List;
019
020import org.apache.commons.lang3.StringUtils;
021import org.apache.commons.lang3.exception.ExceptionUtils;
022import org.quartz.JobExecutionContext;
023
024import org.ametys.runtime.config.Config;
025import org.ametys.runtime.i18n.I18nizableText;
026
027
028/**
029 * Rebuild live workspace for all contents without site.
030 * 
031 * This schedulable will send a report mail at the end end of execution
032 */
033public class RebuildContentsWithoutSiteLiveWorkspaceSchedulable extends AbstractRebuildLiveWorkspaceSchedulable
034{
035    @Override
036    protected void _rebuildLiveWorkspace(JobExecutionContext context) throws Exception
037    {
038        _rebuildLiveComponent.rebuildContentsWithoutSiteWorkspace();
039    }
040    
041    @Override
042    protected I18nizableText _getSuccessMailSubject(JobExecutionContext context)
043    {
044        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILD_CONTENTS_WITHOUT_SITE_SUCCESS_MAIL_SUBJECT");
045    }
046    
047    @Override
048    protected I18nizableText _getSuccessMailBody(JobExecutionContext context)
049    {
050        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILD_CONTENTS_WITHOUT_SITE_SUCCESS_MAIL_BODY");
051    }
052    
053    @Override
054    protected I18nizableText _getErrorMailSubject(JobExecutionContext context)
055    {
056        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILD_CONTENTS_WITHOUT_SITE_ERROR_MAIL_SUBJECT");
057    }
058    
059    @Override
060    protected I18nizableText _getErrorMailBody(JobExecutionContext context, Throwable throwable)
061    {
062        String cmsUrl = StringUtils.stripEnd(StringUtils.removeEndIgnoreCase(Config.getInstance().getValue("cms.url"), "index.html"), "/");
063        String url = cmsUrl + "/_admin/";
064        String error = ExceptionUtils.getStackTrace(throwable);
065        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILD_CONTENTS_WITHOUT_SITE_ERROR_MAIL_BODY", List.of(url, error));
066    }
067}