001/* 002 * Copyright 2017 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.observer; 017 018import java.util.ArrayList; 019import java.util.Collection; 020import java.util.Collections; 021import java.util.List; 022import java.util.Map; 023 024import org.ametys.core.observation.Event; 025import org.ametys.runtime.i18n.I18nizableText; 026import org.ametys.web.repository.page.Page; 027 028/** 029 * Listen page deleted and send mail 030 */ 031public class PageSubscriptionDeletePageObserver extends AbstractPageSubscriptionObserver 032{ 033 @Override 034 public boolean supports(Event event) 035 { 036 String eventType = event.getId(); 037 return eventType.equals(org.ametys.web.ObservationConstants.EVENT_PAGE_DELETING); 038 } 039 040 @Override 041 protected String getSiteParameterId() 042 { 043 return "page-subscription-page-deletion"; 044 } 045 046 @Override 047 protected String _getMailSubject(Event event, Page page) 048 { 049 List<String> i18nparam = new ArrayList<>(); 050 i18nparam.add(page.getSite().getTitle()); // {0} 051 i18nparam.add(page.getTitle()); // {1} 052 053 String i18nKey = null; 054 i18nKey = "PLUGINS_PAGE_SUBSCRIBE_SEND_MAIL_DELETE_PAGE_TITLE"; 055 056 I18nizableText i18nSubject = new I18nizableText("plugin.page-subscription", i18nKey, i18nparam); 057 return _i18nUtils.translate(i18nSubject); 058 } 059 060 @Override 061 protected String _getMailBody(Event event, Page page) 062 { 063 List<String> i18nparam = new ArrayList<>(); 064 065 i18nparam.add(_getAbsolutePageUrl(page)); // {0} 066 i18nparam.add(page.getTitle()); // {1} 067 i18nparam.add(page.getSite().getTitle()); // {2} 068 i18nparam.add(_userManager.getUser(event.getIssuer()).getFullName()); // {3} 069 070 I18nizableText i18nTextBody = null; 071 i18nTextBody = new I18nizableText("plugin.page-subscription", "PLUGINS_PAGE_SUBSCRIBE_SEND_MAIL_DELETE_PAGE_TEXT_BODY", i18nparam); 072 073 return _i18nUtils.translate(i18nTextBody); 074 } 075 076 @Override 077 protected Collection<Page> _getPages(Event event) 078 { 079 Map<String, Object> args = event.getArguments(); 080 String pageId = (String) args.get(org.ametys.web.ObservationConstants.ARGS_PAGE_ID); 081 082 return Collections.singletonList(_resolver.resolveById(pageId)); 083 } 084}