CodeValueFunctions.java
/*
* Copyright 2026 Global Crop Diversity Trust
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root folder or http://www.apache.org/licenses/LICENSE-2.0
*/
package org.gringlobal.custom.jasper;
import org.gringlobal.component.elastic.AppContextHelper;
import org.springframework.context.i18n.LocaleContextHolder;
import net.sf.jasperreports.functions.annotations.Function;
import net.sf.jasperreports.functions.annotations.FunctionCategories;
import net.sf.jasperreports.functions.annotations.FunctionParameter;
import net.sf.jasperreports.functions.annotations.FunctionParameters;
/**
* JasperReports helper functions.
*/
@FunctionCategories({ CustomFunctionCategory.class })
public class CodeValueFunctions {
/**
* Returns the Code Value {@code title} in the active language of the report.
*
* @param groupName Code Value <b>group name</b>
* @param value The value
* @return Title of the code value in selected language, or {@code "?? " + code} if not available.
*/
@Function("CODEVALUE")
@FunctionParameters({ @FunctionParameter("groupName"), @FunctionParameter("value")})
public static String CODEVALUE(String groupName, String value) {
var translatedCodeValue = AppContextHelper.findTitleOfCodeValueByLang(groupName, value, LocaleContextHolder.getLocale());
if (translatedCodeValue.isPresent()) {
return translatedCodeValue.get().title;
}
return "?? " + value; // "?? SD"
}
// /**
// * Returns the Code Value {@code title} in selected language.
// *
// * @param groupName Code Value <b>group name</b>
// * @param value The value
// * @param locale Target language locale (e.g. {@code java.util.Locale.FRENCH})
// * @return Title of the code value in selected language, or {@code "?? " + code} if not available.
// */
// @Function("CODEVALUE")
// @FunctionParameters({ @FunctionParameter("groupName"), @FunctionParameter("value"), @FunctionParameter("locale")})
// public static String CODEVALUE(String groupName, String value, Locale locale) {
// var translatedCodeValue = AppContextHelper.findTitleOfCodeValueByLang(groupName, value, locale);
// if (translatedCodeValue.isPresent()) {
// return translatedCodeValue.get().title;
// }
// return "?? " + value; // "?? SD"
// }
}