001/*
002 *  Copyright 2019 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.ametysobject;
017
018import java.io.IOException;
019import java.util.Map;
020import java.util.Optional;
021
022import org.ametys.plugins.repository.AmetysObject;
023import org.ametys.plugins.repository.ModifiableAmetysObject;
024import org.ametys.plugins.repository.data.UnknownDataException;
025import org.ametys.plugins.repository.data.holder.ModifiableModelLessDataHolder;
026import org.ametys.plugins.repository.data.holder.group.impl.ModifiableModelLessComposite;
027import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
028import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
029import org.ametys.runtime.model.exception.BadItemTypeException;
030import org.ametys.runtime.model.exception.NotUniqueTypeException;
031import org.ametys.runtime.model.exception.UnknownTypeException;
032
033/**
034 * Model less {@link AmetysObject} that can handle modifiable data.
035 */
036public interface ModifiableModelLessDataAwareAmetysObject extends ModifiableModelLessDataHolder, ModelLessDataAwareAmetysObject, ModifiableAmetysObject
037{
038    @Override
039    public ModifiableModelLessDataHolder getDataHolder();
040    
041    @Override
042    public default ModifiableModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException
043    {
044        return getDataHolder().getComposite(compositePath);
045    }
046    
047    public default ModifiableModelLessComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException
048    {
049        return getDataHolder().getComposite(compositePath, createNew);
050    }
051    
052    public default boolean synchronizeValues(Map<String, Object> values) throws UnknownTypeException, NotUniqueTypeException, IOException
053    {
054        return getDataHolder().synchronizeValues(values);
055    }
056
057    public default void setValue(String dataPath, Object value) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, UnknownDataException, BadDataPathCardinalityException
058    {
059        getDataHolder().setValue(dataPath, value);
060    }
061
062    public default void setValue(String dataPath, Object value, String dataType) throws IllegalArgumentException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException
063    {
064        getDataHolder().setValue(dataPath, value, dataType);
065    }
066
067    public default void removeValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
068    {
069        getDataHolder().removeValue(dataPath);
070    }
071    
072    public default ModifiableRepositoryData getRepositoryData()
073    {
074        return getDataHolder().getRepositoryData();
075    }
076    
077    public default Optional<? extends ModifiableModelLessDataHolder> getParentDataHolder()
078    {
079        return getDataHolder().getParentDataHolder();
080    }
081    
082    public default ModifiableModelLessDataHolder getRootDataHolder()
083    {
084        return getDataHolder().getRootDataHolder();
085    }
086}