Commit 0d0359e3 authored by PECQUOT's avatar PECQUOT

[fix] remove unnecessary service methods (moved to static)

Signed-off-by: PECQUOT's avatarlp1ee9d <ludovic.pecquot@e-is.pro>
parent 12c27ca9
......@@ -911,9 +911,9 @@ public final class ReefDbConfiguration extends QuadrigeCoreConfiguration {
if (CollectionUtils.size(pmfmsIdsStr) == 3) {
try {
Integer[] pmfmIds = new Integer[3];
pmfmIds[0] = Integer.parseInt(pmfmsIdsStr.get(0));
pmfmIds[1] = Integer.parseInt(pmfmsIdsStr.get(1));
pmfmIds[2] = Integer.parseInt(pmfmsIdsStr.get(2));
pmfmIds[0] = Integer.parseInt(pmfmsIdsStr.get(0).trim());
pmfmIds[1] = Integer.parseInt(pmfmsIdsStr.get(1).trim());
pmfmIds[2] = Integer.parseInt(pmfmsIdsStr.get(2).trim());
if (pmfmIds[0] < 0 || pmfmIds[1] < 0 || pmfmIds[2] < 0) continue;
......
......@@ -42,6 +42,7 @@ import fr.ifremer.reefdb.dto.configuration.programStrategy.PmfmStrategyDTO;
import fr.ifremer.reefdb.dto.configuration.programStrategy.ProgramDTO;
import fr.ifremer.reefdb.dto.data.measurement.MeasurementAware;
import fr.ifremer.reefdb.dto.data.measurement.MeasurementDTO;
import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
import fr.ifremer.reefdb.dto.data.survey.CampaignDTO;
import fr.ifremer.reefdb.dto.data.survey.SurveyDTO;
import fr.ifremer.reefdb.dto.enums.*;
......@@ -90,36 +91,6 @@ public class ReefDbBeans extends QuadrigeBeans {
}
}
/**
* <p>computeAddress.</p>
*
* @param street a {@link String} object.
* @param zipCode a {@link String} object.
* @param city a {@link String} object.
* @return a {@link String} object.
*/
public static String computeAddress(String street, String zipCode, String city) {
StringBuilder addressBuilder = new StringBuilder();
if (StringUtils.isNotBlank(street)) {
addressBuilder.append(street.replaceAll("[ ]+", " "));
if (StringUtils.isNotBlank(zipCode) || StringUtils.isNotBlank(city)) {
addressBuilder.append(", ");
}
}
if (StringUtils.isNotBlank(zipCode)) {
addressBuilder.append(zipCode);
if (StringUtils.isNotBlank(city)) {
addressBuilder.append(" ");
}
}
if (StringUtils.isNotBlank(city)) {
addressBuilder.append(city);
}
return addressBuilder.toString();
}
public static String toQuotedString(String string) {
return "'" + string.replaceAll("'", "''") + "'";
}
......@@ -189,6 +160,47 @@ public class ReefDbBeans extends QuadrigeBeans {
return bean.toString();
}
public static List<MeasurementDTO> duplicate(List<MeasurementDTO> measurements) {
if (measurements == null)
return new ArrayList<>();
return measurements.stream().map(ReefDbBeans::duplicate).collect(Collectors.toList());
}
public static MeasurementDTO duplicate(MeasurementDTO measurement) {
// Clone object
MeasurementDTO clone = clone(measurement);
// Remove Id & individualId
clone.setId(null);
clone.setIndividualId(null);
// remove errors
clone.setErrors(null);
return clone;
}
public static SamplingOperationDTO duplicate(final SamplingOperationDTO samplingOperation) {
// Clone object
final SamplingOperationDTO clone = clone(samplingOperation);
// Remove ID
clone.setId(null);
// clone coordinate
clone.setCoordinate(clone(samplingOperation.getCoordinate()));
// remove errors
clone.setErrors(null);
// duplicate measurements
clone.setMeasurements(duplicate(samplingOperation.getMeasurements()));
clone.setIndividualMeasurements(duplicate(samplingOperation.getIndividualMeasurements()));
return clone;
}
/**
* <p>filterNotEmptyAppliedPeriod.</p>
*
......
......@@ -26,7 +26,6 @@ package fr.ifremer.reefdb.service.observation;
import fr.ifremer.quadrige3.core.ProgressionCoreModel;
import fr.ifremer.reefdb.dto.configuration.programStrategy.ProgStratDTO;
import fr.ifremer.reefdb.dto.configuration.programStrategy.ProgramDTO;
import fr.ifremer.reefdb.dto.data.measurement.MeasurementDTO;
import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
import fr.ifremer.reefdb.dto.data.survey.CampaignDTO;
import fr.ifremer.reefdb.dto.data.survey.SurveyDTO;
......@@ -128,24 +127,6 @@ public interface ObservationService {
@PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
SurveyDTO duplicateSurvey(SurveyDTO survey, boolean fullDuplication, boolean copyCoordinates, boolean duplicateSurveyMeasurements);
/**
* Duplicate prelevement.
*
* @param samplingOperation Prelevement to duplicate
* @return Prelvement duplicated
*/
@PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
SamplingOperationDTO duplicateSamplingOperation(SamplingOperationDTO samplingOperation);
/**
* Duplicate a list of measurements.
*
* @param measurements Measurements to duplicate
* @return Measurements duplicate
*/
@PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
List<MeasurementDTO> duplicateMeasurements(List<MeasurementDTO> measurements);
/**
* <p>getAvailablePrograms.</p>
*
......
......@@ -538,59 +538,6 @@ public class ObservationServiceImpl implements ObservationInternalService {
}
/**
* {@inheritDoc}
*/
@Override
public SamplingOperationDTO duplicateSamplingOperation(final SamplingOperationDTO samplingOperation) {
// Duplicate sampling operation
final SamplingOperationDTO duplicatedSamplingOperation = ReefDbBeans.clone(samplingOperation);
// Remove ID
duplicatedSamplingOperation.setId(null);
// duplicate coordinate
duplicatedSamplingOperation.setCoordinate(ReefDbBeans.clone(samplingOperation.getCoordinate()));
// remove errors
duplicatedSamplingOperation.setErrors(null);
// duplicate measurements
duplicatedSamplingOperation.setMeasurements(duplicateMeasurements(samplingOperation.getMeasurements()));
duplicatedSamplingOperation.setIndividualMeasurements(duplicateMeasurements(samplingOperation.getIndividualMeasurements()));
return duplicatedSamplingOperation;
}
/**
* {@inheritDoc}
*/
@Override
public List<MeasurementDTO> duplicateMeasurements(List<MeasurementDTO> measurements) {
List<MeasurementDTO> duplicatedMeasurements = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(measurements)) {
for (MeasurementDTO measurement : measurements) {
// duplicated measurement
final MeasurementDTO duplicatedMeasurement = ReefDbBeans.clone(measurement);
// Remove Id & individualId
duplicatedMeasurement.setId(null);
duplicatedMeasurement.setIndividualId(null);
// remove errors
duplicatedMeasurement.setErrors(null);
duplicatedMeasurements.add(duplicatedMeasurement);
}
}
return duplicatedMeasurements;
}
/**
* {@inheritDoc}
*/
......
......@@ -23,12 +23,15 @@ package fr.ifremer.reefdb.ui.swing.content.home.operation;
* #L%
*/
import fr.ifremer.reefdb.dto.ReefDbBeans;
import fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO;
import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbAction;
/**
* Duplicate sampling operation action.
* {@link Deprecated} Use fr.ifremer.reefdb.dto.ReefDbBeans#duplicate(fr.ifremer.reefdb.dto.data.sampling.SamplingOperationDTO) outside an action
*/
@Deprecated
public class DuplicateOperationAction extends AbstractReefDbAction<OperationsTableUIModel, OperationsTableUI, OperationsTableUIHandler> {
/**
......@@ -60,12 +63,10 @@ public class DuplicateOperationAction extends AbstractReefDbAction<OperationsTab
if (operationsTableRowModel != null) {
// Duplicate operation
final SamplingOperationDTO duplicatePrelevement = getContext().getObservationService().duplicateSamplingOperation(operationsTableRowModel.toBean());
if (duplicatePrelevement != null) {
// Add duplicate operation to table
newRow = getModel().addNewRow(duplicatePrelevement);
}
final SamplingOperationDTO duplicateOperation = ReefDbBeans.duplicate(operationsTableRowModel.toBean());
// Add duplicate operation to table
newRow = getModel().addNewRow(duplicateOperation);
}
}
......
......@@ -439,13 +439,11 @@ public class AddOperationTableUIHandler extends AbstractReefDbTableUIHandler<Ope
for (int i = 0; i < nbOperation; i++) {
// Ajout du prelevement dans la liste
final SamplingOperationDTO newOperation = getContext().getObservationService().duplicateSamplingOperation(operation);
if (newOperation != null) {
operations.add(newOperation);
final SamplingOperationDTO newOperation = ReefDbBeans.duplicate(operation);
operations.add(newOperation);
// do it at creation time
newOperation.setMeasurementsLoaded(true);
}
// do it at creation time
newOperation.setMeasurementsLoaded(true);
}
// Ajout des prelevements
......
......@@ -23,11 +23,13 @@ package fr.ifremer.reefdb.ui.swing.content.observation.operation.measurement.gro
* #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> {
/**
......@@ -69,8 +71,8 @@ public class DuplicateOperationMeasurementsAction extends AbstractReefDbAction<O
row.setIndividualPmfms(rowToDuplicate.getIndividualPmfms());
// add also analyst (MAntis #45054)
row.setAnalyst(rowToDuplicate.getAnalyst());
// duplicate measurements by service
row.setIndividualMeasurements(getContext().getObservationService().duplicateMeasurements(rowToDuplicate.getIndividualMeasurements()));
// duplicate measurements
row.setIndividualMeasurements(ReefDbBeans.duplicate(rowToDuplicate.getIndividualMeasurements()));
}
}
......
......@@ -60,7 +60,7 @@
<JPanel id='tableauBasPanelButtons' layout='{new BorderLayout()}' constraints="BorderLayout.PAGE_END">
<JPanel layout='{new FlowLayout()}' constraints='BorderLayout.LINE_START'>
<JButton id='addButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="model.insertNewRowAfterSelected()"/>
<JButton id='duplicateButton' alignmentX='{Component.CENTER_ALIGNMENT}'/>
<JButton id='duplicateButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.duplicateSelectedRow()"/>
<JButton id='initDataGridButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.initializeDataGrid()"/>
<JButton id='multiEditButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.editSelectedMeasurements()"/>
<JButton id='deleteButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.removeIndividualMeasurements()"/>
......
......@@ -52,7 +52,6 @@
actionIcon: copy;
text: "reefdb.action.duplicate.label";
toolTipText: "reefdb.action.duplicate.measurement.tip";
_applicationAction: {DuplicateOperationMeasurementsAction.class};
enabled: {model.getSurvey().isEditable() && !model.getSelectedRows().isEmpty() && (model.getSelectedRows().size() == 1) && !model.getPmfms().isEmpty()};
}
......
......@@ -235,6 +235,14 @@ public class OperationMeasurementsGroupedTableUIHandler
super.onRowModified(rowIndex, row, propertyName, propertyIndex, oldValue, newValue);
}
@Override
protected void onDuplicatedRowAdded(OperationMeasurementsGroupedRowModel row) {
// send update event on sampling operation
if (row.getSamplingOperation() != null) {
getModel().firePropertyChanged(OperationMeasurementsGroupedTableUIModel.PROPERTY_SAMPLING_OPERATION, null, row.getSamplingOperation());
}
}
@Override
protected void resetIndividualMeasurementIds(OperationMeasurementsGroupedRowModel row) {
......
......@@ -23,11 +23,13 @@ package fr.ifremer.reefdb.ui.swing.content.observation.survey.measurement.groupe
* #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> {
/**
......@@ -68,9 +70,8 @@ public class DuplicateSurveyMeasurementsAction extends AbstractReefDbAction<Surv
row.setIndividualPmfms(rowToDuplicate.getIndividualPmfms());
// add also analyst (MAntis #45054)
row.setAnalyst(rowToDuplicate.getAnalyst());
// duplicate measurements by service
row.setIndividualMeasurements(getContext().getObservationService().duplicateMeasurements(rowToDuplicate.getIndividualMeasurements()));
// duplicate measurements
row.setIndividualMeasurements(ReefDbBeans.duplicate(rowToDuplicate.getIndividualMeasurements()));
}
}
......
......@@ -60,7 +60,7 @@
<JPanel id='tableauBasPanelButtons' layout='{new BorderLayout()}' constraints="BorderLayout.PAGE_END">
<JPanel layout='{new FlowLayout()}' constraints='BorderLayout.LINE_START'>
<JButton id='newButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="model.insertNewRowAfterSelected()"/>
<JButton id='duplicateButton' alignmentX='{Component.CENTER_ALIGNMENT}'/>
<JButton id='duplicateButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.duplicateSelectedRow()"/>
<JButton id='multiEditButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.editSelectedMeasurements()"/>
<JButton id='deleteButton' alignmentX='{Component.CENTER_ALIGNMENT}' onActionPerformed="handler.removeIndividualMeasurements()"/>
</JPanel>
......
......@@ -52,7 +52,6 @@
actionIcon: copy;
text: "reefdb.action.duplicate.label";
toolTipText: "reefdb.action.duplicate.measurement.tip";
_applicationAction: {DuplicateSurveyMeasurementsAction.class};
enabled: {model.getSurvey().isEditable() && !model.getSelectedRows().isEmpty() && (model.getSelectedRows().size() == 1) && !model.getPmfms().isEmpty()};
}
......
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