001/* 002 * Copyright 2020 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.activities.projects; 017 018import java.util.List; 019import java.util.Map; 020import java.util.Objects; 021import java.util.stream.Collectors; 022 023import javax.jcr.RepositoryException; 024 025import org.apache.avalon.framework.service.ServiceException; 026import org.apache.avalon.framework.service.ServiceManager; 027 028import org.ametys.cms.ObservationConstants; 029import org.ametys.cms.repository.Content; 030import org.ametys.cms.tag.TagProviderExtensionPoint; 031import org.ametys.core.util.I18nUtils; 032import org.ametys.plugins.repository.activities.Activity; 033import org.ametys.plugins.repository.activities.ActivityType; 034import org.ametys.web.repository.content.WebContent; 035 036/** 037 * {@link ActivityType} implementation for news publication 038 */ 039public class NewsPublishedActivityType extends WebContentActivityType 040{ 041 /** data name for the content tags */ 042 public static final String CONTENT_TAGS = "contentTags"; 043 044 private TagProviderExtensionPoint _tagProviderExtPt; 045 private I18nUtils _i18nUtils; 046 047 @Override 048 public void service(ServiceManager serviceManager) throws ServiceException 049 { 050 super.service(serviceManager); 051 _tagProviderExtPt = (TagProviderExtensionPoint) serviceManager.lookup(TagProviderExtensionPoint.ROLE); 052 _i18nUtils = (I18nUtils) serviceManager.lookup(I18nUtils.ROLE); 053 } 054 055 @Override 056 public void setAdditionalActivityData(Activity activity, Map<String, Object> parameters) throws RepositoryException 057 { 058 super.setAdditionalActivityData(activity, parameters); 059 060 Content content = (Content) parameters.get(ObservationConstants.ARGS_CONTENT); 061 062 List<String> tags = content.getTags().stream() 063 .filter(s -> s.startsWith("WORKSPACES_TAG_")) 064 .map(s -> _tagProviderExtPt.getTag(s, Map.of("siteName", ((WebContent) content).getSiteName()))) 065 .filter(Objects::nonNull) 066 .map(t -> _i18nUtils.translate(t.getTitle(), content.getLanguage())) 067 .collect(Collectors.toList()); 068 069 activity.setValue(CONTENT_TAGS, tags.toArray(new String[tags.size()])); 070 } 071 072 @Override 073 public String getMailBodyURI(Activity activity) 074 { 075 return "cocoon://_plugins/workspaces/notification-mail-news-publication"; 076 } 077}