Commit b8057e83 authored by PECQUOT's avatar PECQUOT
Browse files

[fix] remove OperationGroupVO.physicalGear. It will be saved by Trip

[fix] a SaleMeasurement can be saved with and ExpectedSale parent
parent 90e1a60f
......@@ -95,10 +95,10 @@ public interface MeasurementDao {
Map<Integer, String> saveSaleMeasurementsMap(int saleId, Map<Integer, String> sources);
// Expected Sale
List<MeasurementVO> getExpectedSaleMeasurements(int saleId);
Map<Integer, String> getExpectedSaleMeasurementsMap(int saleId);
List<MeasurementVO> saveExpectedSaleMeasurements(int saleId, List<MeasurementVO> sources);
Map<Integer, String> saveExpectedSaleMeasurementsMap(int saleId, Map<Integer, String> sources);
List<MeasurementVO> getExpectedSaleMeasurements(int expectedSaleId);
Map<Integer, String> getExpectedSaleMeasurementsMap(int expectedSaleId);
List<MeasurementVO> saveExpectedSaleMeasurements(int expectedSaleId, List<MeasurementVO> sources);
Map<Integer, String> saveExpectedSaleMeasurementsMap(int expectedSaleId, Map<Integer, String> sources);
// Landing
List<MeasurementVO> saveLandingMeasurements(int landingId, List<MeasurementVO> sources);
......
......@@ -112,6 +112,9 @@ public class MeasurementDaoImpl extends HibernateDaoSupport implements Measureme
// Sale
result.put(SaleMeasurement.class, BeanUtils.getPropertyDescriptor(SaleMeasurement.class, SaleMeasurement.Fields.SALE));
// ExpectedSale
result.put(SaleMeasurement.class, BeanUtils.getPropertyDescriptor(SaleMeasurement.class, SaleMeasurement.Fields.EXPECTED_SALE));
// Landing
result.put(LandingMeasurement.class, BeanUtils.getPropertyDescriptor(LandingMeasurement.class, LandingMeasurement.Fields.LANDING));
......@@ -367,20 +370,20 @@ public class MeasurementDaoImpl extends HibernateDaoSupport implements Measureme
}
@Override
public List<MeasurementVO> getExpectedSaleMeasurements(int saleId) {
public List<MeasurementVO> getExpectedSaleMeasurements(int expectedSaleId) {
return getMeasurementsByParentId(SaleMeasurement.class,
MeasurementVO.class,
SaleMeasurement.Fields.EXPECTED_SALE,
saleId,
expectedSaleId,
SaleMeasurement.Fields.ID
);
}
@Override
public Map<Integer, String> getExpectedSaleMeasurementsMap(int saleId) {
public Map<Integer, String> getExpectedSaleMeasurementsMap(int expectedSaleId) {
return getMeasurementsMapByParentId(SaleMeasurement.class,
SaleMeasurement.Fields.EXPECTED_SALE,
saleId,
expectedSaleId,
null
);
}
......@@ -494,14 +497,14 @@ public class MeasurementDaoImpl extends HibernateDaoSupport implements Measureme
}
@Override
public List<MeasurementVO> saveExpectedSaleMeasurements(int saleId, List<MeasurementVO> sources) {
ExpectedSale parent = getById(ExpectedSale.class, saleId);
public List<MeasurementVO> saveExpectedSaleMeasurements(int expectedSaleId, List<MeasurementVO> sources) {
ExpectedSale parent = getById(ExpectedSale.class, expectedSaleId);
return saveMeasurements(SaleMeasurement.class, sources, parent.getMeasurements(), parent);
}
@Override
public Map<Integer, String> saveExpectedSaleMeasurementsMap(int saleId, Map<Integer, String> sources) {
ExpectedSale parent = getById(ExpectedSale.class, saleId);
public Map<Integer, String> saveExpectedSaleMeasurementsMap(int expectedSaleId, Map<Integer, String> sources) {
ExpectedSale parent = getById(ExpectedSale.class, expectedSaleId);
return saveMeasurementsMap(SaleMeasurement.class, sources, parent.getMeasurements(), parent);
}
......
......@@ -127,7 +127,6 @@ public class OperationGroupRepositoryImpl
// Physical gear
if (source.getPhysicalGear() != null) {
target.setPhysicalGearId(source.getPhysicalGear().getId());
target.setPhysicalGear(physicalGearRepository.toVO(source.getPhysicalGear(), DataFetchOptions.builder().withRecorderDepartment(false).build()));
}
// Metier
......@@ -213,14 +212,11 @@ public class OperationGroupRepositoryImpl
}
// Physical gear
if (copyIfNull || source.getPhysicalGearId() != null || (source.getPhysicalGear() != null && source.getPhysicalGear().getId() != null)) {
Integer physicalGearId = source.getPhysicalGearId() != null ? source.getPhysicalGearId() : (
source.getPhysicalGear() != null ? source.getPhysicalGear().getId() : null
);
if (physicalGearId == null) {
if (copyIfNull || source.getPhysicalGearId() != null) {
if (source.getPhysicalGearId() == null) {
target.setPhysicalGear(null);
} else {
target.setPhysicalGear(getReference(PhysicalGear.class, physicalGearId));
target.setPhysicalGear(getReference(PhysicalGear.class, source.getPhysicalGearId()));
}
}
......
......@@ -624,7 +624,6 @@ public class AggregatedLandingServiceImpl implements AggregatedLandingService {
PhysicalGearVO physicalGear = new PhysicalGearVO();
physicalGear.setGear(metier.getGear());
physicalGear.setRankOrder(rankOrder);
operationGroup.setPhysicalGear(physicalGear);
return operationGroup;
}
......
......@@ -468,28 +468,20 @@ public class TripServiceImpl implements TripService {
}
protected void fillOperationGroupPhysicalGears(List<OperationGroupVO> sources, List<PhysicalGearVO> physicalGears) {
Map<Integer, PhysicalGearVO> physicalGearsById = Beans.splitById(physicalGears);
Multimap<Integer, PhysicalGearVO> physicalGearsByGearId = Beans.splitByNotUniqueProperty(physicalGears, PhysicalGearVO.Fields.GEAR + "." + ReferentialVO.Fields.ID);
// Affect physical gears from savedTrip.getGears, because new oG can have a physicalGear with null id
sources.forEach(source -> {
PhysicalGearVO physicalGear = source.getPhysicalGear();
if (physicalGear == null) {
if (source.getPhysicalGearId() != null) {
physicalGear = physicalGearsById.get(source.getPhysicalGearId());
}
} else if (physicalGear.getId() == null && physicalGear.getGear() != null && physicalGear.getGear().getId() != null) {
// case of new operation group with unsaved physical gear
// try to find it with trip's gears
Collection<PhysicalGearVO> matches = physicalGearsByGearId.get(physicalGear.getGear().getId());
if (CollectionUtils.isNotEmpty(matches)) {
physicalGear = matches.iterator().next();
}
if (source.getPhysicalGearId() == null && source.getMetier() != null && source.getMetier().getGear() != null) {
Collection<PhysicalGearVO> matches = Beans.getList(physicalGearsByGearId.get(source.getMetier().getGear().getId()));
matches.stream()
.filter(physicalGearVO -> Objects.equals(physicalGearVO.getRankOrder(), source.getRankOrderOnPeriod()))
.findFirst()
.ifPresent(physicalGearVO -> source.setPhysicalGearId(physicalGearVO.getId()));
}
// Assert PhysicalGear
Preconditions.checkNotNull(physicalGear, "OperationGroup has no valid PhysicalGear");
source.setPhysicalGear(physicalGear);
Preconditions.checkNotNull(source.getPhysicalGearId(), "OperationGroup has no valid PhysicalGearId");
});
}
......@@ -551,7 +543,7 @@ public class TripServiceImpl implements TripService {
if (physicalGear.getId() != null) {
// Find with id
operationGroup = operationGroups.stream()
.filter(og -> og.getPhysicalGear() != null ? physicalGear.getId().equals(og.getPhysicalGear().getId()) : physicalGear.getId().equals(og.getPhysicalGearId()))
.filter(og -> physicalGear.getId().equals(og.getPhysicalGearId()))
.findFirst().orElseThrow(() -> new SumarisTechnicalException(String.format("OperationGroup with PhysicalGear#%s not found", physicalGear.getId())));
} else {
......@@ -562,9 +554,9 @@ public class TripServiceImpl implements TripService {
// Find with gear and rank order
operationGroup = operationGroups.stream()
.filter(og -> og.getPhysicalGear() != null && og.getPhysicalGear().getGear() != null
&& physicalGear.getGear().getId().equals(og.getPhysicalGear().getGear().getId())
&& physicalGear.getRankOrder().equals(og.getPhysicalGear().getRankOrder()))
.filter(og -> og.getMetier() != null && og.getMetier().getGear() != null
&& physicalGear.getGear().getId().equals(og.getMetier().getGear().getId())
&& physicalGear.getRankOrder().equals(og.getRankOrderOnPeriod()))
.findFirst().orElseThrow(() -> new SumarisTechnicalException(
String.format("Operation with PhysicalGear.gear#%s and PhysicalGear.rankOrder#%s not found in OperationGroups",
physicalGear.getGear().getId(), physicalGear.getRankOrder()))
......
......@@ -59,8 +59,6 @@ public class OperationGroupVO implements IDataVO<Integer> {
private TripVO trip;
private Integer tripId;
@ToString.Exclude
private PhysicalGearVO physicalGear; // todo to remove ?
private Integer physicalGearId;
private List<MeasurementVO> measurements;
......
......@@ -22,6 +22,7 @@ package net.sumaris.core.vo.data;
* #L%
*/
import io.leangen.graphql.annotations.GraphQLIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
......@@ -49,6 +50,8 @@ public class TripSaveOptions implements ISaveOptions {
@Builder.Default
private Boolean withLanding = false;
@GraphQLIgnore
private Integer landingId;
@GraphQLIgnore
private Integer observedLocationId;
}
......@@ -48,7 +48,6 @@ public class PmfmVO extends ReferentialVO {
private Boolean isCalculated; // from the method
// Link to other entities
private Integer parameterGroupId;
private Integer parameterId;
private Integer matrixId;
private Integer fractionId;
......
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