001/*
002 *  Copyright 2012 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.repository;
017
018import java.util.Date;
019
020import javax.jcr.Node;
021
022import org.ametys.plugins.repository.AmetysRepositoryException;
023import org.ametys.plugins.repository.RepositoryIntegrityViolationException;
024import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObjectHelper;
025
026/**
027 * Default implementation of a {@link Content}, also versionable, lockable and workflow-aware.
028 * @param <F> the actual type of factory.
029 */
030public class DefaultWorkflowAwareContent<F extends DefaultWorkflowAwareContentFactory> extends DefaultContent<F> implements WorkflowAwareContent
031{
032    /**
033     * Creates a JCR-based Content.
034     * @param node the JCR Node backing this Content.
035     * @param parentPath the parent path in the Ametys hierarchy.
036     * @param factory the corresponding {@link ContentFactory}.
037     */
038    public DefaultWorkflowAwareContent(Node node, String parentPath, F factory)
039    {
040        super(node, parentPath, factory);
041    }
042    
043    @Override
044    public long getWorkflowId() throws AmetysRepositoryException
045    {
046        return WorkflowAwareContentHelper.getWorkflowId(this);
047    }
048    
049    @Override
050    public void setWorkflowId(long workflowId) throws AmetysRepositoryException
051    {
052        WorkflowAwareContentHelper.setWorkflowId(this, workflowId);
053    }
054    
055    @Override
056    public long getCurrentStepId() throws AmetysRepositoryException
057    {
058        return WorkflowAwareContentHelper.getCurrentStepId(this);
059    }
060    
061    @Override
062    public void setCurrentStepId (long stepId) throws AmetysRepositoryException
063    {
064        WorkflowAwareContentHelper.setCurrentStepId(this, stepId);
065    }
066    
067    @Override
068    public Date getProposalDate() throws AmetysRepositoryException
069    {
070        return WorkflowAwareContentHelper.getProposalDate(this);
071    }
072    
073    @Override
074    public void setProposalDate(Date proposalDate) throws AmetysRepositoryException
075    {
076        WorkflowAwareContentHelper.setProposalDate(this, proposalDate);
077    }
078    
079    @Override
080    public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException
081    {
082        MetadataAwareAmetysObjectHelper.removeSubObjects(this);
083        
084        super.remove();
085    }
086    
087}