Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 642401fc by Tony CHEMIT at 2018-09-23T21:14:58Z fix desactivate referential generated sql - - - - - f3379ac9 by Tony CHEMIT at 2018-09-23T21:15:11Z Fix validation result serializatoin on server mode - - - - - 649d3f81 by Tony CHEMIT at 2018-09-23T21:35:02Z Les rapports ne fonctionnent pas très bien - Closes #1081 - - - - - f3bbfcf7 by Tony CHEMIT at 2018-09-23T21:35:23Z remove some default shortcuts on some uis (but it still does not work for some of them)... - - - - - e6863e0f by Tony CHEMIT at 2018-09-23T21:39:27Z optimize dependencies - - - - - 25 changed files: - client/src/main/java/fr/ird/observe/client/ui/admin/config/SelectDataModel.java - client/src/main/java/fr/ird/observe/client/ui/admin/report/ReportUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateConfigUI.jcss - client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/dcprefs/FloatingObjectPresetsUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUIHandler.java - services-client/src/test/java/fr/ird/observe/services/client/service/actions/report/AbstractReportServiceClientTest.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/report/ReportServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/DisableSqlStatementGenerator.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/validate/ValidateServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/validate/ValidationMessageDetector.java - services-local/src/test/java/fr/ird/observe/services/local/service/actions/report/AbstractReportServiceLocalTest.java - services-local/src/test/java/fr/ird/observe/services/local/service/actions/report/ReportNonTargetDistributionLengthsTest.java - services/pom.xml - services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java - services/src/main/java/fr/ird/observe/services/gson/ReportVariableAdapter.java - + services/src/main/java/fr/ird/observe/services/gson/ValidationResultDtoAdapter.java - services/src/main/java/fr/ird/observe/services/service/actions/report/ReportBuilder.java - services/src/main/java/fr/ird/observe/services/service/actions/report/ReportRequest.java - + services/src/main/java/fr/ird/observe/services/service/actions/validate/DataValidationResult.java - + services/src/main/java/fr/ird/observe/services/service/actions/validate/ReferentialValidationResult.java - services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateService.java - services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidationResult.java - services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidationResultDto.java - services/src/main/resources/observe-reports.properties Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/config/SelectDataModel.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.admin.config; * 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>. @@ -30,14 +30,14 @@ import fr.ird.observe.client.ui.admin.AdminUIModel; import fr.ird.observe.client.ui.admin.report.ReportModel; import fr.ird.observe.client.ui.tree.selection.SelectionTreeModel; import fr.ird.observe.dto.IdDto; +import fr.ird.observe.dto.IdHelper; import fr.ird.observe.dto.ObserveModelType; import fr.ird.observe.dto.data.longline.TripLonglineReference; import fr.ird.observe.dto.data.seine.TripSeineReference; import fr.ird.observe.dto.reference.DataDtoReference; import fr.ird.observe.dto.reference.DataDtoReferenceSet; -import fr.ird.observe.spi.DtoModelClasses; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -102,10 +102,8 @@ public class SelectDataModel extends AdminActionModel { // on doit aussi calculer les ids des marées distantes ObserveSwingDataSource safeCentralSource = uiModel.getConfigModel().getSafeCentralSource(true); - List<DataDtoReference<?, ?>> existingTrip = new ArrayList<>(); - DataDtoReferenceSet<TripSeineReference> tripSeineSet = safeCentralSource.getTripSeineService().getAllTripSeine(); - existingTrip.addAll(tripSeineSet.toSet()); + List<DataDtoReference<?, ?>> existingTrip = new ArrayList<>(tripSeineSet.toSet()); DataDtoReferenceSet<TripLonglineReference> tripLonglineSet = safeCentralSource.getTripLonglineService().getAllTripLongline(); existingTrip.addAll(tripLonglineSet.toSet()); @@ -131,7 +129,7 @@ public class SelectDataModel extends AdminActionModel { return null; } DataDtoReference dto = data.iterator().next(); - if (DtoModelClasses.isTrip(dto)) { + if (IdHelper.isTrip(dto)) { return dto; } @@ -143,7 +141,7 @@ public class SelectDataModel extends AdminActionModel { ImmutableSet.Builder<DataDtoReference> result = ImmutableSet.builder(); Set<DataDtoReference<?, ?>> data = getSelectionDataModel().getSelectedData(); for (DataDtoReference<?, ?> datum : data) { - if (DtoModelClasses.isTrip(datum)) { + if (IdHelper.isTrip(datum)) { result.add(datum); } } @@ -208,6 +206,7 @@ public class SelectDataModel extends AdminActionModel { public boolean validate(AdminUIModel uiModel) { boolean validate = true; + boolean empty = selectionDataModel.isSelectionEmpty(); if (uiModel.containsOperation(AdminStep.VALIDATE)) { @@ -216,7 +215,6 @@ public class SelectDataModel extends AdminActionModel { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionDataModel.isSelectionEmpty(); validate = !empty; } } @@ -227,7 +225,6 @@ public class SelectDataModel extends AdminActionModel { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionDataModel.isSelectionEmpty(); validate = !empty; } } @@ -238,7 +235,6 @@ public class SelectDataModel extends AdminActionModel { if (validate) { // il faut au moins une donnee de selectionnee - boolean empty = selectionDataModel.isSelectionEmpty(); validate = !empty; } } @@ -248,9 +244,8 @@ public class SelectDataModel extends AdminActionModel { validate &= uiModel.validate(AdminStep.CONFIG); if (validate) { - // il faut exactement une Trip de selectionnee - int selectedCount = selectionDataModel.getSelectedCount(); - validate = selectedCount > 0; + // il faut au moins une donnee de selectionnee + validate = !empty; } } ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/report/ReportUIHandler.java ===================================== @@ -8,12 +8,12 @@ * 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>. @@ -30,8 +30,6 @@ import fr.ird.observe.client.ui.admin.config.ConfigUI; import fr.ird.observe.client.ui.util.UIHelper; import fr.ird.observe.dto.ObserveModelType; import fr.ird.observe.dto.data.DataDto; -import fr.ird.observe.dto.decoration.ObserveI18nDecoratorHelper; -import fr.ird.observe.dto.decoration.ObserveI18nLabelsBuilder; import fr.ird.observe.dto.reference.DataDtoReference; import fr.ird.observe.dto.referential.ReferentialDto; import fr.ird.observe.services.service.actions.report.DataMatrix; @@ -39,8 +37,8 @@ import fr.ird.observe.services.service.actions.report.Report; import fr.ird.observe.services.service.actions.report.ReportService; import fr.ird.observe.services.service.actions.report.ReportVariable; import fr.ird.observe.spi.DtoModelHelper; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.decorator.Decorator; import org.nuiton.decorator.JXPathDecorator; import org.nuiton.jaxx.runtime.context.JAXXInitialContext; @@ -331,27 +329,16 @@ public class ReportUIHandler extends AdminTabUIHandler<ReportUI> implements UIHa combo.setShowReset(true); variablesPanel.add(combo); - log.info("init variable: " + variable); - Class variableType = variable.getType(); Decorator decorator; - Class referenceType; - if (ReferentialDto.class.isAssignableFrom(variableType) && !universe.isEmpty()) { - referenceType = DtoModelHelper.fromReferentialDto(variableType).toReferenceType(); - decorator = getDecoratorService().getReferentialReferenceDecorator(referenceType); - } else if (DataDto.class.isAssignableFrom(variableType) && !universe.isEmpty()) { - referenceType = DtoModelHelper.fromDataDto(variableType).toReferenceType(); - decorator = getDecoratorService().getDataReferenceDecorator(referenceType); + if (ReferentialDto.class.isAssignableFrom(variable.getType()) && !universe.isEmpty()) { + Class type = DtoModelHelper.fromReferentialDto(variable.getType()).toReferenceType(); + decorator = getDecoratorService().getReferentialReferenceDecorator(type); + } else if (DataDto.class.isAssignableFrom(variable.getType()) && !universe.isEmpty()) { + Class type = DtoModelHelper.fromDataDto(variable.getType()).toReferenceType(); + decorator = getDecoratorService().getDataReferenceDecorator(type); } else { - referenceType = variableType; - decorator = getDecoratorService().getDecoratorByType(variableType); + decorator = getDecoratorService().getDecoratorByType(variable.getType()); } - log.info("decorator: " + decorator); - combo.setI18nPrefix("observe.common."); - combo.setBeanType(referenceType); - combo.setI18nLabelBuilder(ObserveI18nLabelsBuilder.createFromReferenceType(referenceType)); - String entityLabel = t(ObserveI18nDecoratorHelper.getTypeI18nKey(variableType)); - combo.setPopupTitleText(t("observe.common.ReferentialDto.type", entityLabel)); - combo.init((JXPathDecorator<Object>) decorator, universe); JComboBox jComboBox = combo.getCombobox(); jComboBox.putClientProperty(VARIABLE_NAME, variableName); ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateConfigUI.jcss ===================================== @@ -68,19 +68,19 @@ #ERROR { _value:{NuitonValidatorScope.ERROR}; - text:{NuitonValidatorScope.ERROR.getLabel()}; + text:{t(NuitonValidatorScope.ERROR.getLabel())}; selected:{getHandler().isScopeSelected(validateModel.getScopes(), ERROR)}; } #WARNING { _value:{NuitonValidatorScope.WARNING}; - text:{NuitonValidatorScope.WARNING.getLabel()}; + text:{t(NuitonValidatorScope.WARNING.getLabel())}; selected:{getHandler().isScopeSelected(validateModel.getScopes(), WARNING)}; } #INFO { _value:{NuitonValidatorScope.INFO}; - text:{NuitonValidatorScope.INFO.getLabel()}; + text:{t(NuitonValidatorScope.INFO.getLabel())}; selected:{getHandler().isScopeSelected(validateModel.getScopes(), INFO)}; } ===================================== client/src/main/java/fr/ird/observe/client/ui/admin/validate/ValidateUIHandler.java ===================================== @@ -6,15 +6,15 @@ * %% * 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 + * 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 + * + * 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% @@ -43,6 +43,7 @@ import fr.ird.observe.dto.reference.DataDtoReference; import fr.ird.observe.dto.reference.DtoReference; import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.services.service.actions.validate.DataValidationRequest; +import fr.ird.observe.services.service.actions.validate.DataValidationResult; import fr.ird.observe.services.service.actions.validate.ReferentialValidationRequest; import fr.ird.observe.services.service.actions.validate.ValidateService; import fr.ird.observe.services.service.actions.validate.ValidationResult; @@ -50,8 +51,8 @@ import fr.ird.observe.services.service.actions.validate.ValidationResultDto; import fr.ird.observe.services.service.actions.validate.ValidationResultDtoMessage; import fr.ird.observe.services.validation.ValidatorDto; import org.apache.commons.io.FileUtils; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.jaxx.runtime.context.JAXXInitialContext; import org.nuiton.jaxx.runtime.spi.UIHandler; import org.nuiton.jaxx.runtime.swing.wizard.ext.WizardState; @@ -410,7 +411,7 @@ public class ValidateUIHandler extends AdminTabUIHandler<ValidateUI> implements mainRequest.setValidationLengthWeightEnable(config.getValidationLengthWeightEnable()); mainRequest.setSeineBycatchObservedSystemConfig(config.getSeineBycatchObservedSystem()); - ValidationResult.Builder<DataValidationRequest> resultBuilder = ValidationResult.builder(ReferentialLocale.valueOf(config.getDbLocale()), mainRequest); + ValidationResult.Builder<DataValidationRequest, DataValidationResult> resultBuilder = DataValidationResult.builder(ReferentialLocale.valueOf(config.getDbLocale()), mainRequest); for (DataDtoReference<?, ?> dataReference : dataModel.getSelectedData()) { ===================================== client/src/main/java/fr/ird/observe/client/ui/dcprefs/FloatingObjectPresetsUIHandler.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.dcprefs; * 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>. @@ -33,8 +33,12 @@ import org.nuiton.jaxx.runtime.swing.renderer.DecoratorListCellRenderer; import javax.swing.AbstractButton; import javax.swing.DefaultListModel; +import javax.swing.JComponent; +import javax.swing.JSplitPane; +import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import java.awt.BorderLayout; +import java.awt.event.KeyEvent; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -69,6 +73,8 @@ public class FloatingObjectPresetsUIHandler implements UIHandler<FloatingObjectP if (o instanceof AbstractButton) { init(actionMap, (AbstractButton) o); + } else if (o instanceof JSplitPane) { + init((JSplitPane) o); } } @@ -119,6 +125,12 @@ public class FloatingObjectPresetsUIHandler implements UIHandler<FloatingObjectP UIHelper.askFocus(ui.getQuitAction()); } + + protected void init(JSplitPane editor) { + editor.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none"); + } + protected void init(ObserveActionMap actionMap, AbstractButton editor) { String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); if (actionId == null) { ===================================== client/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUIHandler.java ===================================== @@ -29,8 +29,8 @@ import fr.ird.observe.client.ui.util.UIHelper; import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration; import fr.ird.observe.dto.presets.ServerDataSourceConfiguration; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.decorator.Decorator; import org.nuiton.jaxx.runtime.spi.UIHandler; import org.nuiton.jaxx.runtime.swing.renderer.DecoratorListCellRenderer; @@ -40,8 +40,11 @@ import javax.swing.ActionMap; import javax.swing.DefaultListModel; import javax.swing.InputMap; import javax.swing.JComponent; +import javax.swing.JSplitPane; +import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import java.awt.BorderLayout; +import java.awt.event.KeyEvent; import java.util.List; import java.util.Objects; @@ -79,6 +82,8 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { if (o instanceof AbstractButton) { init(inputMap, actionMap, (AbstractButton) o); + } else if (o instanceof JSplitPane) { + init((JSplitPane) o); } } @@ -190,6 +195,11 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { } + protected void init(JSplitPane editor) { + editor.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none"); + } + protected void init(InputMap inputMap, ActionMap actionMap, AbstractButton editor) { String actionId = (String) editor.getClientProperty(OBSERVE_ACTION); if (actionId == null) { ===================================== services-client/src/test/java/fr/ird/observe/services/client/service/actions/report/AbstractReportServiceClientTest.java ===================================== @@ -8,12 +8,12 @@ * 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>. ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/report/ReportServiceLocal.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.actions.report; * 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>. @@ -43,6 +43,10 @@ import fr.ird.observe.services.service.actions.report.ReportVariable; import fr.ird.observe.spi.DbModelHelper; import fr.ird.observe.spi.context.DataDtoEntityContext; import fr.ird.observe.spi.context.ReferentialDtoEntityContext; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import java.awt.Dimension; import java.awt.Point; import java.io.Serializable; @@ -54,9 +58,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; -import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; /** * @author Tony Chemit - dev@tchemit.fr @@ -651,6 +652,7 @@ public class ReportServiceLocal extends ObserveServiceLocal implements ReportSer AbstractObserveTopiaDao dao = (AbstractObserveTopiaDao) getTopiaPersistenceContext().getDao(TripSeine.class); + log.info(String.format("Request: %s, params: %s", request, paramsFixes)); return dao.findAllFromHql(request, paramsFixes); } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/DisableSqlStatementGenerator.java ===================================== @@ -43,7 +43,7 @@ public class DisableSqlStatementGenerator { } public String generateSql(String sourceId) { - return TopiaSqlStatements.generateUpdateStatement(metadataEntity, sourceId, "enabled = false, topiaVersion = topiaVersion + 1"); + return TopiaSqlStatements.generateUpdateStatement(metadataEntity, sourceId, "status = 0, topiaVersion = topiaVersion + 1"); } } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/validate/ValidateServiceLocal.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.actions.validate; * 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>. @@ -40,16 +40,17 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.persistence.Entities; import fr.ird.observe.services.local.service.ObserveServiceLocal; import fr.ird.observe.services.service.actions.validate.DataValidationRequest; +import fr.ird.observe.services.service.actions.validate.DataValidationResult; import fr.ird.observe.services.service.actions.validate.ReferentialValidationRequest; +import fr.ird.observe.services.service.actions.validate.ReferentialValidationResult; import fr.ird.observe.services.service.actions.validate.ValidateService; import fr.ird.observe.services.service.actions.validate.ValidationRequest; -import fr.ird.observe.services.service.actions.validate.ValidationResult; import fr.ird.observe.services.service.referential.ReferentialService; import fr.ird.observe.services.validation.ServiceValidationContext; import fr.ird.observe.services.validation.ValidatorsMap; import fr.ird.observe.spi.DbModelHelper; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.validator.xwork2.XWork2ValidatorUtil; import java.util.List; @@ -69,12 +70,12 @@ public class ValidateServiceLocal extends ObserveServiceLocal implements Validat private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(5); @Override - public ValidationResult<ReferentialValidationRequest> validateReferential(ReferentialValidationRequest request) { + public ReferentialValidationResult validateReferential(ReferentialValidationRequest request) { - Future<ValidationResult<ReferentialValidationRequest>> future = EXECUTOR_SERVICE.submit(() -> { + Future<ReferentialValidationResult> future = EXECUTOR_SERVICE.submit(() -> { ReferentialLocale referentialLocale = getReferentialLocale(); - ValidationResult.Builder<ReferentialValidationRequest> resultBuilder = ValidationResult.builder(referentialLocale, request); + ReferentialValidationResult.Builder<ReferentialValidationRequest, ReferentialValidationResult> resultBuilder = ReferentialValidationResult.builder(referentialLocale, request); ServiceValidationContext validationContext = createServiceValidationContext(request); @@ -99,12 +100,12 @@ public class ValidateServiceLocal extends ObserveServiceLocal implements Validat } @Override - public ValidationResult<DataValidationRequest> validateData(DataValidationRequest request) { + public DataValidationResult validateData(DataValidationRequest request) { - Future<ValidationResult<DataValidationRequest>> future = EXECUTOR_SERVICE.submit(() -> { + Future<DataValidationResult> future = EXECUTOR_SERVICE.submit(() -> { ReferentialLocale referentialLocale = getReferentialLocale(); - ValidationResult.Builder<DataValidationRequest> resultBuilder = ValidationResult.builder(referentialLocale, request); + DataValidationResult.Builder<DataValidationRequest, DataValidationResult> resultBuilder = DataValidationResult.builder(referentialLocale, request); ServiceValidationContext validationContext = createServiceValidationContext(request); ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/validate/ValidationMessageDetector.java ===================================== @@ -41,6 +41,7 @@ import fr.ird.observe.dto.navigation.select.ObserveSelectModel; import fr.ird.observe.dto.reference.DtoReference; import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.entities.ObserveEntity; +import fr.ird.observe.services.service.actions.validate.ReferentialValidationResult; import fr.ird.observe.services.service.actions.validate.ValidationResult; import fr.ird.observe.services.validation.ServiceValidationContext; import fr.ird.observe.services.validation.ValidatorsMap; @@ -162,7 +163,7 @@ class ValidationMessageDetector implements SimpleBeanValidatorListener { static ValidationMessageDetector forReferential(ValidatorsMap validators, ServiceValidationContext validationDataContext, ReferentialLocale referentialLocale, - ValidationResult.Builder resultBuilder) { + ReferentialValidationResult.Builder resultBuilder) { ImmutableMap.Builder<Class, EntityInterceptor> interceptorsBuilder = ImmutableMap.builder(); ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/actions/report/AbstractReportServiceLocalTest.java ===================================== @@ -6,15 +6,15 @@ * %% * 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 + * 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 + * + * 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% @@ -34,8 +34,8 @@ import fr.ird.observe.services.service.actions.report.ReportVariable; import fr.ird.observe.test.DatabaseName; import fr.ird.observe.test.ObserveFixtures; import fr.ird.observe.test.spi.DatabaseNameConfiguration; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -58,15 +58,45 @@ public abstract class AbstractReportServiceLocalTest extends ServiceLocalTestSup /** Logger */ private static final Logger log = LogManager.getLogger(AbstractReportServiceLocalTest.class); - - protected ReportService service; - /** La liste de tous les reports connus. */ protected static List<Report> reports; - + protected ReportService service; /** Le report à tester. */ private Report report; + protected static Report getReport(Logger log, String reportId) throws IOException { + if (reports == null) { + + URL reportLocation = + AbstractReportServiceLocalTest.class.getResource("/observe-reports.properties"); + + if (log.isInfoEnabled()) { + log.info("Loading reports from " + reportLocation); + } + + ReportBuilder builder = new ReportBuilder(); + + reports = builder.load(reportLocation); + + builder.clear(); + + Assert.assertNotNull(reports); + Assert.assertFalse(reports.isEmpty()); + } + + Report result = null; + // recuperation du report à tester + for (Report report : reports) { + if (reportId.equals(report.getId())) { + result = report; + break; + } + } + + Assert.assertNotNull("Could not find report with id " + reportId, reports); + return result; + } + protected abstract String getReportId(); @Before @@ -83,7 +113,6 @@ public abstract class AbstractReportServiceLocalTest extends ServiceLocalTestSup } - /** * L'unique test à lancer. * <p> @@ -92,7 +121,6 @@ public abstract class AbstractReportServiceLocalTest extends ServiceLocalTestSup * <li>la syntaxe du report via {@link #testReportSyntax(Report)}</li> * <li>le résultat du report via {@link #testReportResult(DataMatrix)}</li> * </ul> - * */ @Test public final void testReport() { @@ -149,39 +177,6 @@ public abstract class AbstractReportServiceLocalTest extends ServiceLocalTestSup protected abstract void testReportResult(DataMatrix result); - protected static Report getReport(Logger log, String reportId) throws IOException { - if (reports == null) { - - URL reportLocation = - AbstractReportServiceLocalTest.class.getResource("/observe-reports.properties"); - - if (log.isInfoEnabled()) { - log.info("Loading reports from " + reportLocation); - } - - ReportBuilder builder = new ReportBuilder(); - - reports = builder.load(reportLocation); - - builder.clear(); - - Assert.assertNotNull(reports); - Assert.assertFalse(reports.isEmpty()); - } - - Report result = null; - // recuperation du report à tester - for (Report report : reports) { - if (reportId.equals(report.getId())) { - result = report; - break; - } - } - - Assert.assertNotNull("Could not find report with id " + reportId, reports); - return result; - } - protected void assertReportName(Report report, String name, String description) { @@ -234,12 +229,12 @@ public abstract class AbstractReportServiceLocalTest extends ServiceLocalTestSup protected void assertResultRow(DataMatrix result, int rowId, Object... row) { Object[] actualRow = result.getData()[rowId]; - int index=0; + int index = 0; for (Object o : actualRow) { - if (o==null) { + if (o == null) { Assert.assertEquals(row[index++], o); - }else { - Assert.assertArrayEquals(row[index++].toString().split("\\s*\\n\\s*"),o.toString().split("\\s*\\n\\s*")); + } else { + Assert.assertArrayEquals(row[index++].toString().split("\\s*\\n\\s*"), o.toString().split("\\s*\\n\\s*")); } } //Assert.assertArrayEquals(row, actualRow); ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/actions/report/ReportNonTargetDistributionLengthsTest.java ===================================== @@ -6,15 +6,15 @@ * %% * 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 + * 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 + * + * 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% ===================================== services/pom.xml ===================================== @@ -97,10 +97,6 @@ <groupId>io.ultreia.java4all.jaxx</groupId> <artifactId>jaxx-widgets-gis</artifactId> </dependency> - <dependency> - <groupId>io.ultreia.java4all</groupId> - <artifactId>java-lang</artifactId> - </dependency> <!-- XWork --> <dependency> ===================================== services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java ===================================== @@ -25,6 +25,7 @@ package fr.ird.observe.services.gson; import com.google.gson.GsonBuilder; import fr.ird.observe.services.service.actions.consolidate.dcp.FloatingObjectModification; import fr.ird.observe.services.service.actions.report.ReportVariable; +import fr.ird.observe.services.service.actions.validate.ValidationResultDto; import io.ultreia.java4all.http.HResponseError; import io.ultreia.java4all.http.HResponseErrorAdapter; @@ -51,7 +52,7 @@ public class ObserveDtoGsonSupplier extends ObserveDtoGsonSupplierSupport { gsonBuilder.registerTypeAdapter(ReportVariable.class, new ReportVariableAdapter()); gsonBuilder.registerTypeAdapter(HResponseError.class, new HResponseErrorAdapter()); gsonBuilder.registerTypeAdapter(FloatingObjectModification.class, new FloatingObjectModificationAdapter()); - + gsonBuilder.registerTypeAdapter(ValidationResultDto.class, new ValidationResultDtoAdapter()); } return gsonBuilder; ===================================== services/src/main/java/fr/ird/observe/services/gson/ReportVariableAdapter.java ===================================== @@ -29,10 +29,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import fr.ird.observe.dto.data.DataDto; -import fr.ird.observe.dto.reference.DataDtoReference; -import fr.ird.observe.dto.reference.ReferentialDtoReference; import fr.ird.observe.dto.referential.ReferentialDto; import fr.ird.observe.services.service.actions.report.ReportVariable; +import fr.ird.observe.spi.DtoModelHelper; import java.lang.reflect.Type; import java.util.Set; @@ -55,10 +54,10 @@ public class ReportVariableAdapter implements JsonDeserializer<ReportVariable> { Class valueType = type; if (DataDto.class.isAssignableFrom(type)) { - valueType = DataDtoReference.class; + valueType = DtoModelHelper.fromDataDto((Class) type).toReferenceType(); } if (ReferentialDto.class.isAssignableFrom(type)) { - valueType = ReferentialDtoReference.class; + valueType = DtoModelHelper.fromReferentialDto((Class) type).toReferenceType(); } JsonElement valuesJson = reportVariableJson.get(ReportVariable.PROPERTY_VALUES); ===================================== services/src/main/java/fr/ird/observe/services/gson/ValidationResultDtoAdapter.java ===================================== @@ -0,0 +1,66 @@ +package fr.ird.observe.services.gson; + +/* + * #%L + * ObServe :: Services API + * %% + * Copyright (C) 2008 - 2018 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 com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import fr.ird.observe.dto.reference.DtoReference; +import fr.ird.observe.gson.ImmutableSetAdapter; +import fr.ird.observe.services.service.actions.validate.ValidationResultDto; +import fr.ird.observe.services.service.actions.validate.ValidationResultDtoMessage; + +import java.lang.reflect.Type; +import java.util.Set; + +/** + * Created by tchemit on 23/09/2018. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ValidationResultDtoAdapter implements JsonDeserializer<ValidationResultDto>, JsonSerializer<ValidationResultDto> { + + @Override + public ValidationResultDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject reportVariableJson = json.getAsJsonObject(); + Class<?> type = context.deserialize(reportVariableJson.get("type"), Class.class); + DtoReference dtoReference = context.deserialize(reportVariableJson.get("dtoReference"), type); + Set<ValidationResultDtoMessage> messages = context.deserialize(reportVariableJson.get("messages"), ImmutableSetAdapter.setOf(TypeToken.of(ValidationResultDtoMessage.class)).getType()); + return new ValidationResultDto(dtoReference, ImmutableSet.copyOf(messages)); + } + + @Override + public JsonElement serialize(ValidationResultDto src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject result = new JsonObject(); + result.add("type", context.serialize(src.getReference().getReferenceType())); + result.add("dtoReference", context.serialize(src.getReference())); + result.add("messages", context.serialize(src.getMessages().asList())); + return result; + } +} ===================================== services/src/main/java/fr/ird/observe/services/service/actions/report/ReportBuilder.java ===================================== @@ -6,15 +6,15 @@ * %% * 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 + * 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 + * + * 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% @@ -51,27 +51,24 @@ import java.util.regex.Pattern; */ public class ReportBuilder { - private static final Pattern REPORT_DEFINITION_PATTERN = Pattern.compile("report.(\\w+).name"); + public static final Pattern REPORT_DEFINITION_PATTERN = Pattern.compile("report.(\\w+).name"); - private static final String REQUEST_PREFIX = "request."; + public static final String REQUEST_PREFIX = "request."; - private static final String OPERATION_PREFIX = "operations."; + public static final String OPERATION_PREFIX = "operations."; - private static final String VARIABLE_PREFIX = "variable."; + public static final String VARIABLE_PREFIX = "variable."; - private static final String REPEAT_VARIABLE_PREFIX = "repeatVariable."; + public static final String REPEAT_VARIABLE_PREFIX = "repeatVariable."; /** Logger */ private static final Logger log = LogManager.getLogger(ReportBuilder.class); - - /** les propriétés chargées par le builder pour construire les reports */ - private Properties properties; - - /** la liste des lastName sde reports connus par le système */ - private List<String> reportNames; - /** les operations connues par le système */ protected static Map<String, Class<?>> operations; + /** les propriétés chargées par le builder pour construire les reports */ + protected Properties properties; + /** la liste des lastName sde reports connus par le système */ + protected List<String> reportNames; public List<String> getReportNames() { return reportNames; @@ -97,7 +94,7 @@ public class ReportBuilder { } - private List<String> detectReportNames() { + protected List<String> detectReportNames() { List<String> reportNames = new ArrayList<>(); Enumeration<Object> keys = properties.keys(); while (keys.hasMoreElements()) { @@ -163,7 +160,7 @@ public class ReportBuilder { ); } - private Map<String, String> detectReportProperties(String reportName) { + protected Map<String, String> detectReportProperties(String reportName) { Map<String, String> dico = new TreeMap<>(); @@ -238,8 +235,8 @@ public class ReportBuilder { return result.toArray(new ReportRequest[0]); } - private ReportRequest getRequest(String requestDef, - String requestRepeatDef) { + protected ReportRequest getRequest(String requestDef, + String requestRepeatDef) { String[] parts = requestDef.split("\\|"); if (parts.length != 3) { @@ -311,7 +308,7 @@ public class ReportBuilder { return result.toArray(new ReportOperation[0]); } - private ReportVariable[] getVariables(String reportName, Map<String, String> dico) { + protected ReportVariable[] getVariables(String reportName, Map<String, String> dico) { List<ReportVariable> result = new ArrayList<>(); Iterator<Map.Entry<String, String>> itr = dico.entrySet().iterator(); List<String> ids = new ArrayList<>(); @@ -351,7 +348,7 @@ public class ReportBuilder { return result.toArray(new ReportVariable[0]); } - private ReportVariable[] getRepeatVariables(String reportName, Map<String, String> dico) { + protected ReportVariable[] getRepeatVariables(String reportName, Map<String, String> dico) { List<ReportVariable> result = new ArrayList<>(); Iterator<Map.Entry<String, String>> itr = dico.entrySet().iterator(); List<String> ids = new ArrayList<>(); ===================================== services/src/main/java/fr/ird/observe/services/service/actions/report/ReportRequest.java ===================================== @@ -6,15 +6,15 @@ * %% * 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 + * 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 + * + * 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% @@ -25,8 +25,8 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import fr.ird.observe.dto.ObserveDto; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.awt.Point; import java.io.Serializable; @@ -42,61 +42,16 @@ import java.util.Map; */ public class ReportRequest implements Serializable, ObserveDto { + public static final String TRIP_ID_VARIABLE = "tripId"; private static final long serialVersionUID = 1L; - /** Logger. */ private static final Logger log = LogManager.getLogger(ReportRequest.class); - - public static final String TRIP_ID_VARIABLE = "tripId"; - - /** le layout de la requete. */ - public enum RequestLayout { - /** lorsque les résultats de la requète sont les lignes du résultat. */ - row, - /** lorsque les résultats de la requète sont les colonnes du résultat. */ - column - } - - /** Un repeater optionnel sur la requête. */ - public static class RequestRepeat implements Serializable, ObserveDto { - - protected final String variableName; - - protected final RequestLayout layout; - - private static final long serialVersionUID = 1L; - - public RequestRepeat(String variableName, RequestLayout layout) { - this.variableName = variableName; - this.layout = layout; - } - - public String getVariableName() { - return variableName; - } - - public RequestLayout getLayout() { - return layout; - } - - @Override - public String toString() { - ToStringBuilder builder = new ToStringBuilder(this); - builder.append("variableName", getVariableName()); - builder.append("layout", getLayout()); - return builder.toString(); - } - } - /** layout de la requète. */ protected final RequestLayout layout; - /** la requète à exécuter. */ protected final String request; - /** la position de la requète. */ protected final Point location; - /** le repeater optionel. */ protected final RequestRepeat repeat; @@ -111,30 +66,6 @@ public class ReportRequest implements Serializable, ObserveDto { location = new Point(x, y); } - public RequestLayout getLayout() { - return layout; - } - - public int getX() { - return (int) location.getX(); - } - - public int getY() { - return (int) location.getY(); - } - - public Point getLocation() { - return location; - } - - public String getRequest() { - return request; - } - - public RequestRepeat getRepeat() { - return repeat; - } - public static Map<String, Object> extractParams(Report report, ImmutableSet<String> tripId) { Map<String, Object> params = Maps.newHashMap(); @@ -176,6 +107,30 @@ public class ReportRequest implements Serializable, ObserveDto { return datas; } + public RequestLayout getLayout() { + return layout; + } + + public int getX() { + return (int) location.getX(); + } + + public int getY() { + return (int) location.getY(); + } + + public Point getLocation() { + return location; + } + + public String getRequest() { + return request; + } + + public RequestRepeat getRepeat() { + return repeat; + } + @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); @@ -185,4 +140,41 @@ public class ReportRequest implements Serializable, ObserveDto { builder.append("repeatVariable", getRepeat()); return builder.toString(); } + + /** le layout de la requete. */ + public enum RequestLayout { + /** lorsque les résultats de la requète sont les lignes du résultat. */ + row, + /** lorsque les résultats de la requète sont les colonnes du résultat. */ + column + } + + /** Un repeater optionnel sur la requête. */ + public static class RequestRepeat implements Serializable, ObserveDto { + + private static final long serialVersionUID = 1L; + protected final String variableName; + protected final RequestLayout layout; + + public RequestRepeat(String variableName, RequestLayout layout) { + this.variableName = variableName; + this.layout = layout; + } + + public String getVariableName() { + return variableName; + } + + public RequestLayout getLayout() { + return layout; + } + + @Override + public String toString() { + ToStringBuilder builder = new ToStringBuilder(this); + builder.append("variableName", getVariableName()); + builder.append("layout", getLayout()); + return builder.toString(); + } + } } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/validate/DataValidationResult.java ===================================== @@ -0,0 +1,57 @@ +package fr.ird.observe.services.service.actions.validate; + +/*- + * #%L + * ObServe :: Services API + * %% + * Copyright (C) 2008 - 2018 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 com.google.common.collect.ImmutableSet; +import fr.ird.observe.dto.referential.ReferentialLocale; + +/** + * Created by tchemit on 06/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class DataValidationResult extends ValidationResult<DataValidationRequest> { + + private final DataValidationRequest request; + + private DataValidationResult(DataValidationRequest request, ImmutableSet<ValidationResultDto> data) { + super(data); + this.request = request; + } + + @Override + public DataValidationRequest getRequest() { + return request; + } + + public static Builder<DataValidationRequest, DataValidationResult> builder(ReferentialLocale referenceLocale, DataValidationRequest request) { + return new Builder<DataValidationRequest, DataValidationResult>(referenceLocale, request) { + + @Override + protected DataValidationResult newResult(DataValidationRequest request, ImmutableSet<ValidationResultDto> result) { + return new DataValidationResult(request, result); + } + }; + } + +} ===================================== services/src/main/java/fr/ird/observe/services/service/actions/validate/ReferentialValidationResult.java ===================================== @@ -0,0 +1,57 @@ +package fr.ird.observe.services.service.actions.validate; + +/*- + * #%L + * ObServe :: Services API + * %% + * Copyright (C) 2008 - 2018 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 com.google.common.collect.ImmutableSet; +import fr.ird.observe.dto.referential.ReferentialLocale; + +/** + * Created by tchemit on 06/08/17. + * + * @author Tony Chemit - dev@tchemit.fr + */ +public class ReferentialValidationResult extends ValidationResult<ReferentialValidationRequest> { + + private final ReferentialValidationRequest request; + + private ReferentialValidationResult(ReferentialValidationRequest request, ImmutableSet<ValidationResultDto> data) { + super(data); + this.request = request; + } + + @Override + public ReferentialValidationRequest getRequest() { + return request; + } + + public static Builder<ReferentialValidationRequest, ReferentialValidationResult> builder(ReferentialLocale referenceLocale, ReferentialValidationRequest request) { + return new Builder<ReferentialValidationRequest, ReferentialValidationResult>(referenceLocale, request) { + + @Override + protected ReferentialValidationResult newResult(ReferentialValidationRequest request, ImmutableSet<ValidationResultDto> result) { + return new ReferentialValidationResult(request, result); + } + }; + } + +} ===================================== services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidateService.java ===================================== @@ -37,11 +37,11 @@ public interface ValidateService extends ObserveService { @ReadReferentialPermission @Post - ValidationResult<ReferentialValidationRequest> validateReferential(ReferentialValidationRequest request); + ReferentialValidationResult validateReferential(ReferentialValidationRequest request); @ReadDataPermission @ReadReferentialPermission @Post - ValidationResult<DataValidationRequest> validateData(DataValidationRequest request); + DataValidationResult validateData(DataValidationRequest request); } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidationResult.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.actions.validate; * 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>. @@ -28,8 +28,8 @@ import com.google.common.collect.Multimap; import fr.ird.observe.dto.ObserveDto; import fr.ird.observe.dto.reference.DtoReference; import fr.ird.observe.dto.referential.ReferentialLocale; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.nuiton.validator.bean.simple.SimpleBeanValidatorEvent; import java.util.ArrayList; @@ -47,23 +47,15 @@ import static org.nuiton.i18n.I18n.l; * * @author Tony Chemit - dev@tchemit.fr */ -public class ValidationResult<R extends ValidationRequest> implements ObserveDto { +public abstract class ValidationResult<R extends ValidationRequest> implements ObserveDto { - private final R request; private final ImmutableSet<ValidationResultDto> data; - public static <R extends ValidationRequest> Builder<R> builder(ReferentialLocale referenceLocale, R request) { - return new Builder<>(referenceLocale, request); - } - - private ValidationResult(R request, ImmutableSet<ValidationResultDto> data) { - this.request = request; + ValidationResult(ImmutableSet<ValidationResultDto> data) { this.data = data; } - public R getRequest() { - return request; - } + public abstract R getRequest(); public ImmutableSet<ValidationResultDto> getData() { return data; @@ -91,7 +83,7 @@ public class ValidationResult<R extends ValidationRequest> implements ObserveDto * * @author Tony Chemit - dev@tchemit.fr */ - public static class Builder<R extends ValidationRequest> { + public static abstract class Builder<R extends ValidationRequest, S extends ValidationResult<R>> { /** Logger. */ private static final Logger log = LogManager.getLogger(Builder.class); @@ -100,7 +92,7 @@ public class ValidationResult<R extends ValidationRequest> implements ObserveDto private final R request; private final ReferentialLocale referenceLocale; - private Builder(ReferentialLocale referenceLocale, R request) { + Builder(ReferentialLocale referenceLocale, R request) { this.referenceLocale = referenceLocale; this.request = request; data = HashMultimap.create(); @@ -119,12 +111,14 @@ public class ValidationResult<R extends ValidationRequest> implements ObserveDto return this; } - public ValidationResult<R> build() { + protected abstract S newResult(R request, ImmutableSet<ValidationResultDto> result); + + public S build() { ImmutableSet.Builder<ValidationResultDto> result = ImmutableSet.builder(); for (Map.Entry<DtoReference, Collection<ValidationResultDtoMessage>> entry : data.asMap().entrySet()) { result.add(new ValidationResultDto(entry.getKey(), ImmutableSet.copyOf(entry.getValue()))); } - return new ValidationResult<>(request, result.build()); + return newResult(request, result.build()); } private String translateMessage(String message) { ===================================== services/src/main/java/fr/ird/observe/services/service/actions/validate/ValidationResultDto.java ===================================== @@ -35,7 +35,7 @@ public class ValidationResultDto { private final DtoReference reference; private final ImmutableSet<ValidationResultDtoMessage> messages; - ValidationResultDto(DtoReference reference, ImmutableSet<ValidationResultDtoMessage> messages) { + public ValidationResultDto(DtoReference reference, ImmutableSet<ValidationResultDtoMessage> messages) { this.reference = reference; this.messages = messages; } ===================================== services/src/main/resources/observe-reports.properties ===================================== @@ -19,7 +19,6 @@ # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### - ################################################################################ ## Liste des \u00e9quipements (Seine) ################################################################################ @@ -36,7 +35,6 @@ report.tripSeineGearUseFeatures.repeatVariable.gearUseFeaturesId=java.lang.Strin m.id In :tripId \ and g in elements (m.gearUseFeaturesSeine) \ Order By g.gear.label2 - report.tripSeineGearUseFeatures.request.1=0,0|row|\ Select \ concat(CASE When g.gear.code IS NULL Then 'Aucun code' Else g.gear.code End, ' - ', g.gear.label2), \ @@ -44,9 +42,7 @@ report.tripSeineGearUseFeatures.request.1=0,0|row|\ ( CASE g.usedInTrip When true Then 'Oui' Else Case g.usedInTrip When false Then 'Non' Else 'Ind\u00e9termin\u00e9' End End )\ From GearUseFeaturesSeineImpl g \ Where g.id = :gearUseFeaturesId - report.tripSeineGearUseFeatures.request.1.repeat=gearUseFeaturesId|column - ################################################################################ ## Liste des \u00e9quipements (Longline) ################################################################################ @@ -63,7 +59,6 @@ report.tripLonglineGearUseFeatures.repeatVariable.gearUseFeaturesId=java.lang.St m.id In :tripId \ and g in elements (m.gearUseFeaturesLongline) \ Order By g.gear.label2 - report.tripLonglineGearUseFeatures.request.1=0,0|row|\ Select \ concat(CASE When g.gear.code IS NULL Then 'Aucun code' Else g.gear.code End, ' - ', g.gear.label2), \ @@ -71,9 +66,7 @@ report.tripLonglineGearUseFeatures.request.1=0,0|row|\ ( CASE g.usedInTrip When true Then 'Oui' Else Case g.usedInTrip When false Then 'Non' Else 'Ind\u00e9termin\u00e9' End End )\ From GearUseFeaturesLonglineImpl g \ Where g.id = :gearUseFeaturesId - report.tripLonglineGearUseFeatures.request.1.repeat=gearUseFeaturesId|column - ################################################################################ ## Liste des activit\u00e9s avec des comments ################################################################################ @@ -91,7 +84,6 @@ report.activityWithComment.request.1=0,0|row|\ m.id In :tripId \ and a.comment is not null \ Order By r.date, a.time - ################################################################################ ## Liste de toutes les activit\u00e9s et leurs positions ################################################################################ @@ -108,7 +100,6 @@ report.allActivitys.request.1=0,0|row|\ Where \ m.id In :tripId \ Order By r.date, a.time - ################################################################################ ## Nombre de cal\u00e9es et captures journali\u00e8res d'une mar\u00e9e ################################################################################ @@ -127,7 +118,6 @@ report.dailySetAndCatch.request.1=0,0|row|\ m.id In :tripId \ Group By r.date \ Order By r.date - ################################################################################ ## Utilisation des DCP ################################################################################ @@ -145,14 +135,12 @@ report.dcpUsage.repeatVariable.typeObjetId=java.lang.String|\ Where \ m.id In :tripId \ Order by to.code - report.dcpUsage.request.1=0,0|row|\ Select concat(str(to.code) , ' - ', to.label2) \ From ObjectTypeImpl to \ Where \ to.id = :typeObjetId report.dcpUsage.request.1.repeat=typeObjetId|column - report.dcpUsage.request.2=1,0|row|\ Select Count(dcp) \ From TripSeineImpl m \ @@ -164,7 +152,6 @@ report.dcpUsage.request.2=1,0|row|\ and dcp.objectType.id = :typeObjetId \ and dcp.objectOperation.id = 'fr.ird.observe.entities.referentiel.seine.ObjectOperation#1239832686249#0.8268884472438458' report.dcpUsage.request.2.repeat=typeObjetId|column - report.dcpUsage.request.3=2,0|row|\ Select Count(dcp) \ From TripSeineImpl m \ @@ -176,7 +163,6 @@ report.dcpUsage.request.3=2,0|row|\ and dcp.objectType.id = :typeObjetId \ and dcp.objectOperation.id = 'fr.ird.observe.entities.referentiel.seine.ObjectOperation#1239832686249#0.8431519556575698' report.dcpUsage.request.3.repeat=typeObjetId|column - report.dcpUsage.request.4=3,0|row|\ Select Count(dcp) \ From TripSeineImpl m \ @@ -188,7 +174,6 @@ report.dcpUsage.request.4=3,0|row|\ and dcp.objectType.id = :typeObjetId \ and dcp.objectOperation.id = 'fr.ird.observe.entities.referentiel.seine.ObjectOperation#1239832686248#0.8669327599318251' report.dcpUsage.request.4.repeat=typeObjetId|column - report.dcpUsage.request.5=4,0|row|\ Select Count(dcp) \ From TripSeineImpl m \ @@ -201,7 +186,6 @@ report.dcpUsage.request.5=4,0|row|\ and dcp.objectFate.id = 'fr.ird.observe.entities.referentiel.seine.ObjectFate#1396860761530#0.8869464242156488' \ and dcp.objectOperation.id != 'fr.ird.observe.entities.referentiel.seine.ObjectOperation#1239832686248#0.8669327599318251' report.dcpUsage.request.5.repeat=typeObjetId|column - report.dcpUsage.request.6=5,0|row|\ Select Count(dcp) \ From TripSeineImpl m \ @@ -213,7 +197,6 @@ report.dcpUsage.request.6=5,0|row|\ and dcp.objectType.id = :typeObjetId \ and dcp.objectOperation.id = 'fr.ird.observe.entities.referentiel.seine.ObjectOperation#1239832686249#0.7838704130950722' report.dcpUsage.request.6.repeat=typeObjetId|column - report.dcpUsage.request.7=6,0|row| \ Select Sum(efo.count) \ From TripSeineImpl m \ @@ -226,7 +209,6 @@ report.dcpUsage.request.7=6,0|row| \ and dcp.objectType.id = :typeObjetId \ and efo.species.speciesGroup.id = 'fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461' report.dcpUsage.request.7.repeat=typeObjetId|column - ################################################################################ ## Nombre des cal\u00e9es selon le type d'association ################################################################################ @@ -249,7 +231,6 @@ report.setByAssociation.request.1=0,0|column|\ and a.setSeine.reasonForNullSet is null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os not in elements(a.observedSystem) - report.setByAssociation.request.2=0,1|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -262,7 +243,6 @@ report.setByAssociation.request.2=0,1|column|\ and a.setSeine.reasonForNullSet is not null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os not in elements(a.observedSystem) - report.setByAssociation.request.3=1,0|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -275,7 +255,6 @@ report.setByAssociation.request.3=1,0|column|\ and a.setSeine.reasonForNullSet is null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os in elements(a.observedSystem) - report.setByAssociation.request.4=1,1|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -288,7 +267,6 @@ report.setByAssociation.request.4=1,1|column|\ and a.setSeine.reasonForNullSet is not null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os in elements(a.observedSystem) - report.setByAssociation.request.5=2,0|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -301,7 +279,6 @@ report.setByAssociation.request.5=2,0|column|\ and a.setSeine.reasonForNullSet is null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os in elements(a.observedSystem) - report.setByAssociation.request.6=2,1|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -314,7 +291,6 @@ report.setByAssociation.request.6=2,1|column|\ and a.setSeine.reasonForNullSet is not null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os in elements(a.observedSystem) - report.setByAssociation.request.7=3,0|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -327,7 +303,6 @@ report.setByAssociation.request.7=3,0|column|\ and a.setSeine.reasonForNullSet is null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os not in elements(a.observedSystem) - report.setByAssociation.request.8=3,1|column|\ Select Count(a) \ From TripSeineImpl m \ @@ -340,7 +315,6 @@ report.setByAssociation.request.8=3,1|column|\ and a.setSeine.reasonForNullSet is not null \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os not in elements(a.observedSystem) - ################################################################################ ## Captures thon par type d'association ################################################################################ @@ -351,7 +325,6 @@ report.targetCatchByAssociation.columns=YFT, SKJ, BET, LTA, FRI, Autres, Total report.targetCatchByAssociation.rows=BL sans baleine, BL avec baleine, BO avec requin-baleine, BO sans requin-baleine, Total report.targetCatchByAssociation.operations.1=SumRow report.targetCatchByAssociation.operations.2=SumColumn - # ligne 1 report.targetCatchByAssociation.request.1=0,0|row|\ Select \ @@ -383,7 +356,6 @@ report.targetCatchByAssociation.request.1=0,0|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os not in elements(a.observedSystem) - # ligne 2 report.targetCatchByAssociation.request.7=0,1|row|\ Select \ @@ -415,7 +387,6 @@ report.targetCatchByAssociation.request.7=0,1|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os in elements(a.observedSystem) - # ligne 3 report.targetCatchByAssociation.request.13=0,2|row|\ Select \ @@ -447,7 +418,6 @@ report.targetCatchByAssociation.request.13=0,2|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os in elements(a.observedSystem) - # ligne 4 report.targetCatchByAssociation.request.19=0,3|row|\ Select \ @@ -479,7 +449,6 @@ report.targetCatchByAssociation.request.19=0,3|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os not in elements(a.observedSystem) - ################################################################################ ## Rejets thons selon le type d'association ################################################################################ @@ -490,7 +459,6 @@ report.targetDiscardedByAssociation.columns=YFT, SKJ, BET, LTA, FRI, Autres, Tot report.targetDiscardedByAssociation.rows=BL sans baleine, BL avec baleine, BO avec requin-baleine, BO sans requin-baleine, Total report.targetDiscardedByAssociation.operations.1=SumRow report.targetDiscardedByAssociation.operations.2=SumColumn - # ligne 1 report.targetDiscardedByAssociation.request.1=0,0|row|\ Select \ @@ -522,7 +490,6 @@ report.targetDiscardedByAssociation.request.1=0,0|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os not in elements(a.observedSystem) - # ligne 2 report.targetDiscardedByAssociation.request.7=0,1|row|\ Select \ @@ -554,7 +521,6 @@ report.targetDiscardedByAssociation.request.7=0,1|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9395222812356602' \ and os in elements(a.observedSystem) - # ligne 3 report.targetDiscardedByAssociation.request.13=0,2|row|\ Select \ @@ -586,7 +552,6 @@ report.targetDiscardedByAssociation.request.13=0,2|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os in elements(a.observedSystem) - # ligne 4 report.targetDiscardedByAssociation.request.19=0,3|row|\ Select \ @@ -618,7 +583,6 @@ report.targetDiscardedByAssociation.request.19=0,3|row|\ m.id In :tripId \ and os.topiaId = 'fr.ird.observe.entities.referentiel.seine.ObservedSystem#1239832686428#0.9217864901728908' \ and os not in elements(a.observedSystem) - ################################################################################ ## Captures accessoires observ\u00e9es ################################################################################ @@ -631,7 +595,6 @@ report.accessoryCatch.repeatVariable.speciesId=java.lang.String|\ Select e.id From SpeciesImpl e \ Where e.speciesGroup.id = :speciesGroup \ Order By e.homeId - report.accessoryCatch.request.1=0,0|row|\ Select \ concat('[FAO]', (case when e.faoCode is not null then e.faoCode else '-' end), \ @@ -640,7 +603,6 @@ report.accessoryCatch.request.1=0,0|row|\ From SpeciesImpl e \ Where e.id = :speciesId report.accessoryCatch.request.1.repeat=speciesId|column - report.accessoryCatch.request.2=1,0|row|\ Select \ case when Count(ca) > 0 then \ @@ -657,7 +619,6 @@ report.accessoryCatch.request.2=1,0|row|\ with ca.species.id = :speciesId \ Where m.id In :tripId report.accessoryCatch.request.2.repeat=speciesId|column - report.accessoryCatch.request.3=2,0|row|\ Select \ case when Count(ca) > 0 then \ @@ -674,7 +635,6 @@ report.accessoryCatch.request.3=2,0|row|\ with ca.species.id = :speciesId \ Where m.id In :tripId report.accessoryCatch.request.3.repeat=speciesId|column - ################################################################################ ## Captures accessoires par speciesGroup d'esp\u00e8ces ################################################################################ @@ -683,7 +643,6 @@ report.accessoryCatchByGroup.name=D\u00e9nombrement des captures accessoires et report.accessoryCatchByGroup.description=Afficher les nombres de captures accessoires par groupe d'esp\u00e8ce selon le type de banc et le devenir report.accessoryCatchByGroup.columns=Esp\u00e8ce, Total BL, Total BO, Sorti vivant/\u00e9chapp\u00e9, Sorti mort, Rejet\u00e9 vivant, Rejet\u00e9 mort, Partiellement conserv\u00e9, Cuve, Cuisine, Autre report.accessoryCatchByGroup.variable.speciesGroup=fr.ird.observe.dto.referential.SpeciesGroupDto|From SpeciesGroupImpl ge Order By ge.code - report.accessoryCatchByGroup.request.1=0,0|row|\ Select \ concat(\ @@ -726,7 +685,6 @@ report.accessoryCatchByGroup.request.1=0,0|row|\ Where m.id In :tripId \ Group by e \ Order By e.homeId - ########################################################### ## Distribution des tailles par espèces non ciblées ########################################################### @@ -754,7 +712,6 @@ Where t.id In :tripId \ And ntl.species.id = :speciesId \ Group By ntl.length \ Order By ntl.length - #################################################################### ## Distribution des tailles des conservés par espèces ciblées (LD1) #################################################################### @@ -786,7 +743,6 @@ Where t.id In :tripId \ And ts.discarded = false \ Group By tl.length \ Order By tl.length - ################################################################ ## Distribution des tailles des rejets par espèces ciblées (LD1) ################################################################ @@ -818,7 +774,6 @@ Where t.id In :tripId \ And ts.discarded = true \ Group By tl.length \ Order By tl.length - ############################################################### ## Distribution des tailles des conservés par espèces ciblées (LF) ############################################################### @@ -850,7 +805,6 @@ Where t.id In :tripId \ And ts.discarded = false \ Group By tl.length \ Order By tl.length - ############################################################### ## Distribution des tailles des rejets par espèces ciblées (LF) ############################################################### @@ -882,7 +836,6 @@ Where t.id In :tripId \ And ts.discarded = true \ Group By tl.length \ Order By tl.length - ############################################ ## Répartition des calées par cuves ############################################ View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/fb5deba00986e3133e252edc75e... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/fb5deba00986e3133e252edc75e... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT