001/* 002 * Copyright 2010 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.cms.workflow; 017 018import java.util.Date; 019import java.util.Map; 020 021import org.ametys.cms.repository.WorkflowAwareContent; 022import org.ametys.plugins.repository.AmetysRepositoryException; 023 024import com.opensymphony.module.propertyset.PropertySet; 025import com.opensymphony.workflow.FunctionProvider; 026import com.opensymphony.workflow.WorkflowException; 027 028/** 029 * Function setting or removing the date at which the content was proposed for 030 * validation, i.e. put in a workflow step in which it's awaiting validation. 031 */ 032public class SetProposalDateContentFunction extends AbstractContentWorkflowComponent implements FunctionProvider 033{ 034 035 /** The "remove" parameter. */ 036 private static final String __REMOVE_PARAM = "remove"; 037 038 @Override 039 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 040 { 041 _logger.info("Performing content proposal for validation."); 042 043 // Retrieve current content 044 WorkflowAwareContent content = getContent(transientVars); 045 boolean remove = "true".equals(args.get(__REMOVE_PARAM)); 046 047 try 048 { 049 content.setProposalDate(remove ? null : new Date()); 050 content.saveChanges(); 051 } 052 catch (AmetysRepositoryException e) 053 { 054 throw new WorkflowException("Unable to set the proposal date on the content", e); 055 } 056 057 } 058 059}