001/* 002 * Copyright 2024 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.comments; 017 018import java.util.List; 019import java.util.Map; 020 021import org.ametys.cms.repository.comment.Comment; 022import org.ametys.cms.repository.mentions.MentionUtils; 023import org.ametys.core.observation.Event; 024import org.ametys.plugins.workspaces.ObservationConstants; 025import org.ametys.plugins.workspaces.project.objects.Project; 026import org.ametys.plugins.workspaces.tasks.Task; 027import org.ametys.plugins.workspaces.tasks.TasksWorkspaceModule; 028import org.ametys.runtime.i18n.I18nizableText; 029/** 030 * Observer to send mails to mentioned users in contributor comments of {@link Task} 031 */ 032public class NotifyTaskCommentMentionsObserver extends AbstractNotifyWorkspacesCommentMentionsObserver<Task> 033{ 034 @Override 035 public boolean supports(Event event) 036 { 037 return event.getId().equals(ObservationConstants.EVENT_TASK_COMMENTED); 038 } 039 040 @Override 041 protected String _getAmetysObjectTitle(Task task) 042 { 043 return task.getLabel(); 044 } 045 046 @Override 047 protected MentionableObject _getMentionableObjectFromArguments(Map<String, Object> arguments) throws Exception 048 { 049 Task task = _getAmetysObjectFromArguments(arguments); 050 String commentId = (String) arguments.get(ObservationConstants.ARGS_TASK_COMMENT_ID); 051 Comment comment = task.getComment(commentId); 052 Project project = _projectManager.getParentProject(task); 053 054 String url = _getAbsoluteUrl(task, project); 055 056 return new MentionableObject( 057 _userManager.getUser(comment.getAuthor()), 058 comment.getContent(), 059 MentionUtils.extractMentionedUsersFromSimpleText(comment.getContent()), 060 comment.getCreationDate(), 061 task, 062 new LinkToAmetysObject(url, new I18nizableText("plugin.workspaces", "PROJECT_MAIL_NOTIFICATION_BODY_TASK_BUTTON_TEXT")), 063 _getLanguage(project) 064 ); 065 } 066 067 @Override 068 protected I18nizableText _getMailMessage(MentionableObject mentionableObject) 069 { 070 List<String> i18nParams = _getCommonMailI18nParameters(mentionableObject); 071 return new I18nizableText("plugin.workspaces", "PLUGINS_WORKSPACES_TASK_MENTION_MAIL_MESSAGE", i18nParams); 072 } 073 074 @Override 075 protected String _getModuleId() 076 { 077 return TasksWorkspaceModule.TASK_MODULE_ID; 078 } 079 080 @Override 081 protected String getUrl(Task task, Project project) 082 { 083 return _taskModule.getTaskUri(project, task.getId()); 084 } 085}