001/*
002 *  Copyright 2018 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.data.holder;
017
018import java.io.IOException;
019import java.util.Map;
020import java.util.Optional;
021
022import org.ametys.plugins.repository.data.UnknownDataException;
023import org.ametys.plugins.repository.data.holder.group.impl.ModifiableModelLessComposite;
024import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
025import org.ametys.runtime.model.exception.BadItemTypeException;
026import org.ametys.runtime.model.exception.NotUniqueTypeException;
027import org.ametys.runtime.model.exception.UnknownTypeException;
028
029/**
030 * Interface for modifiable data containers without models
031 */
032public interface ModifiableModelLessDataHolder extends ModifiableDataHolder, ModelLessDataHolder
033{
034    @Override
035    public ModifiableModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException;
036    
037    /**
038     * {@inheritDoc}
039     * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple
040     */
041    @Override
042    public ModifiableModelLessComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException;
043    
044    /**
045     * Synchronizes the given values with the current ones
046     * @param values the values to synchronize
047     * @return <code>true</code> if some values have changed, <code>false</code> otherwise
048     * @throws IOException if an error occurs while synchronizing I/O data
049     * @throws UnknownTypeException if there is no available type compatible with a given value for this data holder's type extension point
050     * @throws NotUniqueTypeException if there is more than one available types compatibles with the a value for this data holder's type extension point
051     */
052    public boolean synchronizeValues(Map<String, Object> values) throws UnknownTypeException, NotUniqueTypeException, IOException;
053    
054    /**
055     * Sets the value of the data at the given path
056     * @param dataPath path of the data
057     * @param value the value to set. To empty a value, use {@link #setValue(String, Object, String)} with a <code>null</code> value
058     * @throws IllegalArgumentException if the given data path is null or empty
059     * @throws UnknownTypeException if there is no available type compatible with the given value for this data holder's type extension point
060     * @throws NotUniqueTypeException if there is more than one available types compatibles with the given value for this data holder's type extension point
061     * @throws UnknownDataException if given the data path is composed of an inexisting group
062     * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple
063     */
064    public void setValue(String dataPath, Object value) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, UnknownDataException, BadDataPathCardinalityException;
065    
066    /**
067     * Sets the value of the data at the given path
068     * @param dataPath path of the data
069     * @param value the value to set. Give <code>null</code> to empty the value.  
070     * @param dataTypeId type identifier of the data
071     * @throws IllegalArgumentException if the given data path is null or empty
072     * @throws UnknownTypeException if the given type is not available for this data holder's type extension point
073     * @throws BadItemTypeException if the given type doesn't match the given value to set
074     * @throws UnknownDataException if the given data path is composed of an inexisting group
075     * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple
076     */
077    public void setValue(String dataPath, Object value, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException;
078
079    /**
080     * {@inheritDoc}
081     * @throws BadDataPathCardinalityException if the value of a part of the data path is multiple. Only the last part can be multiple
082     */
083    @Override
084    public void removeValue(String dataPath) throws IllegalArgumentException, UnknownDataException, BadItemTypeException, BadDataPathCardinalityException;
085    
086    @Override
087    public Optional<? extends ModifiableModelLessDataHolder> getParentDataHolder();
088    
089    @Override
090    public ModifiableModelLessDataHolder getRootDataHolder();
091}