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;
019import java.util.List;
020import java.util.Map;
021
022import javax.jcr.Node;
023
024import org.ametys.cms.content.references.OutgoingReferences;
025import org.ametys.cms.repository.comment.Comment;
026import org.ametys.cms.repository.comment.CommentableContent;
027import org.ametys.cms.tag.jcr.TaggableAmetysObjectHelper;
028import org.ametys.core.user.UserIdentity;
029import org.ametys.plugins.repository.AmetysRepositoryException;
030import org.ametys.plugins.repository.RepositoryIntegrityViolationException;
031import org.ametys.plugins.repository.jcr.DublinCoreHelper;
032import org.ametys.plugins.repository.lock.LockableAmetysObject;
033import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObjectHelper;
034
035/**
036 * Default implementation of a {@link Content}, also versionable, lockable and workflow-aware.
037 * @param <F> the actual type of factory.
038 */
039public class ModifiableDefaultContent<F extends ModifiableContentFactory> extends DefaultContent<F> implements CommentableContent, LockableAmetysObject, ModifiableWorkflowAwareContent/*, AnnotableContent*/ //, CopiableAmetysObject
040{
041    /**
042     * Creates a JCR-based Content.
043     * @param node the JCR Node backing this Content.
044     * @param parentPath the parent path in the Ametys hierarchy.
045     * @param factory the corresponding {@link ContentFactory}.
046     */
047    public ModifiableDefaultContent(Node node, String parentPath, F factory)
048    {
049        super(node, parentPath, factory);
050    }
051
052    public void setTypes(String[] types) throws AmetysRepositoryException
053    {
054        ModifiableContentHelper.setTypes(this, types);
055    }
056    
057    public void setMixinTypes(String[] mixins) throws AmetysRepositoryException
058    {
059        ModifiableContentHelper.setMixinTypes(this, mixins);
060    }
061    
062    public void setLanguage(String language) throws AmetysRepositoryException
063    {
064        ModifiableContentHelper.setLanguage(this, language);
065    }
066    
067    public void setTitle(String title) throws AmetysRepositoryException
068    {
069        ModifiableContentHelper.setTitle(this, title);
070    }
071    
072    public void setCreator(UserIdentity user) throws AmetysRepositoryException
073    {
074        ModifiableContentHelper.setCreator(this, user);
075    }
076    
077    public void setCreationDate(Date creationDate) throws AmetysRepositoryException
078    {
079        ModifiableContentHelper.setCreationDate(this, creationDate);
080    }
081    
082    public void setLastContributor(UserIdentity user)
083    {
084        ModifiableContentHelper.setLastContributor(this, user);
085    }
086    
087    public void setLastModified(Date lastModified) throws AmetysRepositoryException
088    {
089        ModifiableContentHelper.setLastModified(this, lastModified);
090    }
091    
092    @Override
093    public void setLastValidationDate(Date validationDate) throws AmetysRepositoryException
094    {
095        ModifiableContentHelper.setLastValidationDate(this, validationDate);
096    }
097    
098    @Override
099    public void setLastMajorValidationDate(Date validationDate) throws AmetysRepositoryException
100    {
101        ModifiableContentHelper.setLastMajorValidationDate(this, validationDate);
102    }
103    
104    @Override
105    public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException
106    {
107        ModifiableContentHelper.setOutgoingReferences(this, references);
108    }
109    
110    // ------------------- Tags management -------------------- //
111    @Override
112    public void tag(String tag) throws AmetysRepositoryException
113    {
114        TaggableAmetysObjectHelper.tag(this, tag);
115    }
116    
117    @Override
118    public void untag(String tag) throws AmetysRepositoryException
119    {
120        TaggableAmetysObjectHelper.untag(this, tag);
121    }
122    
123    // ------------------- Workflow management -------------------- //
124    @Override
125    public long getWorkflowId() throws AmetysRepositoryException
126    {
127        return WorkflowAwareContentHelper.getWorkflowId(this);
128    }
129    
130    @Override
131    public void setWorkflowId(long workflowId) throws AmetysRepositoryException
132    {
133        WorkflowAwareContentHelper.setWorkflowId(this, workflowId);
134    }
135    
136    @Override
137    public long getCurrentStepId() throws AmetysRepositoryException
138    {
139        return WorkflowAwareContentHelper.getCurrentStepId(this);
140    }
141    
142    @Override
143    public void setCurrentStepId (long stepId) throws AmetysRepositoryException
144    {
145        WorkflowAwareContentHelper.setCurrentStepId(this, stepId);
146    }
147    
148    @Override
149    public Date getProposalDate() throws AmetysRepositoryException
150    {
151        return WorkflowAwareContentHelper.getProposalDate(this);
152    }
153    
154    @Override
155    public void setProposalDate(Date proposalDate) throws AmetysRepositoryException
156    {
157        WorkflowAwareContentHelper.setProposalDate(this, proposalDate);
158    }
159    
160    @Override
161    public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException
162    {
163        MetadataAwareAmetysObjectHelper.removeSubObjects(this);
164        
165        super.remove();
166    }
167    
168    // --------------------- Lock management ----------------------- //
169    @Override
170    public void lock() throws AmetysRepositoryException
171    {
172        _getFactory().getLockComponent().lock(this);
173    }
174    
175    @Override
176    public void unlock() throws AmetysRepositoryException
177    {
178        _getFactory().getLockComponent().unlock(this);
179    }
180    
181    @Override
182    public boolean isLocked() throws AmetysRepositoryException
183    {
184        return _getFactory().getLockComponent().isLocked(this);
185    }
186    
187    @Override
188    public UserIdentity getLockOwner() throws AmetysRepositoryException
189    {
190        return _getFactory().getLockComponent().getLockOwner(this);
191    }
192    
193    // -------------------------- DUBLIN CORE ---------------------------- //
194    @Override
195    public void setDCTitle(String title) throws AmetysRepositoryException
196    {
197        DublinCoreHelper.setDCTitle(this, title);
198    }
199
200    @Override
201    public void setDCCreator(String creator) throws AmetysRepositoryException
202    {
203        DublinCoreHelper.setDCCreator(this, creator);
204    }
205
206    @Override
207    public void setDCSubject(String[] subject) throws AmetysRepositoryException
208    {
209        DublinCoreHelper.setDCSubject(this, subject);
210    }
211
212    @Override
213    public void setDCDescription(String description) throws AmetysRepositoryException
214    {
215        DublinCoreHelper.setDCDescription(this, description);
216    }
217
218    @Override
219    public void setDCPublisher(String publisher) throws AmetysRepositoryException
220    {
221        DublinCoreHelper.setDCPublisher(this, publisher);
222    }
223
224    @Override
225    public void setDCContributor(String contributor) throws AmetysRepositoryException
226    {
227        DublinCoreHelper.setDCContributor(this, contributor);
228    }
229
230    @Override
231    public void setDCDate(Date date) throws AmetysRepositoryException
232    {
233        DublinCoreHelper.setDCDate(this, date);
234    }
235
236    @Override
237    public void setDCType(String type) throws AmetysRepositoryException
238    {
239        DublinCoreHelper.setDCType(this, type);
240    }
241
242    @Override
243    public void setDCFormat(String format) throws AmetysRepositoryException
244    {
245        DublinCoreHelper.setDCFormat(this, format);
246    }
247
248    @Override
249    public void setDCIdentifier(String identifier) throws AmetysRepositoryException
250    {
251        DublinCoreHelper.setDCIdentifier(this, identifier);
252    }
253
254    @Override
255    public void setDCSource(String source) throws AmetysRepositoryException
256    {
257        DublinCoreHelper.setDCSource(this, source);
258    }
259
260    @Override
261    public void setDCLanguage(String language) throws AmetysRepositoryException
262    {
263        DublinCoreHelper.setDCLanguage(this, language);
264    }
265
266    @Override
267    public void setDCRelation(String relation) throws AmetysRepositoryException
268    {
269        DublinCoreHelper.setDCRelation(this, relation);
270    }
271    
272    @Override
273    public void setDCCoverage(String coverage) throws AmetysRepositoryException
274    {
275        DublinCoreHelper.setDCCoverage(this, coverage);
276    }
277    
278    @Override
279    public void setDCRights(String rights) throws AmetysRepositoryException
280    {
281        DublinCoreHelper.setDCRights(this, rights);
282    }
283    
284    // ---------------------------- COMMENTS ------------------------------ //
285    @Override
286    public Comment createComment()
287    {
288        return new Comment(this.getUnversionedMetadataHolder());
289    }
290    
291    @Override
292    public Comment getComment(String commentId) throws AmetysRepositoryException
293    {
294        return Comment.getComment(this.getUnversionedMetadataHolder(), commentId);
295    }
296    
297    @Override
298    public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException
299    {
300        return Comment.getComments(this.getUnversionedMetadataHolder(), includeNotValidatedComments, includeValidatedComments);
301    }
302    
303}