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.plugins.repository.metadata;
017
018import java.util.Date;
019
020import org.ametys.core.user.UserIdentity;
021import org.ametys.plugins.repository.AmetysRepositoryException;
022import org.ametys.plugins.repository.ModifiableTraversableAmetysObject;
023import org.ametys.plugins.repository.TraversableAmetysObject;
024
025/**
026 * Modifiable {@link CompositeMetadata}.
027 */
028public interface ModifiableCompositeMetadata extends CompositeMetadata
029{
030    /**
031     * Rename the current metadata
032     * @param newName the new name
033     * @throws AmetysRepositoryException if an error occurs.
034     */
035    public void rename(String newName) throws AmetysRepositoryException;
036    
037    /**
038     * Removes the given metadata.
039     * @param metadataName metadata name.
040     * @throws UnknownMetadataException if the metadata does not exist.
041     * @throws AmetysRepositoryException if an error occurs.
042     */
043    public void removeMetadata(String metadataName) throws UnknownMetadataException, AmetysRepositoryException;
044
045    /**
046     * Returns the named metadata's value as {@link BinaryMetadata}.<br> 
047     * If the metadata does not exist and createNew is <code>false</code>, an {@link UnknownMetadataException} is thrown.
048     * Otherwise, the metadata is automatically created.
049     * @param metadataName the metadata name.
050     * @param createNew <code>true</code> to create automatically the {@link BinaryMetadata} when missing.
051     * @return the metadata value as BinaryMetadata.
052     * @throws UnknownMetadataException if the named metadata does not exist.
053     * @throws AmetysRepositoryException if an error occurs.
054     */
055    public ModifiableBinaryMetadata getBinaryMetadata(String metadataName, boolean createNew) throws UnknownMetadataException, AmetysRepositoryException;
056    
057    public ModifiableBinaryMetadata getBinaryMetadata(String metadataName) throws UnknownMetadataException, AmetysRepositoryException;
058
059    /**
060     * Returns the named metadata's value as {@link RichText}.<br> 
061     * If the metadata does not exist and createNew is <code>false</code>, an {@link UnknownMetadataException} is thrown.
062     * Otherwise, the metadata is automatically created.
063     * @param metadataName the metadata name.
064     * @param createNew <code>true</code> to create automatically the {@link BinaryMetadata} when missing.
065     * @return the metadata value as RichText.
066     * @throws UnknownMetadataException if the named metadata does not exist.
067     * @throws AmetysRepositoryException if an error occurs.
068     */
069    public ModifiableRichText getRichText(String metadataName, boolean createNew) throws UnknownMetadataException, AmetysRepositoryException;
070
071    public ModifiableRichText getRichText(String metadataName) throws UnknownMetadataException, AmetysRepositoryException;
072
073    @Override
074    public ModifiableCompositeMetadata getCompositeMetadata(String metadataName) throws UnknownMetadataException, AmetysRepositoryException;
075
076    /**
077     * Returns the named metadata's value as {@link CompositeMetadata}.<br> 
078     * If the metadata is multi-valued, one of the value is returned.<br>
079     * If the metadata does not exist and createNew is <code>false</code>, an {@link UnknownMetadataException} is thrown. Otherwise, the metadata is automatically created.
080     * @param metadataName the metadata name.
081     * @param createNew <code>true</code> to create automatically the {@link CompositeMetadata} when missing.
082     * @return the metadata value as {@link CompositeMetadata}.
083     * @throws UnknownMetadataException if the named metadata does not exist.
084     * @throws AmetysRepositoryException if an error occurs.
085     */
086    public ModifiableCompositeMetadata getCompositeMetadata(String metadataName, boolean createNew) throws UnknownMetadataException, AmetysRepositoryException;
087
088    @Override
089    ModifiableTraversableAmetysObject getObjectCollection(String metadataName) throws AmetysRepositoryException;
090    
091    /**
092     * Returns an object collection metadata as a {@link TraversableAmetysObject}<br>.
093     * If the metadata does not exist and createNew is <code>false</code>, an {@link UnknownMetadataException} is thrown. Otherwise, the metadata is automatically created.
094     * @param metadataName the metadata name.
095     * @param createNew <code>true</code> to create automatically the {@link CompositeMetadata} when missing.
096     * @return the metadata as a {@link TraversableAmetysObject}.
097     * @throws UnknownMetadataException if the named metadata does not exist.
098     * @throws AmetysRepositoryException if an error occurs.
099     */
100    ModifiableTraversableAmetysObject getObjectCollection(String metadataName, boolean createNew) throws AmetysRepositoryException;
101    
102    /**
103     * Set a string metadata.
104     * @param metadataName the metadata name.
105     * @param value the String value of this metadata.
106     * @throws AmetysRepositoryException if the metadata cannot be set.
107     */
108    public void setMetadata(String metadataName, String value) throws AmetysRepositoryException;
109
110    /**
111     * Set a date metadata.
112     * @param metadataName the metadata name.
113     * @param value the Date value of this metadata.
114     * @throws AmetysRepositoryException if the metadata cannot be set.
115     */
116    public void setMetadata(String metadataName, Date value) throws AmetysRepositoryException;
117
118    /**
119     * Set a long metadata.
120     * @param metadataName the metadata name.
121     * @param value the integer value of this metadata.
122     * @throws AmetysRepositoryException if the metadata cannot be set.
123     */
124    public void setMetadata(String metadataName, long value) throws AmetysRepositoryException;
125
126    /**
127     * Set a double metadata.
128     * @param metadataName the metadata name.
129     * @param value the integer value of this metadata.
130     * @throws AmetysRepositoryException if the metadata cannot be set.
131     */
132    public void setMetadata(String metadataName, double value) throws AmetysRepositoryException;
133
134    /**
135     * Set a boolean metadata.
136     * @param metadataName the metadata name.
137     * @param value the boolean value of this metadata.
138     * @throws AmetysRepositoryException if the metadata cannot be set.
139     */
140    public void setMetadata(String metadataName, boolean value) throws AmetysRepositoryException;
141    
142    /**
143     * Set a {@link UserIdentity} metadata.
144     * @param metadataName the metadata name.
145     * @param value the {@link UserIdentity} value of this metadata.
146     * @throws AmetysRepositoryException if the metadata cannot be set.
147     */
148    public void setMetadata(String metadataName, UserIdentity value) throws AmetysRepositoryException;
149
150    /**
151     * Set a multi-valued string metadata.
152     * @param metadataName the metadata name.
153     * @param values the String array containing values of this metadata.
154     * @throws AmetysRepositoryException if the metadata cannot be set.
155     */
156    public void setMetadata(String metadataName, String[] values) throws AmetysRepositoryException;
157
158    /**
159     * Set a multi-valued date metadata.
160     * @param metadataName the metadata name.
161     * @param values the Date array containing values of this metadata.
162     * @throws AmetysRepositoryException if the metadata cannot be set.
163     */
164    public void setMetadata(String metadataName, Date[] values) throws AmetysRepositoryException;
165
166    /**
167     * Set a multi-valued long metadata.
168     * @param metadataName the metadata name.
169     * @param values the integer array containing values of this metadata.
170     * @throws AmetysRepositoryException if the metadata cannot be set.
171     */
172    public void setMetadata(String metadataName, long[] values) throws AmetysRepositoryException;
173
174    /**
175     * Set a multi-valued double metadata.
176     * @param metadataName the metadata name.
177     * @param values the integer array containing values of this metadata.
178     * @throws AmetysRepositoryException if the metadata cannot be set.
179     */
180    public void setMetadata(String metadataName, double[] values) throws AmetysRepositoryException;
181
182    /**
183     * Set a multi-valued boolean metadata.
184     * @param metadataName the metadata name.
185     * @param values the boolean array containing values of this metadata.
186     * @throws AmetysRepositoryException if the metadata cannot be set.
187     */
188    public void setMetadata(String metadataName, boolean[] values) throws AmetysRepositoryException;
189    
190    /**
191     * Set a multi-valued {@link UserIdentity} metadata.
192     * @param metadataName the metadata name.
193     * @param values the {@link UserIdentity} array containing values of this metadata.
194     * @throws AmetysRepositoryException  if the metadata cannot be set.
195     */
196    public void setMetadata(String metadataName, UserIdentity[] values) throws AmetysRepositoryException;
197}