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