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