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.web.workflow; 017 018import java.util.Map; 019 020import javax.jcr.RepositoryException; 021 022import org.ametys.cms.repository.ModifiableContent; 023import org.ametys.cms.repository.WorkflowAwareContent; 024import org.ametys.cms.workflow.AbstractContentWorkflowComponent; 025import org.ametys.plugins.repository.AmetysRepositoryException; 026 027import com.opensymphony.module.propertyset.PropertySet; 028import com.opensymphony.workflow.FunctionProvider; 029import com.opensymphony.workflow.WorkflowException; 030 031/** 032 * OSWorkflow function for deleting a content. 033 */ 034public class DeleteContentFunction extends AbstractContentWorkflowComponent implements FunctionProvider 035{ 036 @Override 037 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 038 { 039 _logger.info("Performing content deletion"); 040 041 try 042 { 043 WorkflowAwareContent content = getContent(transientVars); 044 if (!(content instanceof ModifiableContent)) 045 { 046 throw new IllegalArgumentException("The provided content " + content.getId() + " is not a ModifiableWorkflowAwareContent."); 047 } 048 049 _removeContent((ModifiableContent) content); 050 } 051 catch (RepositoryException e) 052 { 053 throw new WorkflowException("Unable to link the workflow to the content", e); 054 } 055 catch (AmetysRepositoryException e) 056 { 057 throw new WorkflowException("Unable to delete the content", e); 058 } 059 } 060 061 /** 062 * Deletes the content. 063 * @param content the content. 064 * @throws WorkflowException if an error occurs. 065 * @throws RepositoryException if an error occurs. 066 */ 067 protected void _removeContent(ModifiableContent content) throws WorkflowException, RepositoryException 068 { 069 content.remove(); 070 content.saveChanges(); 071 } 072}