001/* 002 * Copyright 2026 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; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022 023import org.ametys.cms.ObservationConstants; 024import org.ametys.cms.contenttype.ContentTypesHelper; 025import org.ametys.cms.repository.Content; 026import org.ametys.core.observation.Event; 027import org.ametys.plugins.workspaces.WorkspacesConstants; 028 029/** 030 * Observer to notify comment authors when a comment is created or updated, except for workspaces content types. 031 */ 032public class NotifyCommentAuthorWhenReplyingObserver extends org.ametys.web.repository.comment.NotifyCommentAuthorWhenReplyingObserver 033{ 034 private static final List<String> __EXCLUDED_CONTENT_TYPES = List.of(WorkspacesConstants.WALL_CONTENT_CONTENT_TYPE_ID, 035 WorkspacesConstants.PROJECT_NEWS_CONTENT_TYPE_ID, 036 WorkspacesConstants.PROJECT_ALERT_CONTENT_TYPE_ID, 037 WorkspacesConstants.PROJECT_ARTICLE_CONTENT_TYPE, 038 WorkspacesConstants.CATALOG_NEWS_CONTENT_TYPE_ID, 039 WorkspacesConstants.ABOUT_CONTENT_TYPE); 040 041 private ContentTypesHelper _contentTypesHelper; 042 043 @Override 044 public void service(ServiceManager smanager) throws ServiceException 045 { 046 super.service(smanager); 047 _contentTypesHelper = (ContentTypesHelper) smanager.lookup(ContentTypesHelper.ROLE); 048 } 049 050 @Override 051 public boolean supports(Event event) 052 { 053 if (super.supports(event)) 054 { 055 Content content = (Content) event.getArguments().get(ObservationConstants.ARGS_CONTENT); 056 057 boolean isExcludedContentType = __EXCLUDED_CONTENT_TYPES.stream() 058 .filter(excludedContentType -> _contentTypesHelper.isInstanceOf(content, excludedContentType)) 059 .findAny() 060 .isPresent(); 061 062 return !isExcludedContentType; 063 } 064 return false; 065 } 066 067}