001/*
002 *  Copyright 2010 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.Locale;
021import java.util.Map;
022import java.util.Optional;
023
024import org.xml.sax.ContentHandler;
025import org.xml.sax.SAXException;
026
027import org.ametys.cms.content.references.OutgoingReferences;
028import org.ametys.cms.data.ametysobject.ModelAwareDataAwareAmetysObject;
029import org.ametys.core.user.UserIdentity;
030import org.ametys.plugins.explorer.resources.ResourceCollection;
031import org.ametys.plugins.repository.AmetysRepositoryException;
032import org.ametys.plugins.repository.ModifiableACLAmetysObject;
033import org.ametys.plugins.repository.data.UnknownDataException;
034import org.ametys.plugins.repository.data.holder.DataHolder;
035import org.ametys.plugins.repository.data.holder.ModifiableModelLessDataHolder;
036import org.ametys.plugins.repository.dublincore.DublinCoreAwareAmetysObject;
037import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObject;
038import org.ametys.plugins.repository.tag.TagAwareAmetysObject;
039import org.ametys.runtime.model.View;
040
041/**
042 * Content abstraction defined by the following properties:
043 * <dl>
044 *   <dt>type
045 *   <dd>the content type (can only be set on creation)
046 *   <dt>language
047 *   <dd>the language (can only be set on creation)
048 *   <dt>title
049 *   <dd>the title
050 *   <dt>creator
051 *   <dd>the login of the creator
052 *   <dt>creationDate
053 *   <dd>the date when the content was created
054 *   <dt>lastContributor
055 *   <dd>the login of the last contributor
056 *   <dt>lastModified
057 *   <dd>the date when the last modification takes place
058 * </dl>
059 */
060public interface Content extends ModelAwareDataAwareAmetysObject, MetadataAwareAmetysObject, DublinCoreAwareAmetysObject, TagAwareAmetysObject, ModifiableACLAmetysObject
061{
062    /** Constants for title attribute */
063    public static final String ATTRIBUTE_TITLE = "title";
064    
065    /** 
066     * Constants for title Metadata 
067     * Use ATTRIBUTE_TITLE
068     */
069    @Deprecated
070    public static final String METADATA_TITLE = "title";
071    
072    /**
073     * Record to get referencing contents with additional informations, we can get a limited number of referencing contents, then we would
074     * need the total number of refencing contents and if all references has been resolved.
075     * One referencing content can have several references.
076     * 
077     * @param total The total number of references
078     * @param referencingContents The resolved referencing contents (can be limited)
079     * @param hasOtherReferences <code>true</code> if all references has not been resolved in referencingContents attribute.
080     */
081    public record ReferencingContentsSearch(long total, Collection<Content> referencingContents, boolean hasOtherReferences) { /* empty */ }
082    
083    /**
084     * Retrieves the type identifiers of this content.
085     * @return the type identifiers of this content.
086     * @throws AmetysRepositoryException if an error occurs.
087     */
088    public String[] getTypes() throws AmetysRepositoryException;
089    
090    /**
091     * Set the type of this content
092     * @param type the type to set
093     * @throws AmetysRepositoryException if an error occurs.
094     */
095    public void setType(String type) throws AmetysRepositoryException;
096    
097    /**
098     * Set the types of this Content.<br>
099     * @param types the types of this content.
100     * @throws AmetysRepositoryException if an error occurs.
101     */
102    public void setTypes(String[] types) throws AmetysRepositoryException;
103    
104    /**
105     * Retrieves the mixin type identifiers of this content.
106     * @return the mixin type identifiers of this content.
107     * @throws AmetysRepositoryException  if an error occurs.
108     */
109    public String[] getMixinTypes() throws AmetysRepositoryException;
110    
111    /**
112     * Set the mixins of this Content.<br>
113     * @param mixins the mixins of this content.
114     * @throws AmetysRepositoryException if an error occurs.
115     */
116    public void setMixinTypes(String[] mixins) throws AmetysRepositoryException;
117    
118    /**
119     * Retrieves the language of this content.<br>
120     * @return the language of this content or <code>null</code> if the content is a multilingual content
121     * @throws AmetysRepositoryException if an error occurs.
122     */
123    public String getLanguage() throws AmetysRepositoryException;
124
125    /**
126     * Set the type of this Content.<br>
127     * This method may only be called on a new Content, ie. before its first save.
128     * @param language the language of this content.
129     * @throws AmetysRepositoryException if an error occurs.
130     */
131    public void setLanguage(String language) throws AmetysRepositoryException;
132    
133    /**
134     * Retrieves the title for the given locale. If the locale is null or does not exist, the first locale will be used.
135     * @param locale The locale. Can be null if the content is not a multilingual content or to get the title in the default locale.
136     * @return the title.
137     * @throws UnknownDataException if this property does not exist.
138     * @throws AmetysRepositoryException if an error occurs.
139     */
140    public String getTitle(Locale locale) throws UnknownDataException, AmetysRepositoryException;
141    
142    /**
143     * Retrieves the title.
144     * This method is same as {@link #getTitle(Locale)} with a null locale.
145     * Use this method only if you are manipulating no-multilingual content. If not sure, use {@link #getTitle(Locale)} instead.
146     * @return the title.
147     * @throws UnknownDataException if this property does not exist.
148     * @throws AmetysRepositoryException if an error occurs.
149     */
150    public String getTitle() throws UnknownDataException, AmetysRepositoryException;
151
152    /**
153     * Retrieves the login of the creator.
154     * @return the login of the creator.
155     * @throws UnknownDataException if this property does not exist.
156     * @throws AmetysRepositoryException if an error occurs.
157     */
158    public UserIdentity getCreator() throws UnknownDataException, AmetysRepositoryException;
159    
160    /**
161     * Retrieves the creation date.
162     * @return the creation date.
163     * @throws UnknownDataException if this property does not exist.
164     * @throws AmetysRepositoryException if an error occurs.
165     */
166    public ZonedDateTime getCreationDate() throws UnknownDataException, AmetysRepositoryException;
167    
168    /**
169     * Retrieves the login of the last contributor.
170     * @return the login of the last contributor.
171     * @throws UnknownDataException if this property does not exist.
172     * @throws AmetysRepositoryException if an error occurs.
173     */
174    public UserIdentity getLastContributor() throws UnknownDataException, AmetysRepositoryException;
175    
176    /**
177     * Retrieves the last modification date.
178     * @return the last modification date.
179     * @throws UnknownDataException if this property does not exist.
180     * @throws AmetysRepositoryException if an error occurs.
181     */
182    public ZonedDateTime getLastModified() throws UnknownDataException, AmetysRepositoryException;
183
184    /**
185     * Retrieves the identity of the first validator
186     * An empty value should not be considered as a content never being validated.
187     * Old content could have been validated before the introduction of this value and have not be updated.
188     * {@link #getFirstValidationDate()} is more reliable for this usage.
189     * 
190     * @return the first validator
191     * @throws AmetysRepositoryException if an error occurs.
192     */
193    public Optional<UserIdentity> getFirstValidator() throws AmetysRepositoryException;
194    
195    /**
196     * Retrieves the first validation date
197     * @return the first validation date
198     * @throws UnknownDataException if this property does not exist.
199     * @throws AmetysRepositoryException if an error occurs.
200     */
201    public ZonedDateTime getFirstValidationDate() throws UnknownDataException, AmetysRepositoryException;
202    
203    /**
204     * Retrieves the identity of the last validator.
205     * An empty value should not be considered as a content never being validated.
206     * Old content could have been validated before the introduction of this value and have not be updated.
207     * {@link #getLastValidationDate()} is more reliable for this usage.
208     * 
209     * @return the last validator if the value exists
210     * @throws AmetysRepositoryException if an error occurs.
211     */
212    public Optional<UserIdentity> getLastValidator() throws AmetysRepositoryException;
213    
214    /**
215     * Retrieves the last validation date
216     * @return the last validation date
217     * @throws UnknownDataException if this property does not exist.
218     * @throws AmetysRepositoryException if an error occurs.
219     */
220    public ZonedDateTime getLastValidationDate() throws UnknownDataException, AmetysRepositoryException;
221    
222    /**
223     * Retrieves the identity of the last major validator
224     * An empty value should not be considered as a content never being validated.
225     * Old content could have been validated before the introduction of this value and have not be updated.
226     * {@link #getLastMajorValidationDate()} is more reliable for this usage.
227     * 
228     * @return the last major validator
229     * @throws AmetysRepositoryException if an error occurs.
230     */
231    public Optional<UserIdentity> getLastMajorValidator() throws AmetysRepositoryException;
232    
233    /**
234     * Retrieves the last validation date resulting from a major modification. At least this is the first validation date
235     * @return the last validation date resulting from a major modification
236     * @throws UnknownDataException if this property does not exist.
237     * @throws AmetysRepositoryException if an error occurs.
238     */
239    public ZonedDateTime getLastMajorValidationDate () throws UnknownDataException, AmetysRepositoryException;
240    
241    /**
242     * Returns all Contents referencing this Content (as a metadata).
243     * @return all Contents referencing this Content.
244     * @throws AmetysRepositoryException if an error occurs.
245     */
246    public Collection<Content> getReferencingContents() throws AmetysRepositoryException;
247    
248    /**
249     * Returns an object for a limited search of referencing contents with the total of referencing contents, a collection of referencing contents limited to the given limit, and a boolean indicates if there are other references.
250     * @param limit The limit for resolved contents
251     * @return a record with total number of contents, resolved contents and a boolean indicates if there are more references.
252     * @throws AmetysRepositoryException if an error occurs
253     */
254    public ReferencingContentsSearch searchReferencingContents(int limit) throws AmetysRepositoryException;
255    
256    /**
257     * Returns <code>true</code> if there is at least one Content referencing this Content (as a metadata).
258     * @return <code>true</code> if there is at least one Content referencing this Content.
259     * @throws AmetysRepositoryException if an error occurs.
260     */
261    public boolean hasReferencingContents() throws AmetysRepositoryException;
262    
263    /**
264     * Get the stored outgoing references of the content. This references can be used for different purposes, such as testing link consistency for example.
265     * @return A non null map of outgoing references grouped by metadata (key are metadata path)
266     * @throws AmetysRepositoryException if an error occurs.
267     */
268    public Map<String, OutgoingReferences> getOutgoingReferences() throws AmetysRepositoryException;
269
270    /**
271     * Retrieves the attachments root node
272     * @return The attachments root node, or null if the content is working on
273     * an (unmodifiable) old version and the attachments root is missing.
274     * @throws AmetysRepositoryException if an error occurs.
275     */
276    public ResourceCollection getRootAttachments() throws AmetysRepositoryException;
277    
278    /**
279     * Generates SAX events representing this Content.
280     * @param contentHandler the {@link ContentHandler} that will receive the SAX events.
281     * @param locale the {@link Locale} to use for eg. multilingual attributes.
282     * @param view the associated View, or null to generate SAX events for all attributes from the model.
283     * @param saxWorkflowStep if true, also generates SAX events for the current workflow step.
284     * @throws SAXException if an error occurs during the SAX events generation.
285     */
286    public void toSAX(ContentHandler contentHandler, Locale locale, View view, boolean saxWorkflowStep) throws SAXException;
287    
288    /**
289     * Returns the {@link DataHolder} for internal data of this {@link Content}.
290     * @return the {@link DataHolder} for internal data of this {@link Content}
291     */
292    public ModifiableModelLessDataHolder getInternalDataHolder();
293}