Commit 5857d13a authored by PECQUOT's avatar PECQUOT
Browse files

[fix] change PhysicalGearRepository to a RootDataRepository


[enh] ProductService and PacketService improvements
Signed-off-by: PECQUOT's avatarlp1ee9d <ludovic.pecquot@e-is.pro>
parent 9296d687
......@@ -22,15 +22,12 @@ package net.sumaris.core.dao.data;
* #L%
*/
import net.sumaris.core.model.data.Landing;
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.filter.LandingFilterVO;
import net.sumaris.core.vo.filter.PhysicalGearFilterVO;
public interface PhysicalGearRepository extends
DataRepository<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>,
RootDataRepository<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>,
PhysicalGearRepositoryExtend {
}
......@@ -47,7 +47,7 @@ import java.util.Map;
import java.util.stream.Collectors;
public class PhysicalGearRepositoryImpl
extends DataRepositoryImpl<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>
extends RootDataRepositoryImpl<PhysicalGear, Integer, PhysicalGearVO, PhysicalGearFilterVO>
implements PhysicalGearRepositoryExtend {
private static final Logger log =
......
......@@ -3,7 +3,6 @@ package net.sumaris.core.service.data;
import com.google.common.base.Preconditions;
import net.sumaris.core.dao.data.BatchDao;
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.technical.Daos;
import net.sumaris.core.exception.SumarisTechnicalException;
......@@ -77,15 +76,7 @@ public class PacketServiceImpl implements PacketService {
@Override
public List<PacketVO> saveByOperationId(int operationId, List<PacketVO> sources) {
Preconditions.checkNotNull(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()));
});
checkPackets(sources);
// Batches list to save
List<BatchVO> batches = new ArrayList<>();
......@@ -155,6 +146,23 @@ public class PacketServiceImpl implements PacketService {
// 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) {
return sources.stream().flatMap(packet -> toBatchVO(packet, rootBatch).stream()).collect(Collectors.toList());
}
......@@ -426,7 +434,7 @@ public class PacketServiceImpl implements PacketService {
// number
Double averageWeight = referenceWeight / target.getSampledWeights().size();
target.setNumber((int) (target.getWeight() / averageWeight));
target.setNumber(Daos.roundValue(target.getWeight() / averageWeight).intValue());
// composition
target.setComposition(source.getChildren().stream()
......
......@@ -8,10 +8,8 @@ import net.sumaris.core.vo.filter.ProductFilterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
......@@ -51,9 +49,7 @@ public class ProductServiceImpl implements ProductService {
@Override
public ProductVO save(ProductVO product) {
Preconditions.checkNotNull(product);
Preconditions.checkNotNull(product.getRecorderDepartment(), "Missing recorderDepartment");
Preconditions.checkNotNull(product.getRecorderDepartment().getId(), "Missing recorderDepartment.id");
checkProduct(product);
// Save
return productRepository.save(product);
......@@ -69,16 +65,19 @@ public class ProductServiceImpl implements ProductService {
@Override
public List<ProductVO> saveByLandingId(int landingId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveByLandingId(landingId, products);
}
@Override
public List<ProductVO> saveByOperationId(int operationId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveByOperationId(operationId, products);
}
@Override
public List<ProductVO> saveBySaleId(int saleId, List<ProductVO> products) {
checkProducts(products);
return productRepository.saveBySaleId(saleId, products);
}
......@@ -129,34 +128,16 @@ public class ProductServiceImpl implements ProductService {
productRepository.fillMeasurementsMap(product);
}
private void copyMeasurements(List<ProductVO> products) {
if (products == null) return;
products.forEach(this::copyMeasurements);
/* protected methods */
protected void checkProducts(final List<ProductVO> sources) {
Preconditions.checkNotNull(sources);
sources.forEach(this::checkProduct);
}
private void copyMeasurements(ProductVO product) {
if (product == null) return;
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)) {
}
}
});
}
protected void checkProduct(final ProductVO source) {
Preconditions.checkNotNull(source);
Preconditions.checkNotNull(source.getRecorderDepartment(), "Missing recorderDepartment");
Preconditions.checkNotNull(source.getRecorderDepartment().getId(), "Missing recorderDepartment.id");
}
}
......@@ -29,7 +29,7 @@ import java.util.Date;
@Data
@FieldNameConstants
public class PhysicalGearFilterVO implements IVesselFilter {
public class PhysicalGearFilterVO implements IRootDataFilter, IVesselFilter {
private Integer tripId;
......@@ -41,4 +41,8 @@ public class PhysicalGearFilterVO implements IVesselFilter {
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