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