001/* 002 * Copyright 2015 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.workspaces.project.notification; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.apache.commons.lang.StringUtils; 022 023import org.ametys.core.observation.Event; 024import org.ametys.plugins.explorer.ObservationConstants; 025import org.ametys.plugins.explorer.threads.jcr.JCRPost; 026import org.ametys.plugins.explorer.threads.jcr.JCRThread; 027import org.ametys.plugins.repository.AmetysObject; 028import org.ametys.plugins.workspaces.project.objects.Project; 029import org.ametys.runtime.i18n.I18nizableText; 030 031/** 032 * This component is used to send mail notification 033 * 034 */ 035public class ThreadsMailNotifierObserver extends AbstractSendNotificationObserver 036{ 037 @Override 038 public boolean supports(Event event) 039 { 040 return event.getId().equals(ObservationConstants.EVENT_THREAD_POST_CREATED); 041 } 042 043 @Override 044 protected String getRightIdForNotify() 045 { 046 return "Plugins_Projects_Thread_Mail_Notification"; 047 } 048 049 @Override 050 protected AmetysObject getEventAmetysObject(Event event) 051 { 052 JCRPost post = (JCRPost) event.getArguments().get(ObservationConstants.ARGS_POST); 053 return post.getParent(); 054 } 055 056 @Override 057 protected String getMailBodyURI(Event event, Project project) 058 { 059 return "cocoon://_plugins/workspaces/notification-mail-thread"; 060 } 061 062 @Override 063 protected I18nizableText getI18nSubject(Event event, Project project) 064 { 065 String mailSubjecti18nKey = "PROJECT_MAIL_NOTIFICATION_SUBJECT_" + StringUtils.replaceChars(event.getId().toUpperCase(), '.', '_'); 066 List<String> mailSubjectParams = new ArrayList<>(); 067 mailSubjectParams.add(project.getTitle()); 068 mailSubjectParams.add(((JCRThread) getEventAmetysObject(event)).getTitle()); 069 return new I18nizableText("plugin." + _pluginName, mailSubjecti18nKey, mailSubjectParams); 070 } 071}