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.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.plugins.repository.AmetysObject; 025import org.ametys.plugins.repository.data.UnknownDataException; 026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 027import org.ametys.plugins.repository.data.holder.group.ModelLessComposite; 028import org.ametys.plugins.repository.data.type.ModelItemTypeExtensionPoint; 029import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 030import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 031import org.ametys.runtime.model.exception.BadItemTypeException; 032import org.ametys.runtime.model.exception.NotUniqueTypeException; 033import org.ametys.runtime.model.exception.UnknownTypeException; 034import org.ametys.runtime.model.type.DataContext; 035 036/** 037 * Model less {@link AmetysObject} that can handle data. 038 */ 039public interface ModelLessDataAwareAmetysObject extends DataAwareAmetysObject, ModelLessDataHolder 040{ 041 @Override 042 public ModelLessDataHolder getDataHolder(); 043 044 public default ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException 045 { 046 return getDataHolder().getComposite(compositePath); 047 } 048 049 public default boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 050 { 051 return DataAwareAmetysObject.super.hasValue(dataPath); 052 } 053 054 default boolean hasValue(String dataPath, String dataTypeId) throws IllegalArgumentException, BadDataPathCardinalityException 055 { 056 return getDataHolder().hasValue(dataPath, dataTypeId); 057 } 058 059 public default boolean hasValueOrEmpty(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 060 { 061 return DataAwareAmetysObject.super.hasValueOrEmpty(dataPath); 062 } 063 064 public default <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 065 { 066 return getDataHolder().getValue(dataPath); 067 } 068 069 public default <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 070 { 071 return getDataHolder().getValue(dataPath, defaultValue); 072 } 073 074 public default <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException 075 { 076 return getDataHolder().getValueOfType(dataPath, dataTypeId); 077 } 078 079 public default <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException 080 { 081 return getDataHolder().getValueOfType(dataPath, dataTypeId, defaultValue); 082 } 083 084 public default boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException 085 { 086 return getDataHolder().isMultiple(dataPath); 087 } 088 089 public default boolean isMultiple(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException 090 { 091 return getDataHolder().isMultiple(dataPath, dataTypeId); 092 } 093 094 public default RepositoryModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 095 { 096 return getDataHolder().getType(dataPath); 097 } 098 099 public default void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, UnknownTypeException, NotUniqueTypeException 100 { 101 getDataHolder().dataToSAX(contentHandler, context); 102 } 103 104 public default Map<String, Object> dataToJSON(DataContext context) throws UnknownTypeException, NotUniqueTypeException 105 { 106 return getDataHolder().dataToJSON(context); 107 } 108 109 public default boolean hasDifferences(Map<String, Object> values) throws UnknownTypeException, NotUniqueTypeException 110 { 111 return getDataHolder().hasDifferences(values); 112 } 113 114 public default Optional<? extends ModelLessDataHolder> getParentDataHolder() 115 { 116 return getDataHolder().getParentDataHolder(); 117 } 118 119 public default ModelLessDataHolder getRootDataHolder() 120 { 121 return getDataHolder().getRootDataHolder(); 122 } 123 124 default ModelItemTypeExtensionPoint getModelItemTypeExtensionPoint() 125 { 126 return getDataHolder().getModelItemTypeExtensionPoint(); 127 } 128}