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.Collection;
019import java.util.List;
020import java.util.Map;
021import java.util.Optional;
022
023import org.xml.sax.ContentHandler;
024import org.xml.sax.SAXException;
025
026import org.ametys.plugins.repository.AmetysObject;
027import org.ametys.plugins.repository.data.DataComment;
028import org.ametys.plugins.repository.data.external.ExternalizableDataProvider.ExternalizableDataStatus;
029import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
030import org.ametys.plugins.repository.data.holder.group.ModelAwareComposite;
031import org.ametys.plugins.repository.data.holder.group.ModelAwareRepeater;
032import org.ametys.runtime.model.Model;
033import org.ametys.runtime.model.ModelItem;
034import org.ametys.runtime.model.ViewItemAccessor;
035import org.ametys.runtime.model.exception.BadDataPathCardinalityException;
036import org.ametys.runtime.model.exception.BadItemTypeException;
037import org.ametys.runtime.model.exception.UndefinedItemPathException;
038import org.ametys.runtime.model.type.DataContext;
039
040/**
041 * Model aware {@link AmetysObject} that can handle data.
042 */
043public interface ModelAwareDataAwareAmetysObject extends DataAwareAmetysObject, ModelAwareDataHolder
044{
045    @Override
046    public ModelAwareDataHolder getDataHolder();
047    
048    public default ModelAwareComposite getComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
049    {
050        return getDataHolder().getComposite(compositePath);
051    }
052    
053    public default ModelAwareComposite getLocalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
054    {
055        return getDataHolder().getLocalComposite(compositePath);
056    }
057    
058    public default ModelAwareComposite getExternalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
059    {
060        return getDataHolder().getExternalComposite(compositePath);
061    }
062
063    public default ModelAwareRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
064    {
065        return getDataHolder().getRepeater(repeaterPath);
066    }
067
068    public default ModelAwareRepeater getLocalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
069    {
070        return getDataHolder().getLocalRepeater(repeaterPath);
071    }
072
073    public default ModelAwareRepeater getExternalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
074    {
075        return getDataHolder().getExternalRepeater(repeaterPath);
076    }
077    
078    public default boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
079    {
080        return DataAwareAmetysObject.super.hasValue(dataPath);
081    }
082    
083    public default boolean hasLocalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
084    {
085        return getDataHolder().hasLocalValue(dataPath);
086    }
087    
088    public default boolean hasExternalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
089    {
090        return getDataHolder().hasExternalValue(dataPath);
091    }
092    
093    public default boolean hasValueOrEmpty(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
094    {
095        return DataAwareAmetysObject.super.hasValueOrEmpty(dataPath);
096    }
097    
098    public default boolean hasLocalValueOrEmpty(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
099    {
100        return getDataHolder().hasLocalValueOrEmpty(dataPath);
101    }
102    
103    public default boolean hasExternalValueOrEmpty(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
104    {
105        return getDataHolder().hasExternalValueOrEmpty(dataPath);
106    }
107    
108    default boolean hasComments(String dataName) throws IllegalArgumentException, UndefinedItemPathException
109    {
110        return getDataHolder().hasComments(dataName);
111    }
112
113    public default <T extends Object> T getValue(String dataPath, boolean allowMultiValuedPathSegments) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
114    {
115        return getDataHolder().getValue(dataPath, allowMultiValuedPathSegments);
116    }
117    
118    public default <T> T getValue(String dataPath, boolean useDefaultFromModel, T defaultValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
119    {
120        return getDataHolder().getValue(dataPath, useDefaultFromModel, defaultValue);
121    }
122    
123    public default <T> T getLocalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
124    {
125        return getDataHolder().getLocalValue(dataPath);
126    }
127    
128    public default <T> T getExternalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException
129    {
130        return getDataHolder().getExternalValue(dataPath);
131    }
132    
133    public default ExternalizableDataStatus getStatus(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadDataPathCardinalityException
134    {
135        return getDataHolder().getStatus(dataPath);
136    }
137    
138    default List<DataComment> getComments(String dataName) throws IllegalArgumentException, UndefinedItemPathException
139    {
140        return getDataHolder().getComments(dataName);
141    }
142    
143    @SuppressWarnings("unchecked")
144    public default Collection<? extends Model> getModel()
145    {
146        return (Collection<? extends Model>) getDataHolder().getModel();
147    }
148    
149    public default ModelItem getDefinition(String path) throws IllegalArgumentException, UndefinedItemPathException
150    {
151        return getDataHolder().getDefinition(path);
152    }
153    
154    default boolean hasDefinition(String path) throws IllegalArgumentException
155    {
156        return getDataHolder().hasDefinition(path);
157    }
158    
159    public default Collection<String> getDataNames()
160    {
161        return getDataHolder().getDataNames();
162    }
163    
164    public default void dataToSAX(ContentHandler contentHandler, ViewItemAccessor viewItemAccessor, DataContext context) throws SAXException, BadItemTypeException
165    {
166        getDataHolder().dataToSAX(contentHandler, viewItemAccessor, context);
167    }
168    
169    public default void dataToSAXForEdition(ContentHandler contentHandler, ViewItemAccessor viewItemAccessor, DataContext context) throws SAXException, BadItemTypeException
170    {
171        getDataHolder().dataToSAXForEdition(contentHandler, viewItemAccessor, context);
172    }
173    
174    public default Map<String, Object> dataToJSON(ViewItemAccessor viewItemAccessor, DataContext context) throws BadItemTypeException
175    {
176        return getDataHolder().dataToJSON(viewItemAccessor, context);
177    }
178    
179    public default Map<String, Object> dataToJSONForEdition(ViewItemAccessor viewItemAccessor, DataContext context) throws BadItemTypeException
180    {
181        return getDataHolder().dataToJSONForEdition(viewItemAccessor, context);
182    }
183    
184    public default Map<String, Object> dataToMap(ViewItemAccessor viewItemAccessor, DataContext context)
185    {
186        return getDataHolder().dataToMap(viewItemAccessor, context);
187    }
188    
189    public default Optional<? extends ModelAwareDataHolder> getParentDataHolder()
190    {
191        return getDataHolder().getParentDataHolder();
192    }
193    
194    public default ModelAwareDataHolder getRootDataHolder()
195    {
196        return getDataHolder().getRootDataHolder();
197    }
198}