001/* 002 * Copyright 2018 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.holder.group.impl; 017 018import java.io.IOException; 019import java.util.List; 020import java.util.Map; 021import java.util.Optional; 022 023import org.ametys.plugins.repository.data.DataComment; 024import org.ametys.plugins.repository.data.UnknownDataException; 025import org.ametys.plugins.repository.data.external.ExternalizableDataProvider.ExternalizableDataStatus; 026import org.ametys.plugins.repository.data.holder.DataHolder; 027import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder; 028import org.ametys.plugins.repository.data.holder.group.ModifiableComposite; 029import org.ametys.plugins.repository.data.holder.impl.DefaultModifiableModelAwareDataHolder; 030import org.ametys.plugins.repository.data.holder.values.SynchronizationContext; 031import org.ametys.plugins.repository.data.holder.values.SynchronizationResult; 032import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData; 033import org.ametys.runtime.model.ModelItemGroup; 034import org.ametys.runtime.model.ViewItemContainer; 035import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 036import org.ametys.runtime.model.exception.BadItemTypeException; 037import org.ametys.runtime.model.exception.UndefinedItemPathException; 038 039/** 040 * Class for modifiable model aware composites 041 */ 042public class ModifiableModelAwareComposite extends ModelAwareComposite implements ModifiableComposite, ModifiableModelAwareDataHolder 043{ 044 /** The modifiable repository data of this composite */ 045 protected ModifiableRepositoryData _modifiableRepositoryData; 046 047 /** the default implementation of a {@link ModifiableModelAwareDataHolder} to use */ 048 protected ModifiableModelAwareDataHolder _modifiableDefaultDataHolder; 049 050 /** 051 * Creates a modifiable model aware composite 052 * @param repositoryData the repository data of the composite 053 * @param parent the parent of the created {@link DataHolder} 054 * @param root the root {@link DataHolder} 055 * @param definition the definition of the composite 056 */ 057 public ModifiableModelAwareComposite(ModifiableRepositoryData repositoryData, ModifiableModelAwareDataHolder parent, ModifiableModelAwareDataHolder root, ModelItemGroup definition) 058 { 059 super(repositoryData, parent, root, definition); 060 _modifiableDefaultDataHolder = new DefaultModifiableModelAwareDataHolder(repositoryData, Optional.of(parent), Optional.of(root), definition); 061 _modifiableRepositoryData = repositoryData; 062 } 063 064 @Override 065 public ModifiableModelAwareComposite getComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 066 { 067 return getDefaultDataHolder().getComposite(compositePath); 068 } 069 070 @Override 071 public ModifiableModelAwareComposite getLocalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 072 { 073 return getDefaultDataHolder().getLocalComposite(compositePath); 074 } 075 076 @Override 077 public ModifiableModelAwareComposite getExternalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 078 { 079 return getDefaultDataHolder().getExternalComposite(compositePath); 080 } 081 082 @Override 083 public ModifiableModelAwareRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 084 { 085 return getDefaultDataHolder().getRepeater(repeaterPath); 086 } 087 088 @Override 089 public ModifiableModelAwareRepeater getLocalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 090 { 091 return getDefaultDataHolder().getLocalRepeater(repeaterPath); 092 } 093 094 @Override 095 public ModifiableModelAwareRepeater getExternalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 096 { 097 return getDefaultDataHolder().getExternalRepeater(repeaterPath); 098 } 099 100 public ModifiableModelAwareComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 101 { 102 return getDefaultDataHolder().getComposite(compositePath, createNew); 103 } 104 105 public ModifiableModelAwareComposite getLocalComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 106 { 107 return getDefaultDataHolder().getLocalComposite(compositePath, createNew); 108 } 109 110 public ModifiableModelAwareComposite getExternalComposite(String compositePath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 111 { 112 return getDefaultDataHolder().getExternalComposite(compositePath, createNew); 113 } 114 115 public ModifiableModelAwareRepeater getRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 116 { 117 return getDefaultDataHolder().getRepeater(repeaterPath, createNew); 118 } 119 120 public ModifiableModelAwareRepeater getLocalRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 121 { 122 return getDefaultDataHolder().getLocalRepeater(repeaterPath, createNew); 123 } 124 125 public ModifiableModelAwareRepeater getExternalRepeater(String repeaterPath, boolean createNew) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 126 { 127 return getDefaultDataHolder().getExternalRepeater(repeaterPath, createNew); 128 } 129 130 public <T extends SynchronizationResult> T synchronizeValues(Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException, IOException 131 { 132 return getDefaultDataHolder().synchronizeValues(values); 133 } 134 135 public <T extends SynchronizationResult> T synchronizeValues(Map<String, Object> values, SynchronizationContext context) throws UndefinedItemPathException, BadItemTypeException, IOException 136 { 137 return getDefaultDataHolder().synchronizeValues(values, context); 138 } 139 140 public <T extends SynchronizationResult> T synchronizeValues(ViewItemContainer viewItemContainer, Map<String, Object> values) throws UndefinedItemPathException, BadItemTypeException, IOException 141 { 142 return getDefaultDataHolder().synchronizeValues(viewItemContainer, values); 143 } 144 145 public <T extends SynchronizationResult> T synchronizeValues(ViewItemContainer viewItemContainer, Map<String, Object> values, SynchronizationContext context) throws UndefinedItemPathException, BadItemTypeException, IOException 146 { 147 return getDefaultDataHolder().synchronizeValues(viewItemContainer, values, context); 148 } 149 150 public void setValue(String dataPath, Object value) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 151 { 152 getDefaultDataHolder().setValue(dataPath, value); 153 } 154 155 public void setLocalValue(String dataPath, Object localValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 156 { 157 getDefaultDataHolder().setLocalValue(dataPath, localValue); 158 } 159 160 public void setExternalValue(String dataPath, Object externalValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 161 { 162 getDefaultDataHolder().setExternalValue(dataPath, externalValue); 163 } 164 165 public void setStatus(String dataPath, ExternalizableDataStatus status) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 166 { 167 getDefaultDataHolder().setStatus(dataPath, status); 168 } 169 170 public void setComments(String dataName, List<DataComment> comments) throws IllegalArgumentException, UndefinedItemPathException 171 { 172 getDefaultDataHolder().setComments(dataName, comments); 173 } 174 175 public void removeValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, UnknownDataException, BadDataPathCardinalityException 176 { 177 getDefaultDataHolder().removeValue(dataPath); 178 } 179 180 public void removeLocalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException 181 { 182 getDefaultDataHolder().removeLocalValue(dataPath); 183 } 184 185 public void removeExternalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException 186 { 187 getDefaultDataHolder().removeExternalValue(dataPath); 188 } 189 190 @Override 191 public Optional<? extends ModifiableModelAwareDataHolder> getParentDataHolder() 192 { 193 return getDefaultDataHolder().getParentDataHolder(); 194 } 195 196 @Override 197 public ModifiableModelAwareDataHolder getRootDataHolder() 198 { 199 return getDefaultDataHolder().getRootDataHolder(); 200 } 201 202 @Override 203 protected ModifiableModelAwareDataHolder getDefaultDataHolder() 204 { 205 return _modifiableDefaultDataHolder; 206 } 207 208 @Override 209 public ModifiableRepositoryData getRepositoryData() 210 { 211 return _modifiableRepositoryData; 212 } 213}