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