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 org.ametys.plugins.repository.AmetysObject;
019import org.ametys.plugins.repository.data.UnknownDataException;
020import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
021import org.ametys.plugins.repository.data.holder.group.impl.ModelLessComposite;
022import org.ametys.plugins.repository.data.holder.group.impl.ModelLessRepeater;
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;
027import org.ametys.runtime.model.type.ModelItemType;
028
029/**
030 * Model less {@link AmetysObject} that can handle data.
031 */
032public interface ModelLessDataAwareAmetysObject extends DataAwareAmetysObject, ModelLessDataHolder
033{
034    @Override
035    public ModelLessDataHolder getDataHolder();
036    
037    public default ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException
038    {
039        return getDataHolder().getComposite(compositePath);
040    }
041
042    public default ModelLessRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException
043    {
044        return getDataHolder().getRepeater(repeaterPath);
045    }
046    
047    public default boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException
048    {
049        return DataAwareAmetysObject.super.hasValue(dataPath);
050    }
051
052    public default <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
053    {
054        return getDataHolder().getValue(dataPath);
055    }
056    
057    public default <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
058    {
059        return getDataHolder().getValue(dataPath, defaultValue);
060    }
061
062    public default <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
063    {
064        return getDataHolder().getValueOfType(dataPath, dataTypeId);
065    }
066    
067    public default <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException
068    {
069        return getDataHolder().getValueOfType(dataPath, dataTypeId, defaultValue);
070    }
071    
072    public default boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException
073    {
074        return getDataHolder().isMultiple(dataPath);
075    }
076    
077    public default ModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException
078    {
079        return getDataHolder().getType(dataPath);
080    }
081}