001/*
002 *  Copyright 2016 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.lang.StringUtils;
021import org.apache.commons.lang3.exception.ExceptionUtils;
022import org.quartz.JobExecutionContext;
023
024import org.ametys.core.observation.Observer;
025import org.ametys.core.schedule.Schedulable;
026import org.ametys.runtime.config.Config;
027import org.ametys.runtime.i18n.I18nizableText;
028
029/**
030 * A {@link Schedulable} job which rebuild and populate the live workspace.
031 * This ensures data integrity inside the live workspace if by mistake
032 * synchronization {@link Observer}s fails to update the live workspace.
033 */
034public class RebuildLiveAllWorkspaceSchedulable extends AbstractRebuildLiveWorkspaceSchedulable
035{
036    @Override
037    protected void _rebuildLiveWorkspace(JobExecutionContext context) throws Exception
038    {
039        _rebuildLiveComponent.rebuildLiveWorkspace();
040    }
041    
042    @Override
043    protected I18nizableText _getSuccessMailSubject(JobExecutionContext context)
044    {
045        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILDALL_SUCCESS_MAIL_SUBJECT");
046    }
047    
048    @Override
049    protected I18nizableText _getSuccessMailBody(JobExecutionContext context)
050    {
051        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILDALL_SUCCESS_MAIL_BODY");
052    }
053    
054    @Override
055    protected I18nizableText _getErrorMailSubject(JobExecutionContext context)
056    {
057        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILDALL_ERROR_MAIL_SUBJECT");
058    }
059    
060    @Override
061    protected I18nizableText _getErrorMailBody(JobExecutionContext context, Throwable throwable)
062    {
063        String cmsUrl = StringUtils.stripEnd(StringUtils.removeEndIgnoreCase(Config.getInstance().getValue("cms.url"), "index.html"), "/");
064        String url = cmsUrl + "/_admin/";
065        String error = ExceptionUtils.getStackTrace(throwable);
066        return new I18nizableText("plugin.web", "PLUGINS_WEB_BUILDALL_ERROR_MAIL_BODY", List.of(url, error));
067    }
068}