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.data.holder.ModifiableIndexableDataHolder; 028import org.ametys.cms.repository.ModifiableContentDataHolder; 029import org.ametys.cms.repository.ModifiableWorkflowAwareContent; 030import org.ametys.cms.repository.WorkflowAwareContentHelper; 031import org.ametys.cms.repository.comment.Comment; 032import org.ametys.cms.repository.comment.CommentableContent; 033import org.ametys.core.user.UserIdentity; 034import org.ametys.plugins.repository.AmetysRepositoryException; 035import org.ametys.plugins.repository.RepositoryIntegrityViolationException; 036import org.ametys.plugins.repository.data.extractor.xml.XMLValuesExtractorAdditionalDataGetter; 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 setPrivacyLevel(String privacy) 116 { 117 ModifiableRepositoryData repositoryData = new JCRRepositoryData(getNode()); 118 repositoryData.setValue(PROPERTY_PRIVACY, privacy); 119 } 120 121 @Override 122 public void setTitle(String title, Locale locale) throws AmetysRepositoryException 123 { 124 _getFactory().getModifiableContentHelper().setTitle(this, title, locale); 125 } 126 127 @Override 128 @Deprecated 129 public void setTitle(String title) throws AmetysRepositoryException 130 { 131 _getFactory().getModifiableContentHelper().setTitle(this, title); 132 } 133 134 public void setCreator(UserIdentity user) throws AmetysRepositoryException 135 { 136 _getFactory().getModifiableContentHelper().setCreator(this, user); 137 } 138 139 public void setCreationDate(ZonedDateTime creationDate) throws AmetysRepositoryException 140 { 141 _getFactory().getModifiableContentHelper().setCreationDate(this, creationDate); 142 } 143 144 public void setLastContributor(UserIdentity user) 145 { 146 _getFactory().getModifiableContentHelper().setLastContributor(this, user); 147 } 148 149 public void setLastModified(ZonedDateTime lastModified) throws AmetysRepositoryException 150 { 151 _getFactory().getModifiableContentHelper().setLastModified(this, lastModified); 152 } 153 154 public void setFirstValidator(UserIdentity user) throws AmetysRepositoryException 155 { 156 _getFactory().getModifiableContentHelper().setFirstValidator(this, user); 157 } 158 159 @Override 160 public void setFirstValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 161 { 162 _getFactory().getModifiableContentHelper().setFirstValidationDate(this, validationDate); 163 } 164 165 public void setLastValidator(UserIdentity user) throws AmetysRepositoryException 166 { 167 _getFactory().getModifiableContentHelper().setLastValidator(this, user); 168 } 169 170 @Override 171 public void setLastValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 172 { 173 _getFactory().getModifiableContentHelper().setLastValidationDate(this, validationDate); 174 } 175 176 public void setLastMajorValidator(UserIdentity user) throws AmetysRepositoryException 177 { 178 _getFactory().getModifiableContentHelper().setLastMajorValidator(this, user); 179 } 180 181 @Override 182 public void setLastMajorValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 183 { 184 _getFactory().getModifiableContentHelper().setLastMajorValidationDate(this, validationDate); 185 } 186 187 @Override 188 public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException 189 { 190 _getFactory().getModifiableContentHelper().setOutgoingReferences(this, references); 191 } 192 193 // ------------------- Tags management -------------------- // 194 @Override 195 public void tag(String tag) throws AmetysRepositoryException 196 { 197 TaggableAmetysObjectHelper.tag(this, tag); 198 } 199 200 @Override 201 public void untag(String tag) throws AmetysRepositoryException 202 { 203 TaggableAmetysObjectHelper.untag(this, tag); 204 } 205 206 // Lock management. // 207 208 @Override 209 public void lock() throws AmetysRepositoryException 210 { 211 _getFactory().getLockComponent().lock(this); 212 } 213 214 @Override 215 public void unlock() throws AmetysRepositoryException 216 { 217 _getFactory().getLockComponent().unlock(this); 218 } 219 220 @Override 221 public boolean isLocked() throws AmetysRepositoryException 222 { 223 return _getFactory().getLockComponent().isLocked(this); 224 } 225 226 @Override 227 public UserIdentity getLockOwner() throws AmetysRepositoryException 228 { 229 return _getFactory().getLockComponent().getLockOwner(this); 230 } 231 232 // Dublin Core metadata. // 233 234 @Override 235 public void setDCTitle(String title) throws AmetysRepositoryException 236 { 237 DublinCoreHelper.setDCTitle(this, title); 238 } 239 240 @Override 241 public void setDCCreator(String creator) throws AmetysRepositoryException 242 { 243 DublinCoreHelper.setDCCreator(this, creator); 244 } 245 246 @Override 247 public void setDCSubject(String[] subject) throws AmetysRepositoryException 248 { 249 DublinCoreHelper.setDCSubject(this, subject); 250 } 251 252 @Override 253 public void setDCDescription(String description) throws AmetysRepositoryException 254 { 255 DublinCoreHelper.setDCDescription(this, description); 256 } 257 258 @Override 259 public void setDCPublisher(String publisher) throws AmetysRepositoryException 260 { 261 DublinCoreHelper.setDCPublisher(this, publisher); 262 } 263 264 @Override 265 public void setDCContributor(String contributor) throws AmetysRepositoryException 266 { 267 DublinCoreHelper.setDCContributor(this, contributor); 268 } 269 270 @Override 271 public void setDCDate(Date date) throws AmetysRepositoryException 272 { 273 DublinCoreHelper.setDCDate(this, date); 274 } 275 276 @Override 277 public void setDCType(String type) throws AmetysRepositoryException 278 { 279 DublinCoreHelper.setDCType(this, type); 280 } 281 282 @Override 283 public void setDCFormat(String format) throws AmetysRepositoryException 284 { 285 DublinCoreHelper.setDCFormat(this, format); 286 } 287 288 @Override 289 public void setDCIdentifier(String identifier) throws AmetysRepositoryException 290 { 291 DublinCoreHelper.setDCIdentifier(this, identifier); 292 } 293 294 @Override 295 public void setDCSource(String source) throws AmetysRepositoryException 296 { 297 DublinCoreHelper.setDCSource(this, source); 298 } 299 300 @Override 301 public void setDCLanguage(String language) throws AmetysRepositoryException 302 { 303 DublinCoreHelper.setDCLanguage(this, language); 304 } 305 306 @Override 307 public void setDCRelation(String relation) throws AmetysRepositoryException 308 { 309 DublinCoreHelper.setDCRelation(this, relation); 310 } 311 312 @Override 313 public void setDCCoverage(String coverage) throws AmetysRepositoryException 314 { 315 DublinCoreHelper.setDCCoverage(this, coverage); 316 } 317 318 @Override 319 public void setDCRights(String rights) throws AmetysRepositoryException 320 { 321 DublinCoreHelper.setDCRights(this, rights); 322 } 323 324 @Override 325 public Comment createComment() 326 { 327 return new Comment(this.getUnversionedDataHolder()); 328 } 329 330 public Comment createComment(String commentId, ZonedDateTime creationDate) 331 { 332 return new Comment(this.getUnversionedDataHolder(), commentId, creationDate); 333 } 334 335 @Override 336 public Comment getComment(String commentId) throws AmetysRepositoryException 337 { 338 return Comment.getComment(this.getUnversionedDataHolder(), commentId); 339 } 340 341 @Override 342 public List<Comment> getComments(boolean includeNotValidatedComments, boolean includeValidatedComments) throws AmetysRepositoryException 343 { 344 return Comment.getComments(this.getUnversionedDataHolder(), includeNotValidatedComments, includeValidatedComments); 345 } 346 @Override 347 348 public ModifiableIndexableDataHolder getDataHolder() 349 { 350 return new ModifiableContentDataHolder(this, _getFactory().getContentDataHelper(), new JCRRepositoryData(getNode()), _getFactory().getContentHelper().getContentTypes(this)); 351 } 352 353 public void fillContent(org.w3c.dom.Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception 354 { 355 _getFactory().getContentExtractor().fillContent(this, node, additionalDataGetter); 356 } 357}