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.documents.DocumentWorkspaceModule; 026import org.ametys.plugins.workspaces.documents.jcr.File; 027import org.ametys.plugins.workspaces.project.objects.Project; 028import org.ametys.runtime.i18n.I18nizableText; 029/** 030 * Observer to send mails to mentioned users in contributor comments of {@link File} 031 */ 032public class NotifyFileCommentMentionsObserver extends AbstractNotifyWorkspacesCommentMentionsObserver<File> 033{ 034 @Override 035 public boolean supports(Event event) 036 { 037 return event.getId().equals(ObservationConstants.EVENT_RESOURCE_COMMENTED); 038 } 039 040 @Override 041 protected MentionableObject _getMentionableObjectFromArguments(Map<String, Object> arguments) throws Exception 042 { 043 File file = _getAmetysObjectFromArguments(arguments); 044 String commentId = (String) arguments.get(ObservationConstants.ARGS_FILE_COMMENT_ID); 045 Comment comment = file.getComment(commentId); 046 Project project = _projectManager.getParentProject(file); 047 String url = _getAbsoluteUrl(file, project); 048 049 return new MentionableObject( 050 _userManager.getUser(comment.getAuthor()), 051 comment.getContent(), 052 MentionUtils.extractMentionedUsersFromSimpleText(comment.getContent()), 053 comment.getCreationDate(), 054 file, 055 new LinkToAmetysObject(url, new I18nizableText("plugin.workspaces", "PROJECT_MAIL_NOTIFICATION_BODY_DEFAULT_BUTTON_TEXT")), 056 _getLanguage(project) 057 ); 058 } 059 060 @Override 061 protected String _getAmetysObjectTitle(File file) 062 { 063 return file.getName(); 064 } 065 066 @Override 067 protected I18nizableText _getMailMessage(MentionableObject mentionableObject) 068 { 069 List<String> i18nParams = _getCommonMailI18nParameters(mentionableObject); 070 return new I18nizableText("plugin.workspaces", "PLUGINS_WORKSPACES_RESOURCE_MENTION_MAIL_MESSAGE", i18nParams); 071 } 072 073 @Override 074 protected String _getModuleId() 075 { 076 return DocumentWorkspaceModule.DOCUMENT_MODULE_ID; 077 } 078 079 @Override 080 protected String getUrl(File ametysObject, Project project) 081 { 082 return _documentModule.getModuleUrl(project); 083 } 084}