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; 017 018import java.util.List; 019 020import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder; 021import org.ametys.plugins.repository.data.holder.values.SynchronizableRepeater; 022import org.ametys.plugins.repository.data.holder.values.SynchronizationContext; 023import org.ametys.plugins.repository.data.holder.values.SynchronizationResult; 024import org.ametys.runtime.model.ViewItemContainer; 025import org.ametys.runtime.model.exception.BadItemTypeException; 026import org.ametys.runtime.model.exception.UndefinedItemPathException; 027 028/** 029 * Interface for modifiable model aware repeaters 030 */ 031public interface ModifiableModelAwareRepeater extends ModelAwareRepeater, ModifiableRepeater 032{ 033 @Override 034 public List<? extends ModifiableModelAwareRepeaterEntry> getEntries(); 035 036 @Override 037 public ModifiableModelAwareRepeaterEntry getEntry(int position); 038 039 @Override 040 public ModifiableModelAwareRepeaterEntry addEntry(); 041 042 @Override 043 public ModifiableModelAwareRepeaterEntry addEntry(int position) throws IllegalArgumentException; 044 045 /** 046 * Synchronizes the given values with each repeater's entry 047 * @param <T> the type of the {@link SynchronizationResult} 048 * @param viewItemContainer The {@link ViewItemContainer} containing all items to synchronize 049 * @param repeaterValues the values of the repeater to synchronize 050 * @return the {@link SynchronizationResult} 051 * @throws UndefinedItemPathException if an entry's key refers to a data that is not defined by the model 052 * @throws BadItemTypeException if the type defined by the model of one entry's key doesn't match the corresponding value 053 */ 054 public default <T extends SynchronizationResult> T synchronizeValues(ViewItemContainer viewItemContainer, SynchronizableRepeater repeaterValues) throws UndefinedItemPathException, BadItemTypeException 055 { 056 return synchronizeValues(viewItemContainer, repeaterValues, SynchronizationContext.newInstance()); 057 } 058 059 /** 060 * Synchronizes the given values with each repeater's entry 061 * @param <T> the type of the {@link SynchronizationResult} 062 * @param viewItemContainer The {@link ViewItemContainer} containing all items to synchronize 063 * @param repeaterValues the values of the repeater to synchronize 064 * @param context the context of the synchronization 065 * @return the {@link SynchronizationResult} 066 * @throws UndefinedItemPathException if an entry's key refers to a data that is not defined by the model 067 * @throws BadItemTypeException if the type defined by the model of one entry's key doesn't match the corresponding value 068 */ 069 public <T extends SynchronizationResult> T synchronizeValues(ViewItemContainer viewItemContainer, SynchronizableRepeater repeaterValues, SynchronizationContext context) throws UndefinedItemPathException, BadItemTypeException; 070 071 @Override 072 public ModifiableModelAwareDataHolder getParentDataHolder(); 073 074 @Override 075 public ModifiableModelAwareDataHolder getRootDataHolder(); 076}