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