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(ZonedDateTime 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(ZonedDateTime lastModified) throws AmetysRepositoryException
082    {
083        _getFactory()._getModifiableContentHelper().setLastModified(this, lastModified);
084    }
085    
086    public void setFirstValidator(UserIdentity user) throws AmetysRepositoryException
087    {
088        _getFactory()._getModifiableContentHelper().setFirstValidator(this, user);
089    }
090    
091    @Override
092    public void setFirstValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException
093    {
094        _getFactory()._getModifiableContentHelper().setFirstValidationDate(this, validationDate);
095    }
096    
097    public void setLastValidator(UserIdentity user) throws AmetysRepositoryException
098    {
099        _getFactory()._getModifiableContentHelper().setLastValidator(this, user);
100    }
101    
102    @Override
103    public void setLastValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException
104    {
105        _getFactory()._getModifiableContentHelper().setLastValidationDate(this, validationDate);
106    }
107    
108    public void setLastMajorValidator(UserIdentity user) throws AmetysRepositoryException
109    {
110        _getFactory()._getModifiableContentHelper().setLastMajorValidator(this, user);
111    }
112    
113    @Override
114    public void setLastMajorValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException
115    {
116        _getFactory()._getModifiableContentHelper().setLastMajorValidationDate(this, validationDate);
117    }
118    
119    @Override
120    public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException
121    {
122        _getFactory()._getModifiableContentHelper().setOutgoingReferences(this, references);
123    }
124    
125    // ------------------- Tags management -------------------- //
126    @Override
127    public void tag(String tag) throws AmetysRepositoryException
128    {
129        TaggableAmetysObjectHelper.tag(this, tag);
130    }
131    
132    @Override
133    public void untag(String tag) throws AmetysRepositoryException
134    {
135        TaggableAmetysObjectHelper.untag(this, tag);
136    }
137    
138    // ------------------- Workflow management -------------------- //
139    @Override
140    public long getWorkflowId() throws AmetysRepositoryException
141    {
142        return WorkflowAwareContentHelper.getWorkflowId(this);
143    }
144    
145    @Override
146    public void setWorkflowId(long workflowId) throws AmetysRepositoryException
147    {
148        WorkflowAwareContentHelper.setWorkflowId(this, workflowId);
149    }
150    
151    @Override
152    public long getCurrentStepId() throws AmetysRepositoryException
153    {
154        return WorkflowAwareContentHelper.getCurrentStepId(this);
155    }
156    
157    @Override
158    public void setCurrentStepId (long stepId) throws AmetysRepositoryException
159    {
160        WorkflowAwareContentHelper.setCurrentStepId(this, stepId);
161    }
162    
163    @Override
164    public ZonedDateTime getProposalDate() throws AmetysRepositoryException
165    {
166        return WorkflowAwareContentHelper.getProposalDate(this);
167    }
168    
169    @Override
170    public void setProposalDate(ZonedDateTime proposalDate) throws AmetysRepositoryException
171    {
172        WorkflowAwareContentHelper.setProposalDate(this, proposalDate);
173    }
174    
175    @Override
176    public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException
177    {
178        MetadataAwareAmetysObjectHelper.removeSubObjects(this);
179        
180        super.remove();
181    }
182    
183    // --------------------- Lock management ----------------------- //
184    @Override
185    public void lock() throws AmetysRepositoryException
186    {
187        _getFactory().getLockComponent().lock(this);
188    }
189    
190    @Override
191    public void unlock() throws AmetysRepositoryException
192    {
193        _getFactory().getLockComponent().unlock(this);
194    }
195    
196    @Override
197    public boolean isLocked() throws AmetysRepositoryException
198    {
199        return _getFactory().getLockComponent().isLocked(this);
200    }
201    
202    @Override
203    public UserIdentity getLockOwner() throws AmetysRepositoryException
204    {
205        return _getFactory().getLockComponent().getLockOwner(this);
206    }
207    
208    // -------------------------- DUBLIN CORE ---------------------------- //
209    @Override
210    public void setDCTitle(String title) throws AmetysRepositoryException
211    {
212        DublinCoreHelper.setDCTitle(this, title);
213    }
214
215    @Override
216    public void setDCCreator(String creator) throws AmetysRepositoryException
217    {
218        DublinCoreHelper.setDCCreator(this, creator);
219    }
220
221    @Override
222    public void setDCSubject(String[] subject) throws AmetysRepositoryException
223    {
224        DublinCoreHelper.setDCSubject(this, subject);
225    }
226
227    @Override
228    public void setDCDescription(String description) throws AmetysRepositoryException
229    {
230        DublinCoreHelper.setDCDescription(this, description);
231    }
232
233    @Override
234    public void setDCPublisher(String publisher) throws AmetysRepositoryException
235    {
236        DublinCoreHelper.setDCPublisher(this, publisher);
237    }
238
239    @Override
240    public void setDCContributor(String contributor) throws AmetysRepositoryException
241    {
242        DublinCoreHelper.setDCContributor(this, contributor);
243    }
244
245    @Override
246    public void setDCDate(Date date) throws AmetysRepositoryException
247    {
248        DublinCoreHelper.setDCDate(this, date);
249    }
250
251    @Override
252    public void setDCType(String type) throws AmetysRepositoryException
253    {
254        DublinCoreHelper.setDCType(this, type);
255    }
256
257    @Override
258    public void setDCFormat(String format) throws AmetysRepositoryException
259    {
260        DublinCoreHelper.setDCFormat(this, format);
261    }
262
263    @Override
264    public void setDCIdentifier(String identifier) throws AmetysRepositoryException
265    {
266        DublinCoreHelper.setDCIdentifier(this, identifier);
267    }
268
269    @Override
270    public void setDCSource(String source) throws AmetysRepositoryException
271    {
272        DublinCoreHelper.setDCSource(this, source);
273    }
274
275    @Override
276    public void setDCLanguage(String language) throws AmetysRepositoryException
277    {
278        DublinCoreHelper.setDCLanguage(this, language);
279    }
280
281    @Override
282    public void setDCRelation(String relation) throws AmetysRepositoryException
283    {
284        DublinCoreHelper.setDCRelation(this, relation);
285    }
286    
287    @Override
288    public void setDCCoverage(String coverage) throws AmetysRepositoryException
289    {
290        DublinCoreHelper.setDCCoverage(this, coverage);
291    }
292    
293    @Override
294    public void setDCRights(String rights) throws AmetysRepositoryException
295    {
296        DublinCoreHelper.setDCRights(this, rights);
297    }
298    
299    // ---------------------------- COMMENTS ------------------------------ //
300    @Override
301    public Comment createComment()
302    {
303        return new Comment(this.getUnversionedDataHolder());
304    }
305    
306    public Comment createComment(String commentId, ZonedDateTime creationDate)
307    {
308        return new Comment(this.getUnversionedDataHolder(), commentId, creationDate);
309    }
310    
311    @Override
312    public Comment getComment(String commentId) throws AmetysRepositoryException
313    {
314        return Comment.getComment(this.getUnversionedDataHolder(), commentId);
315    }
316    
317    @Override
318    public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException
319    {
320        return Comment.getComments(this.getUnversionedDataHolder(), includeNotValidatedComments, includeValidatedComments);
321    }
322
323    // ---------------------------- DATA HOLDER --------------------------- //
324    @Override
325    public ModifiableContentDataHolder getDataHolder()
326    {
327        return new ModifiableContentDataHolder(this, _getFactory().getContentDataHelper(), new JCRRepositoryData(getNode()), _getFactory().getContentHelper().getContentTypes(this));
328    }
329    
330    public void fillContent(org.w3c.dom.Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception
331    {
332        _getFactory().getContentExtractor().fillContent(this, node, additionalDataGetter);
333    }
334}