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.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.comment.Comment; 028import org.ametys.cms.repository.comment.CommentableContent; 029import org.ametys.cms.tag.jcr.TaggableAmetysObjectHelper; 030import org.ametys.core.user.UserIdentity; 031import org.ametys.plugins.repository.AmetysRepositoryException; 032import org.ametys.plugins.repository.RepositoryIntegrityViolationException; 033import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder; 034import org.ametys.plugins.repository.data.holder.impl.DefaultModifiableModelAwareDataHolder; 035import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData; 036import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData; 037import org.ametys.plugins.repository.jcr.DublinCoreHelper; 038import org.ametys.plugins.repository.lock.LockableAmetysObject; 039import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObjectHelper; 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 setTypes(String[] types) throws AmetysRepositoryException 059 { 060 _getFactory()._getModifiableContentHelper().setTypes(this, types); 061 } 062 063 public void setMixinTypes(String[] mixins) throws AmetysRepositoryException 064 { 065 _getFactory()._getModifiableContentHelper().setMixinTypes(this, mixins); 066 } 067 068 public void setLanguage(String language) throws AmetysRepositoryException 069 { 070 _getFactory()._getModifiableContentHelper().setLanguage(this, language); 071 } 072 073 public void setTitle(String title, Locale locale) throws AmetysRepositoryException 074 { 075 _getFactory()._getModifiableContentHelper().setTitle(this, title, locale); 076 } 077 078 public void setTitle(String title) throws AmetysRepositoryException 079 { 080 _getFactory()._getModifiableContentHelper().setTitle(this, title); 081 } 082 083 public void setCreator(UserIdentity user) throws AmetysRepositoryException 084 { 085 _getFactory()._getModifiableContentHelper().setCreator(this, user); 086 } 087 088 public void setCreationDate(Date creationDate) throws AmetysRepositoryException 089 { 090 _getFactory()._getModifiableContentHelper().setCreationDate(this, creationDate); 091 } 092 093 public void setLastContributor(UserIdentity user) 094 { 095 _getFactory()._getModifiableContentHelper().setLastContributor(this, user); 096 } 097 098 public void setLastModified(Date lastModified) throws AmetysRepositoryException 099 { 100 _getFactory()._getModifiableContentHelper().setLastModified(this, lastModified); 101 } 102 103 @Override 104 public void setFirstValidationDate(Date validationDate) throws AmetysRepositoryException 105 { 106 _getFactory()._getModifiableContentHelper().setFirstValidationDate(this, validationDate); 107 } 108 109 @Override 110 public void setLastValidationDate(Date validationDate) throws AmetysRepositoryException 111 { 112 _getFactory()._getModifiableContentHelper().setLastValidationDate(this, validationDate); 113 } 114 115 @Override 116 public void setLastMajorValidationDate(Date 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 ModifiableModelAwareDataHolder getDataHolder() 328 { 329 ModifiableRepositoryData repositoryData = new JCRRepositoryData(getNode()); 330 return new DefaultModifiableModelAwareDataHolder(repositoryData, getModels()); 331 } 332}