Commit e837a913 authored by LAVENIER's avatar LAVENIER
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents 7f690612 5857d13a
...@@ -22,15 +22,12 @@ package net.sumaris.core.dao.data; ...@@ -22,15 +22,12 @@ package net.sumaris.core.dao.data;
* #L% * #L%
*/ */
import net.sumaris.core.model.data.Landing;
import net.sumaris.core.model.data.PhysicalGear; import net.sumaris.core.model.data.PhysicalGear;
import net.sumaris.core.vo.data.LandingVO;
import net.sumaris.core.vo.data.PhysicalGearVO; import net.sumaris.core.vo.data.PhysicalGearVO;
import net.sumaris.core.vo.filter.LandingFilterVO;
import net.sumaris.core.vo.filter.PhysicalGearFilterVO; import net.sumaris.core.vo.filter.PhysicalGearFilterVO;
public interface PhysicalGearRepository extends public interface PhysicalGearRepository extends
DataRepository<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>, RootDataRepository<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>,
PhysicalGearRepositoryExtend { PhysicalGearRepositoryExtend {
} }
...@@ -47,7 +47,7 @@ import java.util.Map; ...@@ -47,7 +47,7 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class PhysicalGearRepositoryImpl public class PhysicalGearRepositoryImpl
extends DataRepositoryImpl<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO> extends RootDataRepositoryImpl<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>
implements PhysicalGearRepositoryExtend { implements PhysicalGearRepositoryExtend {
private static final Logger log = private static final Logger log =
......
...@@ -3,7 +3,6 @@ package net.sumaris.core.service.data; ...@@ -3,7 +3,6 @@ package net.sumaris.core.service.data;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import net.sumaris.core.dao.data.BatchDao; import net.sumaris.core.dao.data.BatchDao;
import net.sumaris.core.dao.data.MeasurementDao; import net.sumaris.core.dao.data.MeasurementDao;
import net.sumaris.core.dao.referential.pmfm.PmfmDao;
import net.sumaris.core.dao.referential.ReferentialDao; import net.sumaris.core.dao.referential.ReferentialDao;
import net.sumaris.core.dao.technical.Daos; import net.sumaris.core.dao.technical.Daos;
import net.sumaris.core.exception.SumarisTechnicalException; import net.sumaris.core.exception.SumarisTechnicalException;
...@@ -77,15 +76,7 @@ public class PacketServiceImpl implements PacketService { ...@@ -77,15 +76,7 @@ public class PacketServiceImpl implements PacketService {
@Override @Override
public List<PacketVO> saveByOperationId(int operationId, List<PacketVO> sources) { public List<PacketVO> saveByOperationId(int operationId, List<PacketVO> sources) {
Preconditions.checkNotNull(sources); checkPackets(sources);
sources.forEach(source -> {
Preconditions.checkNotNull(source.getNumber());
Preconditions.checkArgument(source.getNumber() > 0);
Preconditions.checkNotNull(source.getRankOrder());
Preconditions.checkNotNull(source.getWeight());
Preconditions.checkArgument(CollectionUtils.isNotEmpty(source.getSampledWeights()));
Preconditions.checkArgument(CollectionUtils.isNotEmpty(source.getComposition()));
});
// Batches list to save // Batches list to save
List<BatchVO> batches = new ArrayList<>(); List<BatchVO> batches = new ArrayList<>();
...@@ -155,6 +146,23 @@ public class PacketServiceImpl implements PacketService { ...@@ -155,6 +146,23 @@ public class PacketServiceImpl implements PacketService {
// return getAllByOperationId(operationId); // return getAllByOperationId(operationId);
} }
private void checkPackets(List<PacketVO> sources) {
Preconditions.checkNotNull(sources);
sources.forEach(this::checkPacket);
}
private void checkPacket(PacketVO source) {
Preconditions.checkNotNull(source);
Preconditions.checkNotNull(source.getNumber());
Preconditions.checkArgument(source.getNumber() > 0);
Preconditions.checkNotNull(source.getRankOrder());
Preconditions.checkNotNull(source.getWeight());
Preconditions.checkArgument(CollectionUtils.isNotEmpty(source.getSampledWeights()));
Preconditions.checkArgument(CollectionUtils.isNotEmpty(source.getComposition()));
Preconditions.checkNotNull(source.getRecorderDepartment(), "Missing recorderDepartment");
Preconditions.checkNotNull(source.getRecorderDepartment().getId(), "Missing recorderDepartment.id");
}
private List<BatchVO> toBatchVOs(List<PacketVO> sources, BatchVO rootBatch) { private List<BatchVO> toBatchVOs(List<PacketVO> sources, BatchVO rootBatch) {
return sources.stream().flatMap(packet -> toBatchVO(packet, rootBatch).stream()).collect(Collectors.toList()); return sources.stream().flatMap(packet -> toBatchVO(packet, rootBatch).stream()).collect(Collectors.toList());
} }
...@@ -426,7 +434,7 @@ public class PacketServiceImpl implements PacketService { ...@@ -426,7 +434,7 @@ public class PacketServiceImpl implements PacketService {
// number // number
Double averageWeight = referenceWeight / target.getSampledWeights().size(); Double averageWeight = referenceWeight / target.getSampledWeights().size();
target.setNumber((int) (target.getWeight() / averageWeight)); target.setNumber(Daos.roundValue(target.getWeight() / averageWeight).intValue());
// composition // composition
target.setComposition(source.getChildren().stream() target.setComposition(source.getChildren().stream()
......
...@@ -8,10 +8,8 @@ import net.sumaris.core.vo.filter.ProductFilterVO; ...@@ -8,10 +8,8 @@ import net.sumaris.core.vo.filter.ProductFilterVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -51,9 +49,7 @@ public class ProductServiceImpl implements ProductService { ...@@ -51,9 +49,7 @@ public class ProductServiceImpl implements ProductService {
@Override @Override
public ProductVO save(ProductVO product) { public ProductVO save(ProductVO product) {
Preconditions.checkNotNull(product); checkProduct(product);
Preconditions.checkNotNull(product.getRecorderDepartment(), "Missing recorderDepartment");
Preconditions.checkNotNull(product.getRecorderDepartment().getId(), "Missing recorderDepartment.id");
// Save // Save
return productRepository.save(product); return productRepository.save(product);
...@@ -69,16 +65,19 @@ public class ProductServiceImpl implements ProductService { ...@@ -69,16 +65,19 @@ public class ProductServiceImpl implements ProductService {
@Override @Override
public List<ProductVO> saveByLandingId(int landingId, List<ProductVO> products) { public List<ProductVO> saveByLandingId(int landingId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveByLandingId(landingId, products); return productRepository.saveByLandingId(landingId, products);
} }
@Override @Override
public List<ProductVO> saveByOperationId(int operationId, List<ProductVO> products) { public List<ProductVO> saveByOperationId(int operationId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveByOperationId(operationId, products); return productRepository.saveByOperationId(operationId, products);
} }
@Override @Override
public List<ProductVO> saveBySaleId(int saleId, List<ProductVO> products) { public List<ProductVO> saveBySaleId(int saleId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveBySaleId(saleId, products); return productRepository.saveBySaleId(saleId, products);
} }
...@@ -129,34 +128,16 @@ public class ProductServiceImpl implements ProductService { ...@@ -129,34 +128,16 @@ public class ProductServiceImpl implements ProductService {
productRepository.fillMeasurementsMap(product); productRepository.fillMeasurementsMap(product);
} }
private void copyMeasurements(List<ProductVO> products) { /* protected methods */
if (products == null) return;
products.forEach(this::copyMeasurements);
protected void checkProducts(final List<ProductVO> sources) {
Preconditions.checkNotNull(sources);
sources.forEach(this::checkProduct);
} }
protected void checkProduct(final ProductVO source) {
private void copyMeasurements(ProductVO product) { Preconditions.checkNotNull(source);
Preconditions.checkNotNull(source.getRecorderDepartment(), "Missing recorderDepartment");
if (product == null) return; Preconditions.checkNotNull(source.getRecorderDepartment().getId(), "Missing recorderDepartment.id");
if (product.getMeasurementValues() != null) {
Set<Integer> pmfmToRemove = new HashSet<>();
product.getMeasurementValues().forEach((pmfmId, value) -> {
if (pmfmService.isWeightPmfm(pmfmId)) {
pmfmToRemove.add(pmfmId);
// product.setWeight(value);
if (pmfmService.isCalculatedPmfm(pmfmId)) {
}
}
});
}
} }
} }
...@@ -29,7 +29,7 @@ import java.util.Date; ...@@ -29,7 +29,7 @@ import java.util.Date;
@Data @Data
@FieldNameConstants @FieldNameConstants
public class PhysicalGearFilterVO implements IVesselFilter { public class PhysicalGearFilterVO implements IRootDataFilter, IVesselFilter {
private Integer tripId; private Integer tripId;
...@@ -41,4 +41,8 @@ public class PhysicalGearFilterVO implements IVesselFilter { ...@@ -41,4 +41,8 @@ public class PhysicalGearFilterVO implements IVesselFilter {
private String programLabel; private String programLabel;
private Integer recorderDepartmentId;
private Integer locationId;
} }
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