Commit a4f3127e authored by PECQUOT's avatar PECQUOT

[fix] Filter individual measurements when building rows to exclude...

[fix] Filter individual measurements when building rows to exclude measurements with negative id (Mantis #51520)
[fix] remove unnecessary service methods (moved to static)
Signed-off-by: PECQUOT's avatarlp1ee9d <ludovic.pecquot@e-is.pro>
parent 0d0359e3
......@@ -905,15 +905,15 @@ public final class ReefDbConfiguration extends QuadrigeCoreConfiguration {
String configOption = applicationConfig.getOption(ReefDbConfigurationOption.PMFM_IDS_TRANSITION_LENGTH.getKey());
if (StringUtils.isBlank(configOption)) return result;
List<String> triplets = Splitter.on(";").splitToList(configOption);
List<String> triplets = Splitter.on(";").omitEmptyStrings().splitToList(configOption);
for (String triplet : triplets) {
List<String> pmfmsIdsStr = Splitter.on(",").splitToList(triplet);
List<String> pmfmsIdsStr = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(triplet);
if (CollectionUtils.size(pmfmsIdsStr) == 3) {
try {
Integer[] pmfmIds = new Integer[3];
pmfmIds[0] = Integer.parseInt(pmfmsIdsStr.get(0).trim());
pmfmIds[1] = Integer.parseInt(pmfmsIdsStr.get(1).trim());
pmfmIds[2] = Integer.parseInt(pmfmsIdsStr.get(2).trim());
pmfmIds[0] = Integer.parseInt(pmfmsIdsStr.get(0));
pmfmIds[1] = Integer.parseInt(pmfmsIdsStr.get(1));
pmfmIds[2] = Integer.parseInt(pmfmsIdsStr.get(2));
if (pmfmIds[0] < 0 || pmfmIds[1] < 0 || pmfmIds[2] < 0) continue;
......
package fr.ifremer.reefdb.ui.swing.content.observation.operation.measurement.grouped;
/*
* #%L
* Reef DB :: UI
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2014 - 2015 Ifremer
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import fr.ifremer.reefdb.dto.ReefDbBeans;
import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbAction;
/**
* Action dupliquer mesure (ecran prelevements/mesure).
*/
@Deprecated
public class DuplicateOperationMeasurementsAction extends AbstractReefDbAction<OperationMeasurementsGroupedTableUIModel, OperationMeasurementsGroupedTableUI, OperationMeasurementsGroupedTableUIHandler> {
/**
* La ligne ajoutee.
*/
private OperationMeasurementsGroupedRowModel row;
/**
* Constrcuteur.
*
* @param handler Controller
*/
public DuplicateOperationMeasurementsAction(final OperationMeasurementsGroupedTableUIHandler handler) {
super(handler, false);
}
/** {@inheritDoc} */
@Override
public boolean prepareAction() throws Exception {
return super.prepareAction() && getModel().getSelectedRows().size() == 1;
}
/** {@inheritDoc} */
@Override
public void doAction() {
// Selected measurement
final OperationMeasurementsGroupedRowModel rowToDuplicate = getModel().getSelectedRows().iterator().next();
if (rowToDuplicate != null) {
row = new OperationMeasurementsGroupedRowModel(false);
row.setSamplingOperation(rowToDuplicate.getSamplingOperation());
row.setTaxonGroup(rowToDuplicate.getTaxonGroup());
row.setTaxon(rowToDuplicate.getTaxon());
row.setInputTaxonId(rowToDuplicate.getInputTaxonId());
row.setInputTaxonName(rowToDuplicate.getInputTaxonName());
row.setComment(rowToDuplicate.getComment());
row.setIndividualPmfms(rowToDuplicate.getIndividualPmfms());
// add also analyst (MAntis #45054)
row.setAnalyst(rowToDuplicate.getAnalyst());
// duplicate measurements
row.setIndividualMeasurements(ReefDbBeans.duplicate(rowToDuplicate.getIndividualMeasurements()));
}
}
/** {@inheritDoc} */
@Override
public void postSuccessAction() {
super.postSuccessAction();
// Add duplicate measurement to table
getModel().insertRowAfterSelected(row);
// save directly to sampling operation
getHandler().saveMeasurementsInModel(row);
// send update event on sampling operation
if (row.getSamplingOperation() != null) {
getModel().firePropertyChanged(OperationMeasurementsGroupedTableUIModel.PROPERTY_SAMPLING_OPERATION, null, row.getSamplingOperation());
}
getHandler().recomputeRowsValidState();
getModel().setModify(true);
// Ajouter le focus sur la cellule de la ligne cree
getHandler().setFocusOnCell(row);
}
}
......@@ -150,6 +150,22 @@ public class OperationMeasurementsGroupedTableUIHandler
// update some controls
getUI().processDataBinding(OperationMeasurementsGroupedTableUI.BINDING_INIT_DATA_GRID_BUTTON_ENABLED);
break;
// TODO ? force sort on sampling operation and transition column
// case OperationMeasurementsGroupedTableUIModel.PROPERTY_PIT_TRANSITION_LENGTH_PMFM_ID:
//
// // Try to apply sort on sampling operation and transition column
// if (getModel().getPitTransitionLengthPmfmId() != null) {
// TableColumnExt samplingColumn = getTable().getColumnExt(OperationMeasurementsGroupedTableModel.SAMPLING);
// PmfmTableColumn transitionColumn = findPmfmColumnByPmfmId(getModel().getPmfmColumns(), getModel().getPitTransitionLengthPmfmId());
// if (samplingColumn != null && transitionColumn != null) {
// getTable().getRowSorter().setSortKeys(ImmutableList.of(
// new RowSorter.SortKey(samplingColumn.getModelIndex(), SortOrder.ASCENDING),
// new RowSorter.SortKey(transitionColumn.getModelIndex(), SortOrder.ASCENDING)
// ));
// }
// }
// break;
}
});
......@@ -429,15 +445,14 @@ public class OperationMeasurementsGroupedTableUIHandler
for (Integer transition : initModel.getResultMap().get(samplingOperation)) {
// Compute next individual id
incrementNextIndividualId(samplingOperation, individualId);
OperationMeasurementsGroupedRowModel row = getTableModel().createNewRow();
// Initialize the row
row.setSamplingOperation(samplingOperation);
// Affect individual pmfms from parent model
row.setIndividualPmfms(new ArrayList<>(getModel().getPmfms()));
OperationMeasurementsGroupedRowModel row = createNewRow(false, samplingOperation);
// Set the individualId
row.setIndividualId(individualId.get());
// Affect individual pmfms from parent model
row.setIndividualPmfms(new ArrayList<>(getModel().getPmfms()));
// Create empty measurements
ReefDbBeans.createEmptyMeasurements(row);
// Get the measurement
......@@ -460,14 +475,6 @@ public class OperationMeasurementsGroupedTableUIHandler
}
}
private void incrementNextIndividualId(SamplingOperationDTO samplingOperation, AtomicInteger nextIndividualId) {
do {
nextIndividualId.incrementAndGet();
} while (getModel().getRows().stream().anyMatch(row ->
samplingOperation.equals(row.getSamplingOperation()) && nextIndividualId.get() == row.getIndividualId()));
}
public void editSelectedMeasurements() {
OperationMeasurementsMultiEditUI editUI = new OperationMeasurementsMultiEditUI(getUI());
......
......@@ -44,6 +44,7 @@ public class OperationMeasurementsGroupedTableUIModel
* property identifier used to propagate row sampling operation property change to parent
*/
public static final String PROPERTY_SAMPLING_OPERATION = "samplingOperation";
public static final String PROPERTY_PIT_TRANSITION_LENGTH_PMFM_ID = "pitTransitionLengthPmfmId";
// pmfm ids for grid initialization (pit protocol)
private Integer pitTransectOriginPmfmId;
......@@ -85,6 +86,7 @@ public class OperationMeasurementsGroupedTableUIModel
public void setPitTransitionLengthPmfmId(Integer pitTransitionLengthPmfmId) {
this.pitTransitionLengthPmfmId = pitTransitionLengthPmfmId;
firePropertyChange(PROPERTY_PIT_TRANSITION_LENGTH_PMFM_ID, null, pitTransitionLengthPmfmId);
}
public boolean isPitTransitionGridInitializationEnabled() {
......
......@@ -442,7 +442,7 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
}
// set default analyst from pmfm strategies (Mantis #42619)
setDefaultAnalyst(ImmutableList.of(newRow));
setDefaultAnalyst(newRow);
// now calculate individual id
calculateIndividualIds(newRow);
......@@ -462,6 +462,10 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
}
}
protected void setDefaultAnalyst(R row) {
setDefaultAnalyst(Collections.singleton(row));
}
protected void setDefaultAnalyst(Collection<R> rows) {
if (CollectionUtils.isEmpty(rows))
......@@ -480,22 +484,43 @@ public abstract class AbstractMeasurementsGroupedTableUIHandler<
MeasurementAware bean = getMeasurementAwareModelForRow(rowToUpdate);
if (bean == null) return;
// Don't "push" all individual ids, use only the next unused number (see Mantis #51520)
AtomicInteger individualId = new AtomicInteger();
incrementNextIndividualId(bean, individualId);
rowToUpdate.setIndividualId(individualId.get());
rowToUpdate.getIndividualMeasurements().forEach(measurement -> measurement.setIndividualId(individualId.get()));
// iterate over all ordered rows and set incremental individualId
getModel().getRows().stream().filter(getRowForBeanPredicate(bean)).forEach(row -> {
row.setIndividualId(individualId.incrementAndGet());
// update all individual measurements
if (CollectionUtils.isNotEmpty(row.getIndividualMeasurements())) {
for (MeasurementDTO individualMeasurement : row.getIndividualMeasurements()) {
individualMeasurement.setIndividualId(individualId.get());
}
}
});
// getModel().getRows().stream().filter(getRowForBeanPredicate(bean)).forEach(row -> {
// row.setIndividualId(individualId.incrementAndGet());
// // update all individual measurements
// if (CollectionUtils.isNotEmpty(row.getIndividualMeasurements())) {
// for (MeasurementDTO individualMeasurement : row.getIndividualMeasurements()) {
// individualMeasurement.setIndividualId(individualId.get());
// }
// }
// });
setDirty(bean);
}
/**
* Increment the nextIndividualId to next unused individual id in rows
*
* @param bean the current bean
* @param nextIndividualId the counter to increment
*/
protected void incrementNextIndividualId(MeasurementAware bean, AtomicInteger nextIndividualId) {
do {
nextIndividualId.incrementAndGet();
} while (getModel().getRows().stream()
.filter(getRowForBeanPredicate(bean))
.anyMatch(row -> Objects.equals(nextIndividualId.get(), row.getIndividualId())));
Assert.isTrue(nextIndividualId.get() > 0, "the next individual id must be > 0");
}
/**
* return a predicate to tell if the row is associated to the bean (true by default)
*
......
package fr.ifremer.reefdb.ui.swing.content.observation.survey.measurement.grouped;
/*
* #%L
* Reef DB :: UI
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2014 - 2015 Ifremer
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import fr.ifremer.reefdb.dto.ReefDbBeans;
import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbAction;
/**
* Action dupliquer mesure (ecran observation/mesure).
*/
@Deprecated
public class DuplicateSurveyMeasurementsAction extends AbstractReefDbAction<SurveyMeasurementsGroupedTableUIModel, SurveyMeasurementsGroupedTableUI, SurveyMeasurementsGroupedTableUIHandler> {
/**
* La ligne ajoutee.
*/
private SurveyMeasurementsGroupedRowModel row;
/**
* Constrcuteur.
*
* @param handler Controller
*/
public DuplicateSurveyMeasurementsAction(final SurveyMeasurementsGroupedTableUIHandler handler) {
super(handler, false);
}
/** {@inheritDoc} */
@Override
public boolean prepareAction() throws Exception {
return super.prepareAction() && getModel().getSelectedRows().size() == 1;
}
/** {@inheritDoc} */
@Override
public void doAction() {
// Selected measurement
final SurveyMeasurementsGroupedRowModel rowToDuplicate = getModel().getSelectedRows().iterator().next();
if (rowToDuplicate != null) {
row = new SurveyMeasurementsGroupedRowModel(false);
row.setTaxonGroup(rowToDuplicate.getTaxonGroup());
row.setTaxon(rowToDuplicate.getTaxon());
row.setInputTaxonId(rowToDuplicate.getInputTaxonId());
row.setInputTaxonName(rowToDuplicate.getInputTaxonName());
row.setComment(rowToDuplicate.getComment());
row.setIndividualPmfms(rowToDuplicate.getIndividualPmfms());
// add also analyst (MAntis #45054)
row.setAnalyst(rowToDuplicate.getAnalyst());
// duplicate measurements
row.setIndividualMeasurements(ReefDbBeans.duplicate(rowToDuplicate.getIndividualMeasurements()));
}
}
/** {@inheritDoc} */
@Override
public void postSuccessAction() {
super.postSuccessAction();
// Add duplicate measurement to table
getModel().insertRowAfterSelected(row);
// save directly to sampling operation
getHandler().saveMeasurementsInModel(row);
getHandler().recomputeRowsValidState();
getModel().setModify(true);
// Ajouter le focus sur la cellule de la ligne cree
getHandler().setFocusOnCell(row);
}
}
......@@ -31,6 +31,12 @@
</properties>
<body>
<release version="3.9.7" date="2020-03-19" description="Stable release">
<action dev="ludovic.pecquot@e-is.pro" type="fix" issue="51520">
Filter individual measurements when building rows to exclude measurements with negative id
</action>
</release>
<release version="3.9.6" date="2020-03-06" description="Stable release">
<action dev="ludovic.pecquot@e-is.pro" type="fix" issue="51385">
Upgrade quadrige3-core to version 3.6.11
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment