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