Search in sources :

Example 1 with SpeciesQuantityDTO

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);
}
Also used : FaCatchEntity(eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity) CatchEvolutionProgressDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchEvolutionProgressDTO) FaReportDocumentEntity(eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity) SpeciesQuantityDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity) Test(org.junit.Test)

Example 2 with SpeciesQuantityDTO

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;
}
Also used : CatchEvolutionProgressDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchEvolutionProgressDTO) SpeciesQuantityDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO) CatchSummaryListDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchSummaryListDTO) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with SpeciesQuantityDTO

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);
    }
}
Also used : SpeciesQuantityDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO)

Example 4 with 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);
    }
}
Also used : SpeciesQuantityDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO) CatchSummaryListDTO(eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchSummaryListDTO)

Aggregations

SpeciesQuantityDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.SpeciesQuantityDTO)4 CatchEvolutionProgressDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchEvolutionProgressDTO)2 CatchSummaryListDTO (eu.europa.ec.fisheries.ers.service.dto.fishingtrip.CatchSummaryListDTO)2 FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)1 FaReportDocumentEntity (eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity)1 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1