001/* 002 * Copyright 2022 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.forms.workflow; 017 018import java.util.List; 019import java.util.Map; 020 021import org.apache.avalon.framework.component.Component; 022import org.apache.avalon.framework.logger.AbstractLogEnabled; 023import org.apache.avalon.framework.service.ServiceException; 024import org.apache.avalon.framework.service.ServiceManager; 025import org.apache.avalon.framework.service.Serviceable; 026import org.apache.commons.collections.ListUtils; 027 028import org.ametys.cms.workflow.AmetysObjectCheckRightsCondition; 029import org.ametys.plugins.forms.helper.LimitedEntriesHelper; 030import org.ametys.plugins.forms.repository.FormEntry; 031import org.ametys.plugins.workflow.EnhancedFunction; 032import org.ametys.runtime.i18n.I18nizableText; 033 034import com.opensymphony.module.propertyset.PropertySet; 035import com.opensymphony.workflow.WorkflowException; 036 037/** 038 * OS workflow function to deactive the entry 039 */ 040public class DeactiveEntryFunction extends AbstractLogEnabled implements Component, EnhancedFunction, Serviceable 041{ 042 /** The handling limited entries helper */ 043 protected LimitedEntriesHelper _handleLimitedEntriesHelper; 044 045 public void service(ServiceManager manager) throws ServiceException 046 { 047 _handleLimitedEntriesHelper = (LimitedEntriesHelper) manager.lookup(LimitedEntriesHelper.ROLE); 048 } 049 050 @Override 051 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 052 { 053 FormEntry entryRefused = (FormEntry) transientVars.get(AmetysObjectCheckRightsCondition.AMETYS_OBJECT_KEY); 054 _handleLimitedEntriesHelper.deactivateEntry(entryRefused.getId()); 055 } 056 057 @Override 058 public List<FunctionArgument> getArguments() 059 { 060 return ListUtils.EMPTY_LIST; 061 } 062 063 @Override 064 public I18nizableText getDescription(Map<String, String> argumentsValues) 065 { 066 return new I18nizableText("plugin.forms", "PLUGINS_FORMS_DEACTIVE_ENTRY_FUNCTION_DESCRIPTION"); 067 } 068}