Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 57b501c2 by tchemit at 2019-08-06T21:56:29Z Use Decorators from toolkit - - - - - 7 changed files: - dto/src/main/i18n/getters/java.getter - − dto/src/main/java/fr/ird/observe/dto/decoration/decorators/DataReferenceDecorator.java - − dto/src/main/java/fr/ird/observe/dto/decoration/decorators/ObserveDecorator.java - − dto/src/main/java/fr/ird/observe/dto/decoration/decorators/ReferentialReferenceDecorator.java - observe-i18n/src/main/i18n/translations/observe_en_GB.properties - observe-i18n/src/main/i18n/translations/observe_es_ES.properties - observe-i18n/src/main/i18n/translations/observe_fr_FR.properties Changes: ===================================== dto/src/main/i18n/getters/java.getter ===================================== @@ -17,8 +17,6 @@ observe.common.gps.activity observe.common.gps.gpsPoint observe.common.inconnu observe.common.no.unit -observe.common.nocode -observe.common.none observe.data.Data.baitHaulingStatus observe.data.Data.captain observe.data.Data.dataQuality ===================================== dto/src/main/java/fr/ird/observe/dto/decoration/decorators/DataReferenceDecorator.java deleted ===================================== @@ -1,71 +0,0 @@ -package fr.ird.observe.dto.decoration.decorators; - -/*- - * #%L - * ObServe :: Dto - * %% - * Copyright (C) 2008 - 2019 IRD, Code Lutin, Ultreia.io - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.dto.reference.DataDtoReference; -import fr.ird.observe.dto.reference.DtoReference; -import org.apache.commons.jxpath.JXPathContext; - -/** - * @author Kevin Morin (Code Lutin) - */ -public class DataReferenceDecorator<R extends DataDtoReference> extends ObserveDecorator<R> implements Cloneable { - - private static final long serialVersionUID = 1L; - - public DataReferenceDecorator(Class<R> type, String expression) { - super(type, expression); - } - - @Override - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { - - // assume all values are comparable - Comparable<Comparable<?>> value; - - Object contextBean = jxcontext.getContextBean(); - - if (contextBean instanceof DtoReference) { - - String[] tokens = token.split("/"); - - value = getValueFromReference(tokens, (DtoReference) contextBean, 0); - - if (value == null) { - value = (Comparable<Comparable<?>>) getDefaultNullValue(tokens[0]); - } - - } else { - value = super.getTokenValue(jxcontext, token); - } - - return value; - - } - - @Override - public String toString(Object bean) { - String result = super.toString(bean); - return result == null ? null : result.trim(); - } -} ===================================== dto/src/main/java/fr/ird/observe/dto/decoration/decorators/ObserveDecorator.java deleted ===================================== @@ -1,140 +0,0 @@ -/* - * #%L - * ObServe :: Dto - * %% - * Copyright (C) 2008 - 2019 IRD, Code Lutin, Ultreia.io - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ird.observe.dto.decoration.decorators; - -import fr.ird.observe.dto.reference.DtoReference; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.nuiton.decorator.MultiJXPathDecorator; - -import java.io.Serializable; - -import static io.ultreia.java4all.i18n.I18n.t; - -/** - * Abstract decorator for any complex decorator. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.4 - */ -public class ObserveDecorator<E> extends MultiJXPathDecorator<E> implements Cloneable { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Logger log = LogManager.getLogger(ObserveDecorator.class); - - public static final String DEFAULT_SEPARATOR = "##"; - - public static final String DEFAULT_SEPARATOR_REPLACEMENT = " - "; - - public ObserveDecorator(Class<E> internalClass, String expression) { - super(internalClass, expression, DEFAULT_SEPARATOR, DEFAULT_SEPARATOR_REPLACEMENT); - } - - public ObserveDecorator(Class<E> internalClass, String expression, String separator) { - super(internalClass, expression, DEFAULT_SEPARATOR, separator); - } - - @Override - public final Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { - // assume all values are comparable - Comparable<Comparable<?>> value; - - try { - - String[] tokens = token.split("/"); - - Object value0 = jxcontext.getValue(tokens[0]); - - if (value0 instanceof DtoReference) { - - value = getValueFromReference(tokens, (DtoReference<?, ?>) value0, 1); - - } else { - - value = (Comparable<Comparable<?>>) jxcontext.getValue(token); - } - - if (value == null) { - value = (Comparable<Comparable<?>>) getDefaultNullValue(token); - } - - } catch (Exception e) { - value = (Comparable<Comparable<?>>) getDefaultUndefinedValue(token); - } - - return value; - } - - protected Comparable<Comparable<?>> getValueFromReference(String[] tokens, DtoReference<?, ?> referenceBean, int startIndex) { - - for (int i = startIndex, max = tokens.length - 1; i < max; i++) { - - if (referenceBean.getPropertyNames().contains(tokens[i])) { - - Serializable propertyValue = referenceBean.getPropertyValue(tokens[i]); - - if (!(propertyValue instanceof DtoReference)) { - - return (Comparable<Comparable<?>>) getDefaultUndefinedValue(StringUtils.join(tokens, "/")); - - } - - referenceBean = (DtoReference<?, ?>) propertyValue; - } - } - - Comparable<Comparable<?>> value = null; - - String lastToken = tokens[tokens.length - 1]; - if (referenceBean.getPropertyNames().contains(lastToken)) { - value = referenceBean.getPropertyValue(lastToken); - } else { - value = referenceBean.get(lastToken); - } - - return value; - } - - protected Comparable<?> getDefaultUndefinedValue(String token) { - if (log.isDebugEnabled()) { - log.debug("No defined value for token [" + token + "]"); - } - return t("observe.common.none"); - } - - protected Comparable<?> getDefaultNullValue(String token) { - if (log.isDebugEnabled()) { - log.debug("Null value for token [" + token + "]"); - } - return t("observe.common.none"); - } - - -} ===================================== dto/src/main/java/fr/ird/observe/dto/decoration/decorators/ReferentialReferenceDecorator.java deleted ===================================== @@ -1,102 +0,0 @@ -package fr.ird.observe.dto.decoration.decorators; - -/*- - * #%L - * ObServe :: Dto - * %% - * Copyright (C) 2008 - 2019 IRD, Code Lutin, Ultreia.io - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.dto.reference.ReferentialDtoReference; -import fr.ird.observe.dto.referential.ReferentialDto; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.decorator.JXPathDecorator; - -import java.util.List; - -import static io.ultreia.java4all.i18n.I18n.t; - -/** - * @author Kevin Morin (Code Lutin) - */ -public class ReferentialReferenceDecorator<R extends ReferentialDtoReference> extends ObserveDecorator<R> implements Cloneable { - - private static final long serialVersionUID = 1L; - - public ReferentialReferenceDecorator(Class<R> type, String expression) { - super(type, expression); - for (int i = 0; i < nbToken; i++) { - String property = getProperty(i); - if (ReferentialDto.PROPERTY_CODE.equals(property)) { - - // On change le comparateur pour simuler le tri numérique si possible. - contexts[i].setComparator(new JXPathComparator<R>(property) { - - @Override - public void init(JXPathDecorator<R> decorator, List<R> datas) { - clear(); - for (R data : datas) { - JXPathContext jxcontext = JXPathContext.newContext(data); - Comparable<Comparable<?>> key = getTokenValue(jxcontext, ReferentialDto.PROPERTY_CODE); - // on passe en 000000x comme ça si on a des nombres, ils seront bien triés - String value = key == null ? "" : StringUtils.leftPad(key.toString(), 6, "0"); - valueCache.put(data, (Comparable) value); - } - } - }); - break; - } - } - } - - @Override - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { - - - // assume all values are comparable - Comparable<Comparable<?>> value; - - Object contextBean = jxcontext.getContextBean(); - - if (contextBean instanceof ReferentialDtoReference) { - - String[] tokens = token.split("/"); - - value = getValueFromReference(tokens, (ReferentialDtoReference) contextBean, 0); - - if (value == null) { - value = (Comparable<Comparable<?>>) getDefaultNullValue(tokens[0]); - } - - } else { - value = super.getTokenValue(jxcontext, token); - } - - return value; - - } - - @Override - protected Comparable<?> getDefaultNullValue(String token) { - if (token.equals("startDate") || token.equals("endDate")) { - return null; - } - return ReferentialDto.PROPERTY_CODE.equals(token) ? t("observe.common.nocode") : super.getDefaultNullValue(token); - } -} ===================================== observe-i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -426,8 +426,6 @@ observe.common.inconnu=Unknown observe.common.label=Label observe.common.lengthWeightFormula=Length weight formula observe.common.no.unit=No unit -observe.common.nocode=Nocode -observe.common.none=None observe.common.operation.resume=Summary of operations observe.common.resume=Summary observe.common.saveFile.overwrite=file alreayd exists, would you like to overwrite it? ===================================== observe-i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -426,8 +426,6 @@ observe.common.inconnu=desconocido observe.common.label=Texto observe.common.lengthWeightFormula=Relación de peso observe.common.no.unit=No unit \#TODO -observe.common.nocode=codigo ausente -observe.common.none=Ninguno observe.common.operation.resume=Resumen de operaciones observe.common.resume=Resumen de la configuración observe.common.saveFile.overwrite=El archivo ya existe. Quiere reemplazar lo ? ===================================== observe-i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -426,8 +426,6 @@ observe.common.inconnu=inconnu observe.common.label=Libellé observe.common.lengthWeightFormula=Relation Poids observe.common.no.unit=Pas d'unité -observe.common.nocode=code absent -observe.common.none=Aucun observe.common.operation.resume=Résumé des opérations observe.common.resume=Résumé de la configuration observe.common.saveFile.overwrite=Le fichier existe déjà. Voulez-vous le remplacer ? View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/57b501c2a3dde82446521e5962ea... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/57b501c2a3dde82446521e5962ea... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT