use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO in project UVMS-ActivityModule-APP by UnionVMS.
the class TripCatchEvolutionTest method testHandleCumulatedCatchWithDeletion.
@Test
public void testHandleCumulatedCatchWithDeletion() {
FaReportDocumentEntity faReportDocumentEntity = ActivityDataUtil.getFaReportDocumentEntity(FaReportDocumentType.DECLARATION.name(), "FLUX_FA_REPORT_TYPE", DateUtils.parseToUTCDate("2016-06-27 07:47:31", "yyyy-MM-dd HH:mm:ss"), null, null, "new");
FishingActivityEntity fishingActivityEntity = ActivityDataUtil.getFishingActivityEntity(FishingActivityTypeEnum.DISCARD.name(), "FLUX_FA_TYPE", DateUtils.parseToUTCDate("2014-05-27 07:47:31", "yyyy-MM-dd HH:mm:ss"), "FISHING", "FIS", faReportDocumentEntity, null);
FaCatchEntity faCatchEntity = ActivityDataUtil.getFaCatchEntity(fishingActivityEntity, "DEMINIMIS", "FA_CATCH_TYPE", "COD", "FAO_SPECIES", 11112D, 11112.0D, "KGM", "BFT", "WEIGHT_MEANS", null);
faCatchEntity.setCalculatedWeightMeasure(11112D);
CatchEvolutionProgressDTO catchEvolutionProgressDTO = initCatchEvolutionProgressDTO(fishingActivityEntity, FaReportDocumentType.DECLARATION, new HashMap<String, Double>());
SpeciesQuantityDTO speciesQuantityDTO = new SpeciesQuantityDTO();
speciesQuantityDTO.setSpeciesCode("COD");
speciesQuantityDTO.setWeight(1000D);
catchEvolutionProgressDTO.getCatchEvolution().get("cumulated").addSpecieAndQuantity("COD", 11112D, StringUtils.EMPTY);
catchEvolutionProgressDTO.getCatchEvolution().get("onboard").addSpecieAndQuantity("COD", 11112D, StringUtils.EMPTY);
catchEvolutionProgressDTO.getCatchEvolution().get("onboard").addSpecieAndQuantity("HKE", 11112D, StringUtils.EMPTY);
handleCumulatedCatchWithDeletion(faCatchEntity, catchEvolutionProgressDTO, new HashMap<String, Double>(), Arrays.asList(FaCatchTypeEnum.DEMINIMIS));
assertTrue(!catchEvolutionProgressDTO.getCatchEvolution().get("cumulated").getSpeciesList().isEmpty());
assertEquals(catchEvolutionProgressDTO.getCatchEvolution().get("cumulated").getSpeciesList().get(0).getSpeciesCode(), "COD");
assertTrue(catchEvolutionProgressDTO.getCatchEvolution().get("cumulated").getSpeciesList().get(0).getWeight() == 0);
}
use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO in project UVMS-ActivityModule-APP by UnionVMS.
the class CatchEvolutionProgressHandler method initCatchEvolutionProgressDTO.
protected CatchEvolutionProgressDTO initCatchEvolutionProgressDTO(FishingActivityEntity fishingActivity, FaReportDocumentType faReportDocumentType, Map<String, Double> speciesCumulatedWeight) {
CatchSummaryListDTO onboard = new CatchSummaryListDTO();
CatchSummaryListDTO cumulated = new CatchSummaryListDTO();
Map<String, CatchSummaryListDTO> catchEvolution = new TreeMap<>();
catchEvolution.put("onboard", onboard);
catchEvolution.put("cumulated", cumulated);
CatchEvolutionProgressDTO catchEvolutionProgressDTO = new CatchEvolutionProgressDTO();
catchEvolutionProgressDTO.setActivityType(fishingActivity.getTypeCode());
catchEvolutionProgressDTO.setCatchEvolution(catchEvolution);
catchEvolutionProgressDTO.setReportType(faReportDocumentType.name());
for (Map.Entry scw : speciesCumulatedWeight.entrySet()) {
SpeciesQuantityDTO speciesQuantityDTO = new SpeciesQuantityDTO();
speciesQuantityDTO.setSpeciesCode((String) scw.getKey());
Double weight = (Double) scw.getValue();
speciesQuantityDTO.setWeight(weight);
cumulated.getSpeciesList().add(speciesQuantityDTO);
cumulated.setTotal(cumulated.getTotal() + weight);
}
return catchEvolutionProgressDTO;
}
use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO in project UVMS-ActivityModule-APP by UnionVMS.
the class CatchEvolutionProgressHandler method handleCumulatedCatch.
protected void handleCumulatedCatch(FaCatchEntity faCatch, CatchSummaryListDTO cumulated, Map<String, Double> speciesCumulatedWeight, boolean delete) {
String speciesCode = faCatch.getSpeciesCode();
boolean exists = false;
cumulated.setTotal(delete ? cumulated.getTotal() - faCatch.getCalculatedWeightMeasure() : cumulated.getTotal() + faCatch.getCalculatedWeightMeasure());
for (SpeciesQuantityDTO speciesQuantityDTO : cumulated.getSpeciesList()) {
if (speciesQuantityDTO.getSpeciesCode().equalsIgnoreCase(speciesCode)) {
double weight = delete ? speciesQuantityDTO.getWeight() - faCatch.getCalculatedWeightMeasure() : speciesQuantityDTO.getWeight() + faCatch.getCalculatedWeightMeasure();
speciesQuantityDTO.setWeight(weight);
if (speciesCumulatedWeight.containsKey(speciesCode)) {
double existingCumulatedWeight = speciesCumulatedWeight.get(speciesCode);
double newCumulatedWeight = delete ? existingCumulatedWeight - faCatch.getCalculatedWeightMeasure() : existingCumulatedWeight + faCatch.getCalculatedWeightMeasure();
speciesCumulatedWeight.put(speciesCode, newCumulatedWeight);
} else {
speciesCumulatedWeight.put(speciesCode, new Double(weight));
}
exists = true;
break;
}
}
if (!exists) {
SpeciesQuantityDTO speciesQuantityDTO = new SpeciesQuantityDTO();
speciesQuantityDTO.setSpeciesCode(speciesCode);
double weight = speciesCumulatedWeight.containsKey(speciesCode) ? delete ? speciesCumulatedWeight.get(speciesCode) - faCatch.getCalculatedWeightMeasure() : speciesCumulatedWeight.get(speciesCode) + faCatch.getCalculatedWeightMeasure() : faCatch.getCalculatedWeightMeasure();
speciesCumulatedWeight.put(speciesCode, new Double(weight));
speciesQuantityDTO.setWeight(weight);
cumulated.getSpeciesList().add(speciesQuantityDTO);
}
}
use of eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO in project UVMS-ActivityModule-APP by UnionVMS.
the class CatchEvolutionProgressHandler method handleOnboardCatch.
protected void handleOnboardCatch(FaCatchEntity faCatch, CatchEvolutionProgressDTO catchEvolutionProgressDTO) {
CatchSummaryListDTO onboard = catchEvolutionProgressDTO.getCatchEvolution().get("onboard");
String speciesCode = faCatch.getSpeciesCode();
boolean exists = false;
onboard.setTotal(onboard.getTotal() + faCatch.getCalculatedWeightMeasure());
for (SpeciesQuantityDTO speciesQuantityDTO : onboard.getSpeciesList()) {
if (speciesQuantityDTO.getSpeciesCode().equalsIgnoreCase(speciesCode)) {
speciesQuantityDTO.setWeight(speciesQuantityDTO.getWeight() + faCatch.getCalculatedWeightMeasure());
exists = true;
break;
}
}
if (!exists) {
SpeciesQuantityDTO speciesQuantityDTO = new SpeciesQuantityDTO();
speciesQuantityDTO.setSpeciesCode(speciesCode);
speciesQuantityDTO.setWeight(faCatch.getCalculatedWeightMeasure());
onboard.getSpeciesList().add(speciesQuantityDTO);
}
}
Aggregations