001/* 002 * Copyright 2018 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.odf.workflow.copy; 017 018import java.util.HashMap; 019import java.util.List; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.commons.collections.ListUtils; 025 026import org.ametys.cms.ObservationConstants; 027import org.ametys.cms.repository.WorkflowAwareContent; 028import org.ametys.cms.workflow.AbstractContentWorkflowComponent; 029import org.ametys.core.observation.Event; 030import org.ametys.core.observation.ObservationManager; 031import org.ametys.core.user.CurrentUserProvider; 032import org.ametys.core.user.UserIdentity; 033import org.ametys.plugins.workflow.EnhancedFunction; 034import org.ametys.runtime.i18n.I18nizableText; 035 036import com.opensymphony.module.propertyset.PropertySet; 037import com.opensymphony.workflow.WorkflowException; 038 039/** 040 * OS Workflow function to notify that the copy has ended. 041 */ 042public class NotifyCopyFunction extends AbstractContentWorkflowComponent implements EnhancedFunction 043{ 044 /** The observation manager */ 045 protected ObservationManager _observationManager; 046 047 /** The user provider */ 048 protected CurrentUserProvider _userProvider; 049 050 @Override 051 public void service(ServiceManager manager) throws ServiceException 052 { 053 super.service(manager); 054 _observationManager = (ObservationManager) manager.lookup(ObservationManager.ROLE); 055 _userProvider = (CurrentUserProvider) manager.lookup(CurrentUserProvider.ROLE); 056 } 057 058 @Override 059 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 060 { 061 UserIdentity currentUserIdentity = _userProvider.getUser(); 062 WorkflowAwareContent content = getContent(transientVars); 063 064 Map<String, Object> eventParams = new HashMap<>(); 065 eventParams.put(ObservationConstants.ARGS_CONTENT, content); 066 eventParams.put(ObservationConstants.ARGS_CONTENT_ID, content.getId()); 067 _observationManager.notify(new Event(ObservationConstants.EVENT_CONTENT_MODIFIED, currentUserIdentity, eventParams)); 068 } 069 070 @Override 071 public List<FunctionArgument> getArguments() 072 { 073 return ListUtils.EMPTY_LIST; 074 } 075 076 @Override 077 public I18nizableText getDescription(Map<String, String> argumentsValues) 078 { 079 return new I18nizableText("plugin.odf", "PLUGINS_ODF_NOTIFY_COPY_FUNCTION_DESCRIPTION"); 080 } 081}