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.plugins.pagesubscription.notifier;
017
018import java.io.IOException;
019import java.util.ArrayList;
020import java.util.List;
021
022import org.ametys.core.ui.mail.StandardMailBodyHelper;
023import org.ametys.core.user.User;
024import org.ametys.plugins.repository.activities.Activity;
025import org.ametys.plugins.repository.activities.ActivityType;
026import org.ametys.runtime.i18n.I18nizableText;
027import org.ametys.web.activities.PageDeletedActivityType;
028import org.ametys.web.repository.page.Page;
029
030/**
031 * Notifier for {@link PageDeletedActivityType}
032 */
033public class PageSubscriptionPageDeletedNotifier extends AbstractPageSubscriptionNotifier
034{
035    @Override
036    public boolean support(ActivityType activityType)
037    {
038        return activityType instanceof PageDeletedActivityType;
039    }
040    
041    public boolean isAsync()
042    {
043        return false;
044    }
045    
046    @Override
047    protected String getSiteParameterId()
048    {
049        return "page-subscription-page-deletion";
050    }
051    
052    @Override
053    protected I18nizableText _getMailSubject(Activity activity, Page page)
054    {
055        List<String> i18nparam = new ArrayList<>();
056        i18nparam.add(page.getSite().getTitle()); // {0}
057        i18nparam.add(page.getTitle()); // {1}
058        
059        return new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_DELETE_PAGE_SUBJECT", i18nparam);
060    }
061
062    @Override
063    protected String _getMailHtmlBody(Activity activity, Page page, User author) throws IOException
064    {
065        return StandardMailBodyHelper.newHTMLBody()
066                .withLanguage(page.getSitemapName())
067                .withTitle(new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_DELETE_PAGE_BODY_TITLE", List.of(page.getTitle())))
068                .withMessage(new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_DELETE_PAGE_BODY", List.of(author.getFullName(), page.getTitle(), page.getSite().getTitle())))
069                .build();
070    }
071}