001/* 002 * Copyright 2023 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.forms.enumerators; 017 018import java.util.Map; 019 020import org.ametys.runtime.i18n.I18nizableText; 021 022/** 023 * Enumerator for listing values with lazy loading.<p> 024 * Such values usually depends on environment (directory listing, DB table, ...). 025 * @param <T> Type of the values 026 */ 027public interface LazyEnumerator<T> 028{ 029 /** The pattern parameter key for search */ 030 public static final String PATTERN_PARAMETER_KEY = "pattern"; 031 032 /** The sort parameter key for search */ 033 public static final String SORT_PARAMETER_KEY = "sort"; 034 035 /** The lang parameter key for search */ 036 public static final String LANG_PARAMETER_KEY = "lang"; 037 038 /** 039 * Retrieves a single label from a value. 040 * @param value the value. 041 * @param contextParams the search contextual parameters 042 * @return the label or <code>null</code> if not found. 043 * @throws Exception if an error occurs. 044 */ 045 public I18nizableText getEntry(T value, Map<String, Object> contextParams) throws Exception; 046 047 /** 048 * Provides the enumerated values with their optional label. 049 * @param contextParams the search contextual parameters 050 * @return the enumerated values and their label. 051 * @throws Exception if an error occurs. 052 */ 053 public Map<T, I18nizableText> getTypedEntries(Map<String, Object> contextParams) throws Exception; 054 055 /** 056 * Provides the enumerated values with their optional label. 057 * @param contextParams the search contextual parameters 058 * @param limit the limit of entries 059 * @param paginationData the data to process pagination 060 * @return the enumerated values and their label. 061 * @throws Exception if an error occurs. 062 */ 063 public Map<T, I18nizableText> searchEntries(Map<String, Object> contextParams, int limit, Object paginationData) throws Exception; 064}