Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 18188033 by Tony CHEMIT at 2018-05-02T11:54:47Z Calculer en temps réel les données calculées sur un FAD lors de la modification de ses materials (closes #937) - - - - - 17 changed files: - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java - persistence/src/main/resources/db/migration/7.2/01_update_objectMaterial-common.sql - server/src/main/filtered-resources/mapping - services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocal.java - services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java - services-local/src/test/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocalTest.java - services/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateDataService.java - services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/ConsolidateFloatingObjectResult.java - services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/FloatingObjectConsolidateEngine.java - services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeManager.java - services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeNode.java - test/src/main/java/fr/ird/observe/test/ObserveFixtures.java - test/src/main/resources/db/7.2/dataForTestLongline.sql.gz - test/src/main/resources/db/7.2/dataForTestSeine.sql.gz - test/src/main/resources/db/7.2/referentiel.sql.gz Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.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% @@ -47,6 +47,8 @@ import fr.ird.observe.dto.form.Form; import fr.ird.observe.dto.referential.seine.ObjectMaterialDto; import fr.ird.observe.dto.referential.seine.ObjectOperationReference; import fr.ird.observe.dto.result.SaveResultDto; +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectRequest; +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectResult; import fr.ird.observe.spi.DtoModelHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -85,7 +87,8 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, /** Logger */ private static final Log log = LogFactory.getLog(FloatingObjectUIHandler.class); - + private static final Icon ICON_NOT_A_REFERENCE = SwingUtil.createImageIcon("star-empty.png"); + private static final Icon ICON_IS_A_REFERENCE = SwingUtil.createImageIcon("star.png"); // Compute valid state of tab from the error table protected final TableModelListener computeTabValidStateListener; @@ -235,14 +238,14 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, getUi().getValidator().setContext(contextName); if (create) { addMessage(getUi(), - NuitonValidatorScope.INFO, - getTypeI18nKey(FloatingObjectDto.class), - t("observe.common.FloatingObjectDto.message.creating")); + NuitonValidatorScope.INFO, + getTypeI18nKey(FloatingObjectDto.class), + t("observe.common.FloatingObjectDto.message.creating")); } else { addMessage(getUi(), - NuitonValidatorScope.INFO, - getTypeI18nKey(FloatingObjectDto.class), - t("observe.common.FloatingObjectDto.message.updating")); + NuitonValidatorScope.INFO, + getTypeI18nKey(FloatingObjectDto.class), + t("observe.common.FloatingObjectDto.message.updating")); } super.startEditUI(FloatingObjectUI.BINDING_COMMENT_MODEL); contentUIModel.setModified(create); @@ -253,6 +256,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, String activityId = getSelectedParentId(); + recomputeComputedValues(); SaveResultDto saveResult = getFloatingObjectService().save(activityId, bean); saveResult.toDto(bean); @@ -323,12 +327,13 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, Map<String, ObjectMaterialDto> allMap = new TreeMap<>(); detailedForm.stream().flatMap(o -> o.getAllDtos().stream()).forEach(s -> allMap.putIfAbsent(s.getId(), s)); - getModel().setReferentialMap(allMap); + FloatingObjectUIModel model = getModel(); + model.setReferentialMap(allMap); initTable(detailedForm, ui.getTable()); - getModel().addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> { - if (!getModel().isUpdatingMode()) { + model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> { + if (!model.isUpdatingMode()) { return; } FloatingObjectPreset newValue = (FloatingObjectPreset) e.getNewValue(); @@ -349,12 +354,26 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, } }); - getModel().addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_PARTS_MODIFIED, e -> getModel().recomputeComputedValues()); + model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_PARTS_MODIFIED, e -> { + if (Objects.equals(e.getNewValue(), Boolean.TRUE)) { + recomputeComputedValues(); + } + }); getBean().addPropertyChangeListener(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, e -> updateMaterials((ObjectOperationReference) e.getNewValue())); } + private void recomputeComputedValues() { + + ConsolidateFloatingObjectResult result = getConsolidateDataService().consolidateFloatingObject(new ConsolidateFloatingObjectRequest(getBean(), getModel().toParts())); + if (result != null) { + log.info("Flush consolidate dcp changes..."); + result.flushToDto(getBean()); + getModel().fireComputedValuesChanged(); + } + } + private void updateMaterials(ObjectOperationReference operation) { if (operation == null) { getModel().setArriving(false); @@ -367,9 +386,6 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, treeModel.reset(); } - private static final Icon ICON_NOT_A_REFERENCE = SwingUtil.createImageIcon("star-empty.png"); - private static final Icon ICON_IS_A_REFERENCE = SwingUtil.createImageIcon("star.png"); - private void initTable(List<ObjectMaterialHierarchyDto> materials, JXTreeTable table) { FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel(); ===================================== client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java @@ -144,7 +144,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { fireComputedValuesChanged(); } - private void fireComputedValuesChanged() { + public void fireComputedValuesChanged() { firePropertyChange("computedWhenArrivingBiodegradableValue", getComputedWhenArrivingBiodegradableValue()); firePropertyChange("computedWhenArrivingNonEntanglingValue", getComputedWhenArrivingNonEntanglingValue()); firePropertyChange("computedWhenArrivingSimplifiedObjectTypeValue", getComputedWhenArrivingSimplifiedObjectTypeValue()); ===================================== persistence/src/main/resources/db/migration/7.2/01_update_objectMaterial-common.sql ===================================== --- a/persistence/src/main/resources/db/migration/7.2/01_update_objectMaterial-common.sql +++ b/persistence/src/main/resources/db/migration/7.2/01_update_objectMaterial-common.sql @@ -104,4 +104,8 @@ update observe_seine.objectmaterial set validation='x >= 5 && x <= 1000', topiav -- Mise à jour label 4-8 update observe_seine.objectmaterial set label2='Number of tangled FOBs', label3='Numero de FADs enmallados', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.76'; -- Mise à jour formule de validation len -update observe_seine.objectmaterial set validation='x.length() >= 3 && x.length() <= 64', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.75'; \ No newline at end of file +update observe_seine.objectmaterial set validation='x.length() >= 3 && x.length() <= 64', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.75'; +-- Re-add entry for FOB with '' code +INSERT INTO observe_seine.objectMaterial (topiaid, topiaversion, topiacreatedate, lastupdatedate, needComment, status, legacyCode, standardCode, code, parent, label1, label2, label3, selectable, childrenMultiSelectable, childSelectionMandatory, objectMaterialType, validation, biodegradable, nonEntangling) values ('fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3', 0, CURRENT_DATE, CURRENT_TIMESTAMP, false, 1, NULL, 'FOB', '' , null , 'FOB', 'FOB', 'FOB', false, true , true, NULL, NULL, false, false); +UPDATE observe_seine.objectmaterial SET parent='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3' WHERE parent IS NULL; +UPDATE observe_seine.objectmaterial SET parent= NULL WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3'; ===================================== server/src/main/filtered-resources/mapping ===================================== --- a/server/src/main/filtered-resources/mapping +++ b/server/src/main/filtered-resources/mapping @@ -67,6 +67,7 @@ POST /api/v1/LastUpdateDateService/updateDataLastUpdateDates POST /api/v1/LastUpdateDateService/updateReferentialLastUpdateDates v1.LastUpdateDateServiceRestApi.updateReferentialLastUpdateDates GET /api/v1/PingService/getModelVersion v1.PingServiceRestApi.getModelVersion GET /api/v1/PingService/getServerVersion v1.PingServiceRestApi.getServerVersion +POST /api/v1/actions/consolidate/ConsolidateDataService/consolidateFloatingObject v1.actions.consolidate.ConsolidateDataServiceRestApi.consolidateFloatingObject POST /api/v1/actions/consolidate/ConsolidateDataService/consolidateTripSeine v1.actions.consolidate.ConsolidateDataServiceRestApi.consolidateTripSeine GET /api/v1/actions/consolidate/ConsolidateDataService/newSimplifiedObjectTypeManager v1.actions.consolidate.ConsolidateDataServiceRestApi.newSimplifiedObjectTypeManager POST /api/v1/actions/report/ReportService/executeReport v1.actions.report.ReportServiceRestApi.executeReport ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java ===================================== --- a/services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java +++ b/services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.actions.consolidate; * 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>. @@ -25,11 +25,11 @@ package fr.ird.observe.services.local.service.actions.consolidate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import fr.ird.observe.binder.data.DataEntityDtoBinderSupport; +import fr.ird.observe.dto.data.seine.FloatingObjectDto; +import fr.ird.observe.dto.data.seine.FloatingObjectPartDto; import fr.ird.observe.dto.data.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.dto.data.seine.SchoolType; import fr.ird.observe.dto.referential.ReferentialLocale; -import fr.ird.observe.dto.data.seine.FloatingObjectDto; -import fr.ird.observe.dto.data.seine.FloatingObjectPartDto; import fr.ird.observe.entities.LengthWeightComputable; import fr.ird.observe.entities.referentiel.LengthLengthParameter; import fr.ird.observe.entities.referentiel.LengthLengthParameters; @@ -65,6 +65,11 @@ import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectT import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectTypeNode; import fr.ird.observe.services.service.actions.consolidate.set.ConsolidateActivitySeineDataResult; import fr.ird.observe.spi.DbModelHelper; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.beans.BeanMonitor; + import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; @@ -74,10 +79,6 @@ import java.util.Optional; import java.util.Set; import java.util.TreeMap; import java.util.stream.Collectors; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BeanMonitor; /** * Created on 28/08/15. @@ -89,15 +90,81 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements /** Logger. */ private static final Log log = LogFactory.getLog(ConsolidateDataServiceLocal.class); + private static ImmutableMap<String, SimplifiedObjectTypeNode> create(List<ObjectMaterial> materials) { + TreeMap<String, SimplifiedObjectTypeNode> mappingBuilder = new TreeMap<>(); + + Set<ObjectMaterial> materialsDone = new LinkedHashSet<>(); + Set<ObjectMaterial> materialsTodo = new LinkedHashSet<>(materials); + + while (!materialsTodo.isEmpty()) { + + Set<ObjectMaterial> currentRoundMaterials; + if (materialsDone.isEmpty()) { + + // first round + currentRoundMaterials = materialsTodo.stream().filter(f -> f.getParent() == null).collect(Collectors.toSet()); + + } else { + currentRoundMaterials = materialsTodo.stream().filter(f -> materialsDone.contains(f.getParent())).collect(Collectors.toSet()); + } + + materialsDone.addAll(currentRoundMaterials); + materialsTodo.removeAll(currentRoundMaterials); + + for (ObjectMaterial currentRoundMaterial : currentRoundMaterials) { + + ObjectMaterial simplifiedObjectMaterial = currentRoundMaterial.getSimplifiedObjectMaterial(); + + SimplifiedObjectTypeNode node; + if (Objects.equals(currentRoundMaterial, simplifiedObjectMaterial)) { + + // new node + ObjectMaterial simplifiedParentObjectMaterial = currentRoundMaterial.getSimplifiedParentObjectMaterial(); + SimplifiedObjectTypeNode parentNode = simplifiedParentObjectMaterial == null ? null : mappingBuilder.get(simplifiedParentObjectMaterial.getTopiaId()); + node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), parentNode); + + } else { + + if (simplifiedObjectMaterial == null) { + simplifiedObjectMaterial = currentRoundMaterial; + } + // simplified object material is a parent, so must have been process in previous round + Objects.requireNonNull(simplifiedObjectMaterial); + + node = mappingBuilder.get(simplifiedObjectMaterial.getTopiaId()); + if (node == null) { + node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), null); + } + Objects.requireNonNull(node); + + } + + mappingBuilder.put(currentRoundMaterial.getTopiaId(), node); + + } + } + return ImmutableMap.copyOf(mappingBuilder); + } + @Override - public ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest) { + public ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest request) { ReferentialLocale referenceLocale = serviceContext.getReferentialLocale(); - boolean failIfLenghtWeightParameterNotFound = consolidateTripSeineDataRequest.isFailIfLengthWeightParameterNotFound(); - Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, consolidateTripSeineDataRequest.getTripSeineId(), failIfLenghtWeightParameterNotFound); + boolean failIfLenghtWeightParameterNotFound = request.isFailIfLengthWeightParameterNotFound(); + Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, request.getTripSeineId(), failIfLenghtWeightParameterNotFound); return consolidateTripSeineDataResult.orElse(null); } @Override + public ConsolidateFloatingObjectResult consolidateFloatingObject(ConsolidateFloatingObjectRequest request) { + + SimplifiedObjectTypeManager simplifiedObjectTypeManager = newSimplifiedObjectTypeManager(); + + FloatingObjectConsolidateEngine floatingObjectConsolidateEngine = new FloatingObjectConsolidateEngine(simplifiedObjectTypeManager); + Optional<ConsolidateFloatingObjectResult> result = floatingObjectConsolidateEngine.consolidate(request); + return result.orElse(null); + } + + @Override public SimplifiedObjectTypeManager newSimplifiedObjectTypeManager() { ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext(); ImmutableMap<String, SimplifiedObjectTypeNode> materialMapping = create(persistenceContext.getObjectMaterialDao().findAll()); @@ -251,9 +318,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements activityContext.watchTargetLength(targetLength); updateLengthWeightAble(activityContext, - targetLength.getSpecies(), - null, /* pas de sexe precise */ - targetLength); + targetLength.getSpecies(), + null, /* pas de sexe precise */ + targetLength); activityContext.flushTargetLength(); @@ -273,9 +340,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements activityContext.watchNonTargetLenght(nonTargetLength); updateLengthWeightAble(activityContext, - nonTargetLength.getSpecies(), - nonTargetLength.getSex(), - nonTargetLength); + nonTargetLength.getSpecies(), + nonTargetLength.getSex(), + nonTargetLength); activityContext.flushNonTargetLength(); @@ -697,60 +764,4 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements } } - static ImmutableMap<String, SimplifiedObjectTypeNode> create(List<ObjectMaterial> materials) { - TreeMap<String, SimplifiedObjectTypeNode> mappingBuilder = new TreeMap<>(); - - Set<ObjectMaterial> materialsDone = new LinkedHashSet<>(); - Set<ObjectMaterial> materialsTodo = new LinkedHashSet<>(materials); - - while (!materialsTodo.isEmpty()) { - - Set<ObjectMaterial> currentRoundMaterials; - if (materialsDone.isEmpty()) { - - // first round - currentRoundMaterials = materialsTodo.stream().filter(f -> f.getParent() == null).collect(Collectors.toSet()); - - } else { - currentRoundMaterials = materialsTodo.stream().filter(f -> materialsDone.contains(f.getParent())).collect(Collectors.toSet()); - } - - materialsDone.addAll(currentRoundMaterials); - materialsTodo.removeAll(currentRoundMaterials); - - for (ObjectMaterial currentRoundMaterial : currentRoundMaterials) { - - ObjectMaterial simplifiedObjectMaterial = currentRoundMaterial.getSimplifiedObjectMaterial(); - - SimplifiedObjectTypeNode node; - if (Objects.equals(currentRoundMaterial, simplifiedObjectMaterial)) { - - // new node - ObjectMaterial simplifiedParentObjectMaterial = currentRoundMaterial.getSimplifiedParentObjectMaterial(); - SimplifiedObjectTypeNode parentNode = simplifiedParentObjectMaterial == null ? null : mappingBuilder.get(simplifiedParentObjectMaterial.getTopiaId()); - node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), parentNode); - - } else { - - if (simplifiedObjectMaterial==null) { - simplifiedObjectMaterial = currentRoundMaterial; - } - // simplified object material is a parent, so must have been process in previous round - Objects.requireNonNull(simplifiedObjectMaterial); - - node = mappingBuilder.get(simplifiedObjectMaterial.getTopiaId()); - if (node==null) { - node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), null); - } - Objects.requireNonNull(node); - - } - - mappingBuilder.put(currentRoundMaterial.getTopiaId(), node); - - } - } - return ImmutableMap.copyOf(mappingBuilder); - } - } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocal.java ===================================== --- a/services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocal.java +++ b/services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocal.java @@ -238,8 +238,8 @@ public class FloatingObjectServiceLocal extends ObserveServiceLocal implements F private List<ObjectMaterialHierarchyDto> getObjectMaterialHierarchyDtos(List<ObjectMaterial> objectMaterials) { Multimap<String, ObjectMaterial> childrenByParent = ArrayListMultimap.create(); - objectMaterials.forEach(o -> childrenByParent.put(Optional.ofNullable(o.getParent()).map(ObjectMaterial::getTopiaId).orElse(null), o)); - Collection<ObjectMaterial> topLevelMaterials = childrenByParent.get(null); + objectMaterials.forEach(o -> childrenByParent.put(Optional.ofNullable(o.getParent()).map(ObjectMaterial::getTopiaId).orElse("Yo"), o)); + Collection<ObjectMaterial> topLevelMaterials = childrenByParent.get("Yo"); ReferentialEntityDtoBinderSupport<ObjectMaterialDto, ObserveReferentialEntity> referentialBinder = OBJECT_MATERIAL_SPI.toEntityBinder(); ReferentialLocale referentialLocale = getReferentialLocale(); List<ObjectMaterialHierarchyDto> result = new LinkedList<>(); ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java ===================================== --- a/services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java +++ b/services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java @@ -55,7 +55,7 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport { @Test public void getStandardCode() { -// SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB"); + SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB"); SimplifiedObjectTypeNode fad = simplifiedObjectTypeManager.getNodeForStandardCode("FAD"); SimplifiedObjectTypeNode dfad = simplifiedObjectTypeManager.getNodeForStandardCode("DFAD"); SimplifiedObjectTypeNode log = simplifiedObjectTypeManager.getNodeForStandardCode("LOG"); @@ -65,11 +65,11 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport { SimplifiedObjectTypeNode falog = simplifiedObjectTypeManager.getNodeForStandardCode("FALOG"); SimplifiedObjectTypeNode halog = simplifiedObjectTypeManager.getNodeForStandardCode("HALOG"); -// assertStandardCode(fob, fob); - assertStandardCode(fad, /*fob,*/ fad); + assertStandardCode(fob, fob); + assertStandardCode(fad, fob, fad); assertStandardCode(dfad, fad, dfad, dfad); assertStandardCode(falog, log, alog, falog); - assertStandardCode(null, dfad, log, nlog); + assertStandardCode(fob, dfad, log, nlog); assertStandardCode(falog, alog, falog, falog); assertStandardCode(alog, alog, falog, halog); assertStandardCode(log, falog, vnlog); @@ -78,7 +78,7 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport { private void assertStandardCode(SimplifiedObjectTypeNode expectedStandardCode, SimplifiedObjectTypeNode... objectMaterialIds) { String actualStandardCode = simplifiedObjectTypeManager.getStandardCode(ImmutableSet.copyOf(objectMaterialIds).stream().map(SimplifiedObjectTypeNode::getId).collect(Collectors.toSet())); - Assert.assertEquals(expectedStandardCode == null ? SimplifiedObjectTypeManager.FOB : expectedStandardCode.getStandardCode(), actualStandardCode); + Assert.assertEquals(expectedStandardCode.getStandardCode(), actualStandardCode); } } ===================================== services-local/src/test/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocalTest.java ===================================== --- a/services-local/src/test/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocalTest.java +++ b/services-local/src/test/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocalTest.java @@ -52,7 +52,7 @@ public class FloatingObjectServiceLocalTest extends ServiceLocalTestSupport { List<ObjectMaterialHierarchyDto> form = service.getObjectMaterialHierarchy(); Assert.assertNotNull(form); - Assert.assertEquals(4, form.size()); + Assert.assertEquals(1, form.size()); } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateDataService.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateDataService.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateDataService.java @@ -23,6 +23,8 @@ package fr.ird.observe.services.service.actions.consolidate; */ import fr.ird.observe.services.service.ObserveService; +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectRequest; +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectResult; import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectTypeManager; import fr.ird.observe.services.spi.ReadDataPermission; import fr.ird.observe.services.spi.ReadReferentialPermission; @@ -44,16 +46,26 @@ public interface ConsolidateDataService extends ObserveService { SimplifiedObjectTypeManager newSimplifiedObjectTypeManager(); /** - * Effectue la consolitation à partir de la demande passé en paramètre et retourne les résultats pour les marées - * modifiées. + * Consolidate trip data using given {@code request} and produce a result. * - * @param consolidateTripSeineDataRequest la demande de consolidation + * @param request la demande de consolidation * @return le résultat de la consolidation de données pour chaque marée qui a été modifée. */ @ReadDataPermission @WriteDataPermission @Post @Write - ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest); + ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest request); + + /** + * Effectue la consolitation à partir de la demande passé en paramètre et retourne les résultats pour les marées + * modifiées. + * + * @param request request + * @return {@code null} if no modification done, or {@code result} of operation. + */ + @ReadDataPermission + @Post + ConsolidateFloatingObjectResult consolidateFloatingObject(ConsolidateFloatingObjectRequest request); } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/ConsolidateFloatingObjectResult.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/ConsolidateFloatingObjectResult.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/ConsolidateFloatingObjectResult.java @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.actions.consolidate.dcp; * 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>. @@ -24,6 +24,9 @@ package fr.ird.observe.services.service.actions.consolidate.dcp; import com.google.common.collect.ImmutableSet; import fr.ird.observe.dto.ObserveDto; +import fr.ird.observe.dto.data.seine.DcpComputedValue; +import fr.ird.observe.dto.data.seine.FloatingObjectDto; + import java.io.Serializable; /** @@ -52,4 +55,38 @@ public class ConsolidateFloatingObjectResult implements Serializable, ObserveDto return floatingObjectModifications; } + public void flushToDto(FloatingObjectDto dto) { + for (FloatingObjectModification floatingObjectModification : floatingObjectModifications) { + Serializable newValue = floatingObjectModification.getNewValue(); + switch (floatingObjectModification.getPropertyName()) { + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_BIODEGRADABLE: { + dto.setComputedWhenArrivingBiodegradable((DcpComputedValue) newValue); + break; + } + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_NON_ENTANGLING: { + dto.setComputedWhenArrivingNonEntangling((DcpComputedValue) newValue); + + break; + } + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_SIMPLIFIED_OBJECT_TYPE: { + dto.setComputedWhenArrivingSimplifiedObjectType((String) newValue); + break; + } + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_BIODEGRADABLE: { + dto.setComputedWhenLeavingBiodegradable((DcpComputedValue) newValue); + break; + } + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_NON_ENTANGLING: { + dto.setComputedWhenLeavingNonEntangling((DcpComputedValue) newValue); + + break; + } + case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_SIMPLIFIED_OBJECT_TYPE: { + dto.setComputedWhenLeavingSimplifiedObjectType((String) newValue); + break; + } + } + } + } } + ===================================== services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/FloatingObjectConsolidateEngine.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/FloatingObjectConsolidateEngine.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/FloatingObjectConsolidateEngine.java @@ -136,6 +136,9 @@ public class FloatingObjectConsolidateEngine { } private String computeDcpSimplifiedObjectType0(Set<FloatingObjectPartDto> FloatingObjectPartDtos) { + if (FloatingObjectPartDtos.isEmpty()) { + return null; + } Set<String> objectMaterialIds = FloatingObjectPartDtos.stream().map(p -> p.getObjectMaterial().getId()).collect(Collectors.toSet()); return simplifiedObjectTypeManager.getStandardCode(objectMaterialIds); } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeManager.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeManager.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeManager.java @@ -39,7 +39,6 @@ import java.util.Set; */ public class SimplifiedObjectTypeManager implements ObserveDto { - public static final String FOB = "FOB"; // For each object material, get his simplified object type node private final ImmutableMap<String, SimplifiedObjectTypeNode> mapping; @@ -48,7 +47,7 @@ public class SimplifiedObjectTypeManager implements ObserveDto { } public SimplifiedObjectTypeNode getNodeForStandardCode(String standardCode) { - return mapping.values().stream().filter(n -> n.getStandardCode().equals(standardCode)).findFirst().orElseThrow(IllegalArgumentException::new); + return mapping.values().stream().filter(n -> Objects.equals(n.getStandardCode(), standardCode)).findFirst().orElseThrow(IllegalArgumentException::new); } public String getStandardCode(Set<String> objectMaterialIds) { @@ -59,10 +58,6 @@ public class SimplifiedObjectTypeManager implements ObserveDto { // get highest level first availableNodes.sort(Comparator.comparing(SimplifiedObjectTypeNode::getLevel).reversed()); - if (availableNodes.isEmpty()) { - return FOB; - } - // remove from available nodes, all nodes in the path of other ones List<SimplifiedObjectTypeNode> mainNodes = new LinkedList<>(availableNodes); @@ -78,9 +73,6 @@ public class SimplifiedObjectTypeManager implements ObserveDto { while (iterator.hasNext()) { result = result.getSharedAncestor(iterator.next()); } - if (result==null) { - return FOB; - } Objects.requireNonNull(result); return result.getStandardCode(); } ===================================== services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeNode.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeNode.java +++ b/services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeNode.java @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.actions.consolidate.dcp; * 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>. @@ -70,7 +70,7 @@ public class SimplifiedObjectTypeNode { result.retainAll(otherPathsToRoot); // get the most precise on common paths (if it exists) - return result.isEmpty() ? null : result.get(0); + return result.isEmpty() ? pathsToRoot.get(pathsToRoot.size() - 1) : result.get(0); } @Override ===================================== test/src/main/java/fr/ird/observe/test/ObserveFixtures.java ===================================== --- a/test/src/main/java/fr/ird/observe/test/ObserveFixtures.java +++ b/test/src/main/java/fr/ird/observe/test/ObserveFixtures.java @@ -117,7 +117,7 @@ public class ObserveFixtures { .put("observe_seine.nontargetcatchreleasestatus", 5L) .put("observe_seine.nontargetcatchreleasingtime", 4L) .put("observe_seine.objectoperation", 10L) - .put("observe_seine.objectmaterial", 77L) + .put("observe_seine.objectmaterial", 78L) .put("observe_seine.objectmaterialtype", 4L) .put("observe_seine.observedsystem", 21L) .put("observe_seine.reasonfordiscard", 5L) ===================================== test/src/main/resources/db/7.2/dataForTestLongline.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.2/dataForTestLongline.sql.gz and b/test/src/main/resources/db/7.2/dataForTestLongline.sql.gz differ ===================================== test/src/main/resources/db/7.2/dataForTestSeine.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.2/dataForTestSeine.sql.gz and b/test/src/main/resources/db/7.2/dataForTestSeine.sql.gz differ ===================================== test/src/main/resources/db/7.2/referentiel.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.2/referentiel.sql.gz and b/test/src/main/resources/db/7.2/referentiel.sql.gz differ View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/18188033e0ee813e8e198888b86d... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/18188033e0ee813e8e198888b86d... You're receiving this email because of your account on gitlab.com.