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.util.Collection;
019import java.util.Date;
020import java.util.Locale;
021import java.util.Map;
022
023import org.ametys.cms.content.references.OutgoingReferences;
024import org.ametys.core.user.UserIdentity;
025import org.ametys.plugins.explorer.resources.ResourceCollection;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027import org.ametys.plugins.repository.ModifiableACLAmetysObject;
028import org.ametys.plugins.repository.dublincore.DublinCoreAwareAmetysObject;
029import org.ametys.plugins.repository.metadata.MetadataAwareAmetysObject;
030import org.ametys.plugins.repository.metadata.UnknownMetadataException;
031
032/**
033 * Content abstraction defined by the following properties:
034 * <dl>
035 *   <dt>type
036 *   <dd>the content type (can only be set on creation)
037 *   <dt>language
038 *   <dd>the language (can only be set on creation)
039 *   <dt>title
040 *   <dd>the title
041 *   <dt>creator
042 *   <dd>the login of the creator
043 *   <dt>creationDate
044 *   <dd>the date when the content was created
045 *   <dt>lastContributor
046 *   <dd>the login of the last contributor
047 *   <dt>lastModified
048 *   <dd>the date when the last modification takes place
049 * </dl>
050 */
051public interface Content extends MetadataAwareAmetysObject, DublinCoreAwareAmetysObject, TagAwareAmetysObject, ModifiableACLAmetysObject
052{
053    /**
054     * Retrieves the types of this content.
055     * @return the types of this content.
056     * @throws AmetysRepositoryException if an error occurs.
057     */
058    public String[] getTypes() throws AmetysRepositoryException;
059    
060    /**
061     * Retrieves the mixin types of this content.
062     * @return the mixin types of this content.
063     * @throws AmetysRepositoryException  if an error occurs.
064     */
065    public String[] getMixinTypes() throws AmetysRepositoryException;
066    
067    /**
068     * Retrieves the language of this content.<br>
069     * @return the language of this content or <code>null</code> if the content is a multilingual content
070     * @throws AmetysRepositoryException if an error occurs.
071     */
072    public String getLanguage() throws AmetysRepositoryException;
073    
074    /**
075     * Retrieves the title for the given locale. If the locale is null or does not exist, the first locale will be used.
076     * @param locale The locale. Can be null if the content is not a multilingual content or to get the title in the default locale.
077     * @return the title.
078     * @throws UnknownMetadataException if this property does not exist.
079     * @throws AmetysRepositoryException if an error occurs.
080     */
081    public String getTitle(Locale locale) throws UnknownMetadataException, AmetysRepositoryException;
082    
083    /**
084     * Retrieves the title.
085     * This method is same as {@link #getTitle(Locale)} with a null locale.
086     * Use this method only if you are manipulating no-multilingual content. If not sure, use {@link #getTitle(Locale)} instead.
087     * @return the title.
088     * @throws UnknownMetadataException if this property does not exist.
089     * @throws AmetysRepositoryException if an error occurs.
090     */
091    public String getTitle() throws UnknownMetadataException, AmetysRepositoryException;
092
093    /**
094     * Retrieves the login of the creator.
095     * @return the login of the creator.
096     * @throws UnknownMetadataException if this property does not exist.
097     * @throws AmetysRepositoryException if an error occurs.
098     */
099    public UserIdentity getCreator() throws UnknownMetadataException, AmetysRepositoryException;
100    
101    /**
102     * Retrieves the creation date.
103     * @return the creation date.
104     * @throws UnknownMetadataException if this property does not exist.
105     * @throws AmetysRepositoryException if an error occurs.
106     */
107    public Date getCreationDate() throws UnknownMetadataException, AmetysRepositoryException;
108    
109    /**
110     * Retrieves the login of the last contributor.
111     * @return the login of the last contributor.
112     * @throws UnknownMetadataException if this property does not exist.
113     * @throws AmetysRepositoryException if an error occurs.
114     */
115    public UserIdentity getLastContributor() throws UnknownMetadataException, AmetysRepositoryException;
116    
117    /**
118     * Retrieves the last modification date.
119     * @return the last modification date.
120     * @throws UnknownMetadataException if this property does not exist.
121     * @throws AmetysRepositoryException if an error occurs.
122     */
123    public Date getLastModified() throws UnknownMetadataException, AmetysRepositoryException;
124
125    /**
126     * Retrieves the last validation date
127     * @return the last validation date
128     * @throws UnknownMetadataException if this property does not exist.
129     * @throws AmetysRepositoryException if an error occurs.
130     */
131    public Date getLastValidationDate() throws UnknownMetadataException, AmetysRepositoryException;
132    
133    /**
134     * Retrieves the last validation date resulting from a major modification. At least this is the first validation date
135     * @return the last validation date resulting from a major modification
136     * @throws UnknownMetadataException if this property does not exist.
137     * @throws AmetysRepositoryException if an error occurs.
138     */
139    public Date getLastMajorValidationDate () throws UnknownMetadataException, AmetysRepositoryException;
140    
141    /**
142     * Returns all Contents referencing this Content (as a metadata).
143     * @return all Contents referencing this Content.
144     * @throws AmetysRepositoryException if an error occurs.
145     */
146    public Collection<Content> getReferencingContents() throws AmetysRepositoryException;
147    
148    /**
149     * Returns <code>true</code> if there is at least one Content referencing this Content (as a metadata).
150     * @return <code>true</code> if there is at least one Content referencing this Content.
151     * @throws AmetysRepositoryException if an error occurs.
152     */
153    public boolean hasReferencingContents() throws AmetysRepositoryException;
154    
155    /**
156     * Get the stored outgoing references of the content. This references can be used for different purposes, such as testing link consistency for example.
157     * @return A non null map of outgoing references grouped by metadata (key are metadata path)
158     * @throws AmetysRepositoryException if an error occurs.
159     */
160    public Map<String, OutgoingReferences> getOutgoingReferences() throws AmetysRepositoryException;
161
162    /**
163     * Retrieves the attachments root node
164     * @return The attachments root node, or null if the content is working on
165     * an (unmodifiable) old version and the attachments root is missing.
166     * @throws AmetysRepositoryException if an error occurs.
167     */
168    public ResourceCollection getRootAttachments() throws AmetysRepositoryException;
169}