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