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.PageUpdatedActivityType;
028import org.ametys.web.repository.page.Page;
029
030/**
031 * Notifier for {@link PageUpdatedActivityType}
032 */
033public class PageSubscriptionPageUpdatedNotifier extends AbstractPageSubscriptionNotifier
034{
035    @Override
036    public boolean support(ActivityType activityType)
037    {
038        return activityType instanceof PageUpdatedActivityType;
039    }
040    
041    @Override
042    protected String getSiteParameterId()
043    {
044        return "page-subscription-content-validation";
045    }
046    
047    @Override
048    protected I18nizableText _getMailSubject(Activity activity, Page page)
049    {
050        List<String> i18nparam = new ArrayList<>();
051        i18nparam.add(page.getSite().getTitle()); // {0}
052        i18nparam.add(page.getTitle()); // {1}
053
054        return new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_UPDATE_PAGE_SUBJECT", i18nparam);
055    }
056    
057    @Override
058    protected String _getMailHtmlBody(Activity activity, Page page, User author) throws IOException
059    {
060        String pageUrl = _getAbsolutePageUrl(page);
061        return StandardMailBodyHelper.newHTMLBody()
062                .withLanguage(page.getSitemapName())
063                .withTitle(new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_UPDATE_PAGE_BODY_TITLE", List.of(page.getTitle())))
064                .addMessage(new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_UPDATE_PAGE_BODY", List.of(author.getFullName(), page.getTitle(), page.getSite().getTitle())))
065                .addMessage(new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_PAGE_LINK", List.of(pageUrl)))
066                .withLink(pageUrl, new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_NOTIFICATION_MAIL_PAGE_LINK_TITLE"))
067                .build();
068    }
069}