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.time.ZonedDateTime;
019import java.util.Date;
020import java.util.List;
021import java.util.Locale;
022import java.util.Map;
023
024import javax.jcr.Node;
025
026import org.ametys.cms.content.references.OutgoingReferences;
027import org.ametys.cms.repository.comment.Comment;
028import org.ametys.cms.repository.comment.CommentableContent;
029import org.ametys.core.user.UserIdentity;
030import org.ametys.plugins.repository.AmetysRepositoryException;
031import org.ametys.plugins.repository.RepositoryIntegrityViolationException;
032import org.ametys.plugins.repository.data.extractor.xml.XMLValuesExtractorAdditionalDataGetter;
033import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData;
034import org.ametys.plugins.repository.jcr.DublinCoreHelper;
035import org.ametys.plugins.repository.lock.LockableAmetysObject;
036import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObjectHelper;
037import org.ametys.plugins.repository.tag.TaggableAmetysObjectHelper;
038
039/**
040 * Default implementation of a {@link Content}, also versionable, lockable and workflow-aware.
041 * @param <F> the actual type of factory.
042 */
043public class ModifiableDefaultContent<F extends ModifiableContentFactory> extends DefaultContent<F> implements CommentableContent, LockableAmetysObject, ModifiableWorkflowAwareContent/*, AnnotableContent*/ //, CopiableAmetysObject
044{
045    /**
046     * Creates a JCR-based Content.
047     * @param node the JCR Node backing this Content.
048     * @param parentPath the parent path in the Ametys hierarchy.
049     * @param factory the corresponding {@link ContentFactory}.
050     */
051    public ModifiableDefaultContent(Node node, String parentPath, F factory)
052    {
053        super(node, parentPath, factory);
054    }
055
056    public void setTitle(String title, Locale locale) throws AmetysRepositoryException
057    {
058        _getFactory()._getModifiableContentHelper().setTitle(this, title, locale);
059    }
060    
061    public void setTitle(String title) throws AmetysRepositoryException
062    {
063        _getFactory()._getModifiableContentHelper().setTitle(this, title);
064    }
065    
066    public void setCreator(UserIdentity user) throws AmetysRepositoryException
067    {
068        _getFactory()._getModifiableContentHelper().setCreator(this, user);
069    }
070    
071    public void setCreationDate(Date creationDate) throws AmetysRepositoryException
072    {
073        _getFactory()._getModifiableContentHelper().setCreationDate(this, creationDate);
074    }
075    
076    public void setLastContributor(UserIdentity user)
077    {
078        _getFactory()._getModifiableContentHelper().setLastContributor(this, user);
079    }
080    
081    public void setLastModified(Date lastModified) throws AmetysRepositoryException
082    {
083        _getFactory()._getModifiableContentHelper().setLastModified(this, lastModified);
084    }
085    
086    @Override
087    public void setFirstValidationDate(Date validationDate) throws AmetysRepositoryException
088    {
089        _getFactory()._getModifiableContentHelper().setFirstValidationDate(this, validationDate);
090    }
091    
092    @Override
093    public void setLastValidationDate(Date validationDate) throws AmetysRepositoryException
094    {
095        _getFactory()._getModifiableContentHelper().setLastValidationDate(this, validationDate);
096    }
097    
098    @Override
099    public void setLastMajorValidationDate(Date validationDate) throws AmetysRepositoryException
100    {
101        _getFactory()._getModifiableContentHelper().setLastMajorValidationDate(this, validationDate);
102    }
103    
104    @Override
105    public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException
106    {
107        _getFactory()._getModifiableContentHelper().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 ZonedDateTime getProposalDate() throws AmetysRepositoryException
150    {
151        return WorkflowAwareContentHelper.getProposalDate(this);
152    }
153    
154    @Override
155    public void setProposalDate(ZonedDateTime 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.getUnversionedDataHolder());
289    }
290    
291    public Comment createComment(String commentId, ZonedDateTime creationDate)
292    {
293        return new Comment(this.getUnversionedDataHolder(), commentId, creationDate);
294    }
295    
296    @Override
297    public Comment getComment(String commentId) throws AmetysRepositoryException
298    {
299        return Comment.getComment(this.getUnversionedDataHolder(), commentId);
300    }
301    
302    @Override
303    public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException
304    {
305        return Comment.getComments(this.getUnversionedDataHolder(), includeNotValidatedComments, includeValidatedComments);
306    }
307
308    // ---------------------------- DATA HOLDER --------------------------- //
309    @Override
310    public ModifiableContentDataHolder getDataHolder()
311    {
312        return new ModifiableContentDataHolder(this, _getFactory().getContentDataHelper(), new JCRRepositoryData(getNode()), _getFactory().getContentHelper().getContentTypes(this));
313    }
314    
315    public void fillContent(org.w3c.dom.Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception
316    {
317        _getFactory().getContentExtractor().fillContent(this, node, additionalDataGetter);
318    }
319}