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.util.Map;
019import java.util.Optional;
020
021import org.ametys.plugins.repository.AmetysObject;
022import org.ametys.plugins.repository.ModifiableAmetysObject;
023import org.ametys.plugins.repository.data.UnknownDataException;
024import org.ametys.plugins.repository.data.external.ExternalizableDataProvider.ExternalizableDataStatus;
025import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder;
026import org.ametys.plugins.repository.data.holder.group.ModifiableModelAwareComposite;
027import org.ametys.plugins.repository.data.holder.group.ModifiableModelAwareRepeater;
028import org.ametys.plugins.repository.data.holder.values.SynchronizationContext;
029import org.ametys.plugins.repository.data.holder.values.SynchronizationResult;
030import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
031import org.ametys.runtime.model.ViewItemAccessor;
032import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
033import org.ametys.runtime.model.exception.BadItemTypeException;
034import org.ametys.runtime.model.exception.UndefinedItemPathException;
035
036/**
037 * Model aware {@link AmetysObject} that can handle modifiable data.
038 */
039public interface ModifiableModelAwareDataAwareAmetysObject extends ModelAwareDataAwareAmetysObject, ModifiableModelAwareDataHolder, ModifiableAmetysObject
040{
041    @Override
042    public ModifiableModelAwareDataHolder getDataHolder();
043
044    @Override
045    public default ModifiableModelAwareComposite getComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
046    {
047        return getDataHolder().getComposite(compositePath);
048    }
049    
050    @Override
051    public default ModifiableModelAwareComposite getLocalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
052    {
053        return getDataHolder().getLocalComposite(compositePath);
054    }
055    
056    @Override
057    public default ModifiableModelAwareComposite getExternalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
058    {
059        return getDataHolder().getExternalComposite(compositePath);
060    }
061
062    @Override
063    public default ModifiableModelAwareRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
064    {
065        return getDataHolder().getRepeater(repeaterPath);
066    }
067    
068    @Override
069    public default ModifiableModelAwareRepeater getLocalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
070    {
071        return getDataHolder().getLocalRepeater(repeaterPath);
072    }
073    
074    @Override
075    public default ModifiableModelAwareRepeater getExternalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
076    {
077        return getDataHolder().getExternalRepeater(repeaterPath);
078    }
079
080    public default ModifiableModelAwareComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
081    {
082        return getDataHolder().getComposite(compositePath, createNew);
083    }
084    
085    public default ModifiableModelAwareComposite getLocalComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
086    {
087        return getDataHolder().getLocalComposite(compositePath, createNew);
088    }
089    
090    public default ModifiableModelAwareComposite getExternalComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
091    {
092        return getDataHolder().getExternalComposite(compositePath, createNew);
093    }
094
095    public default ModifiableModelAwareRepeater getRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
096    {
097        return getDataHolder().getRepeater(repeaterPath, createNew);
098    }
099    
100    public default ModifiableModelAwareRepeater getLocalRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
101    {
102        return getDataHolder().getLocalRepeater(repeaterPath, createNew);
103    }
104    
105    public default ModifiableModelAwareRepeater getExternalRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
106    {
107        return getDataHolder().getExternalRepeater(repeaterPath, createNew);
108    }
109    
110    public default <T extends SynchronizationResult> T synchronizeValues(Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException
111    {
112        return getDataHolder().synchronizeValues(values);
113    }
114    
115    public default <T extends SynchronizationResult> T synchronizeValues(Map<String, Object> values, SynchronizationContext context) throws UndefinedItemPathException, BadItemTypeException
116    {
117        return getDataHolder().synchronizeValues(values, context);
118    }
119    
120    public default <T extends SynchronizationResult> T synchronizeValues(ViewItemAccessor viewItemAccessor, Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException
121    {
122        return getDataHolder().synchronizeValues(viewItemAccessor, values);
123    }
124    
125    public default <T extends SynchronizationResult> T synchronizeValues(ViewItemAccessor viewItemAccessor, Map<String, Object> values, SynchronizationContext context) throws UndefinedItemPathException, BadItemTypeException
126    {
127        return getDataHolder().synchronizeValues(viewItemAccessor, values, context);
128    }
129
130    public default void setValue(String dataPath, Object value) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
131    {
132        getDataHolder().setValue(dataPath, value);
133    }
134    
135    public default void setLocalValue(String dataPath, Object localValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
136    {
137        getDataHolder().setLocalValue(dataPath, localValue);
138    }
139    
140    public default void setExternalValue(String dataPath, Object externalValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
141    {
142        getDataHolder().setExternalValue(dataPath, externalValue);
143    }
144    
145    public default void setStatus(String dataPath, ExternalizableDataStatus status) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
146    {
147        getDataHolder().setStatus(dataPath, status);
148    }
149    
150    public default void removeValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, UnknownDataException, BadDataPathCardinalityException
151    {
152        getDataHolder().removeValue(dataPath);
153    }
154
155    public default void removeLocalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, UnknownDataException, BadDataPathCardinalityException
156    {
157        getDataHolder().removeLocalValue(dataPath);
158    }
159
160    public default void removeExternalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, UnknownDataException, BadDataPathCardinalityException
161    {
162        getDataHolder().removeExternalValue(dataPath);
163    }
164    
165    default void removeExternalizableMetadataIfExists(String dataPath) throws IllegalArgumentException, BadItemTypeException, UndefinedItemPathException, BadDataPathCardinalityException
166    {
167        getDataHolder().removeExternalizableMetadataIfExists(dataPath);
168    }
169    
170    public default ModifiableRepositoryData getRepositoryData()
171    {
172        return getDataHolder().getRepositoryData();
173    }
174
175    public default Optional<? extends ModifiableModelAwareDataHolder> getParentDataHolder()
176    {
177        return getDataHolder().getParentDataHolder();
178    }
179    
180    public default ModifiableModelAwareDataHolder getRootDataHolder()
181    {
182        return getDataHolder().getRootDataHolder();
183    }
184}