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.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.repository.comment.Comment; 030import org.ametys.cms.repository.comment.CommentableContent; 031import org.ametys.core.user.UserIdentity; 032import org.ametys.plugins.repository.AmetysRepositoryException; 033import org.ametys.plugins.repository.RepositoryIntegrityViolationException; 034import org.ametys.plugins.repository.data.extractor.xml.XMLValuesExtractorAdditionalDataGetter; 035import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData; 036import org.ametys.plugins.repository.jcr.DublinCoreHelper; 037import org.ametys.plugins.repository.lock.LockableAmetysObject; 038import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObjectHelper; 039import org.ametys.plugins.repository.tag.TaggableAmetysObjectHelper; 040 041/** 042 * Default implementation of a {@link Content}, also versionable, lockable and workflow-aware. 043 * @param <F> the actual type of factory. 044 */ 045public class ModifiableDefaultContent<F extends ModifiableContentFactory> extends DefaultContent<F> implements CommentableContent, LockableAmetysObject, ModifiableWorkflowAwareContent/*, AnnotableContent*/ //, CopiableAmetysObject 046{ 047 /** 048 * Creates a JCR-based Content. 049 * @param node the JCR Node backing this Content. 050 * @param parentPath the parent path in the Ametys hierarchy. 051 * @param factory the corresponding {@link ContentFactory}. 052 */ 053 public ModifiableDefaultContent(Node node, String parentPath, F factory) 054 { 055 super(node, parentPath, factory); 056 } 057 058 public void setTitle(String title, Locale locale) throws AmetysRepositoryException 059 { 060 _getFactory()._getModifiableContentHelper().setTitle(this, title, locale); 061 } 062 063 public void setTitle(String title) throws AmetysRepositoryException 064 { 065 _getFactory()._getModifiableContentHelper().setTitle(this, title); 066 } 067 068 public void setCreator(UserIdentity user) throws AmetysRepositoryException 069 { 070 _getFactory()._getModifiableContentHelper().setCreator(this, user); 071 } 072 073 public void setCreationDate(ZonedDateTime creationDate) throws AmetysRepositoryException 074 { 075 _getFactory()._getModifiableContentHelper().setCreationDate(this, creationDate); 076 } 077 078 public void setLastContributor(UserIdentity user) 079 { 080 _getFactory()._getModifiableContentHelper().setLastContributor(this, user); 081 } 082 083 public void setLastModified(ZonedDateTime lastModified) throws AmetysRepositoryException 084 { 085 _getFactory()._getModifiableContentHelper().setLastModified(this, lastModified); 086 } 087 088 public void setFirstValidator(UserIdentity user) throws AmetysRepositoryException 089 { 090 _getFactory()._getModifiableContentHelper().setFirstValidator(this, user); 091 } 092 093 @Override 094 public void setFirstValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 095 { 096 _getFactory()._getModifiableContentHelper().setFirstValidationDate(this, validationDate); 097 } 098 099 public void setLastValidator(UserIdentity user) throws AmetysRepositoryException 100 { 101 _getFactory()._getModifiableContentHelper().setLastValidator(this, user); 102 } 103 104 @Override 105 public void setLastValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 106 { 107 _getFactory()._getModifiableContentHelper().setLastValidationDate(this, validationDate); 108 } 109 110 public void setLastMajorValidator(UserIdentity user) throws AmetysRepositoryException 111 { 112 _getFactory()._getModifiableContentHelper().setLastMajorValidator(this, user); 113 } 114 115 @Override 116 public void setLastMajorValidationDate(ZonedDateTime validationDate) throws AmetysRepositoryException 117 { 118 _getFactory()._getModifiableContentHelper().setLastMajorValidationDate(this, validationDate); 119 } 120 121 @Override 122 public void setOutgoingReferences(Map<String, OutgoingReferences> references) throws AmetysRepositoryException 123 { 124 _getFactory()._getModifiableContentHelper().setOutgoingReferences(this, references); 125 } 126 127 // ------------------- Tags management -------------------- // 128 @Override 129 public void tag(String tag) throws AmetysRepositoryException 130 { 131 TaggableAmetysObjectHelper.tag(this, tag); 132 } 133 134 @Override 135 public void untag(String tag) throws AmetysRepositoryException 136 { 137 TaggableAmetysObjectHelper.untag(this, tag); 138 } 139 140 // ------------------- Workflow management -------------------- // 141 @Override 142 public long getWorkflowId() throws AmetysRepositoryException 143 { 144 return WorkflowAwareContentHelper.getWorkflowId(this); 145 } 146 147 @Override 148 public void setWorkflowId(long workflowId) throws AmetysRepositoryException 149 { 150 WorkflowAwareContentHelper.setWorkflowId(this, workflowId); 151 } 152 153 @Override 154 public long getCurrentStepId() throws AmetysRepositoryException 155 { 156 return WorkflowAwareContentHelper.getCurrentStepId(this); 157 } 158 159 @Override 160 public void setCurrentStepId (long stepId) throws AmetysRepositoryException 161 { 162 WorkflowAwareContentHelper.setCurrentStepId(this, stepId); 163 } 164 165 @Override 166 public ZonedDateTime getProposalDate() throws AmetysRepositoryException 167 { 168 return WorkflowAwareContentHelper.getProposalDate(this); 169 } 170 171 @Override 172 public void setProposalDate(ZonedDateTime proposalDate) throws AmetysRepositoryException 173 { 174 WorkflowAwareContentHelper.setProposalDate(this, proposalDate); 175 } 176 177 @Override 178 public void remove() throws AmetysRepositoryException, RepositoryIntegrityViolationException 179 { 180 MetadataAwareAmetysObjectHelper.removeSubObjects(this); 181 182 super.remove(); 183 } 184 185 // --------------------- Lock management ----------------------- // 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 ---------------------------- // 211 @Override 212 public void setDCTitle(String title) throws AmetysRepositoryException 213 { 214 DublinCoreHelper.setDCTitle(this, title); 215 } 216 217 @Override 218 public void setDCCreator(String creator) throws AmetysRepositoryException 219 { 220 DublinCoreHelper.setDCCreator(this, creator); 221 } 222 223 @Override 224 public void setDCSubject(String[] subject) throws AmetysRepositoryException 225 { 226 DublinCoreHelper.setDCSubject(this, subject); 227 } 228 229 @Override 230 public void setDCDescription(String description) throws AmetysRepositoryException 231 { 232 DublinCoreHelper.setDCDescription(this, description); 233 } 234 235 @Override 236 public void setDCPublisher(String publisher) throws AmetysRepositoryException 237 { 238 DublinCoreHelper.setDCPublisher(this, publisher); 239 } 240 241 @Override 242 public void setDCContributor(String contributor) throws AmetysRepositoryException 243 { 244 DublinCoreHelper.setDCContributor(this, contributor); 245 } 246 247 @Override 248 public void setDCDate(Date date) throws AmetysRepositoryException 249 { 250 DublinCoreHelper.setDCDate(this, date); 251 } 252 253 @Override 254 public void setDCType(String type) throws AmetysRepositoryException 255 { 256 DublinCoreHelper.setDCType(this, type); 257 } 258 259 @Override 260 public void setDCFormat(String format) throws AmetysRepositoryException 261 { 262 DublinCoreHelper.setDCFormat(this, format); 263 } 264 265 @Override 266 public void setDCIdentifier(String identifier) throws AmetysRepositoryException 267 { 268 DublinCoreHelper.setDCIdentifier(this, identifier); 269 } 270 271 @Override 272 public void setDCSource(String source) throws AmetysRepositoryException 273 { 274 DublinCoreHelper.setDCSource(this, source); 275 } 276 277 @Override 278 public void setDCLanguage(String language) throws AmetysRepositoryException 279 { 280 DublinCoreHelper.setDCLanguage(this, language); 281 } 282 283 @Override 284 public void setDCRelation(String relation) throws AmetysRepositoryException 285 { 286 DublinCoreHelper.setDCRelation(this, relation); 287 } 288 289 @Override 290 public void setDCCoverage(String coverage) throws AmetysRepositoryException 291 { 292 DublinCoreHelper.setDCCoverage(this, coverage); 293 } 294 295 @Override 296 public void setDCRights(String rights) throws AmetysRepositoryException 297 { 298 DublinCoreHelper.setDCRights(this, rights); 299 } 300 301 // ---------------------------- COMMENTS ------------------------------ // 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 325 // ---------------------------- DATA HOLDER --------------------------- // 326 @Override 327 public ModifiableContentDataHolder getDataHolder() 328 { 329 // It is necessary to instantiate the repository data because of locks: 330 // when the content is locked, the lock token is released to be taken by anyone 331 // in repository data there is a lock checked boolean that need to be reset in order to take the token 332 // this boolean is only reset at instantiation 333 Collection<ContentType> contentTypes = _getFactory().getContentHelper().getContentTypes(this); 334 return new ModifiableContentDataHolder(this, _getFactory().getContentDataHelper(), new JCRRepositoryData(getNode()), contentTypes); 335 } 336 337 public void fillContent(org.w3c.dom.Node node, XMLValuesExtractorAdditionalDataGetter additionalDataGetter) throws Exception 338 { 339 _getFactory().getContentExtractor().fillContent(this, node, additionalDataGetter); 340 } 341}