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