Search in sources :

Example 1 with DelimitedPeriodDTO

use of eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class BaseMapper method calculateFishingTime.

public static DelimitedPeriodDTO calculateFishingTime(Set<DelimitedPeriodEntity> periodEntities) {
    BigDecimal fishingTime = BigDecimal.ZERO;
    Date startDate = null;
    Date endDate = null;
    String unitCode = null;
    for (DelimitedPeriodEntity period : periodEntities) {
        Double calcDur = period.getCalculatedDuration();
        Date start = period.getStartDate();
        Date end = period.getEndDate();
        if (startDate == null || start.before(startDate)) {
            startDate = start;
        }
        if (endDate == null || end.after(endDate)) {
            endDate = end;
        }
        if (calcDur != null) {
            fishingTime = fishingTime.add(new BigDecimal(calcDur));
        }
        unitCode = unitCode == null ? periodEntities.size() > 1 ? UnitCodeEnum.MIN.getUnit() : period.getDurationMeasure().getUnitCode() : unitCode;
    }
    DelimitedPeriodDTO build = DelimitedPeriodDTO.builder().duration(fishingTime.doubleValue()).endDate(endDate).startDate(startDate).unitCode(unitCode).build();
    if (Math.abs(BigDecimal.ZERO.doubleValue() - build.getDuration()) < 0.00000001) {
        build.setDuration(null);
    }
    return build;
}
Also used : DelimitedPeriodEntity(eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity) BigDecimal(java.math.BigDecimal) Date(java.util.Date) DelimitedPeriodDTO(eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)

Example 2 with DelimitedPeriodDTO

use of eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityLandingViewMapper method populateActivityDetails.

@Override
protected ActivityDetailsDto populateActivityDetails(FishingActivityEntity faEntity, ActivityDetailsDto activityDetails) {
    DelimitedPeriodDTO delimitedPeriodDTO = mapToDelimitedPeriodDto(faEntity.getDelimitedPeriods());
    activityDetails.setLandingTime(delimitedPeriodDTO);
    return activityDetails;
}
Also used : DelimitedPeriodDTO(eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)

Example 3 with DelimitedPeriodDTO

use of eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityTranshipmentViewMapper method populateActivityDetails.

protected ActivityDetailsDto populateActivityDetails(FishingActivityEntity faEntity, ActivityDetailsDto activityDetails) {
    Map<String, String> idMap = new HashMap<>();
    for (FishingActivityIdentifierEntity idEntity : faEntity.getFishingActivityIdentifiers()) {
        idMap.put(idEntity.getFaIdentifierId(), idEntity.getFaIdentifierSchemeId());
    }
    Set<IdentifierDto> identifierDtos = FishingActivityIdentifierMapper.INSTANCE.mapToIdentifierDTOSet(faEntity.getFishingActivityIdentifiers());
    activityDetails.setIdentifiers(identifierDtos);
    Set<DelimitedPeriodEntity> delimitedPeriodEntitySet = faEntity.getDelimitedPeriods();
    if (!Collections.isEmpty(delimitedPeriodEntitySet)) {
        DelimitedPeriodEntity delimitedPeriod = delimitedPeriodEntitySet.iterator().next();
        DelimitedPeriodDTO delimitedPeriodDTO = DelimitedPeriodMapper.INSTANCE.mapToDelimitedPeriodDTO(delimitedPeriod);
        activityDetails.setTranshipmentTime(delimitedPeriodDTO);
        // Override occurrence date from delimited period
        activityDetails.setOccurrence(delimitedPeriod.getStartDate());
    }
    return activityDetails;
}
Also used : DelimitedPeriodEntity(eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity) IdentifierDto(eu.europa.ec.fisheries.ers.service.dto.view.IdentifierDto) HashMap(java.util.HashMap) FishingActivityIdentifierEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityIdentifierEntity) DelimitedPeriodDTO(eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)

Example 4 with DelimitedPeriodDTO

use of eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityLandingViewMapper method mapToDelimitedPeriodDto.

private DelimitedPeriodDTO mapToDelimitedPeriodDto(Set<DelimitedPeriodEntity> delimitedPeriods) {
    Date startDate = null;
    Date endDate = null;
    Double duration = null;
    String unitCode = null;
    if (CollectionUtils.isNotEmpty(delimitedPeriods)) {
        DelimitedPeriodEntity delimPeriod = delimitedPeriods.iterator().next();
        startDate = delimPeriod.getStartDate();
        endDate = delimPeriod.getEndDate();
        duration = delimPeriod.getDurationMeasure().getValue();
        unitCode = delimPeriod.getDurationMeasure().getUnitCode();
    }
    return new DelimitedPeriodDTO(startDate, endDate, duration, unitCode);
}
Also used : DelimitedPeriodEntity(eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity) Date(java.util.Date) DelimitedPeriodDTO(eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)

Example 5 with DelimitedPeriodDTO

use of eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO in project UVMS-ActivityModule-APP by UnionVMS.

the class BaseMapperTest method testCalculateFishingActivity.

@Test
@SneakyThrows
public void testCalculateFishingActivity() {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    DelimitedPeriodEntity period1 = new DelimitedPeriodEntity();
    period1.setStartDate(sdf.parse("21/12/2011"));
    period1.setEndDate(sdf.parse("21/12/2013"));
    period1.setCalculatedDuration(22.22d);
    period1.getDurationMeasure().setUnitCode("MIN");
    DelimitedPeriodEntity period2 = new DelimitedPeriodEntity();
    period2.setStartDate(sdf.parse("21/11/2010"));
    period2.setEndDate(sdf.parse("21/11/2012"));
    period2.setCalculatedDuration(2.24d);
    period2.getDurationMeasure().setUnitCode("HOU");
    DelimitedPeriodDTO periodDTO = BaseMapper.calculateFishingTime(newSet(period1, period2));
    assertEquals(24.46d, periodDTO.getDuration());
    assertEquals(period2.getStartDate(), periodDTO.getStartDate());
    assertEquals(period1.getEndDate(), periodDTO.getEndDate());
    assertEquals(UnitCodeEnum.MIN.getUnit(), periodDTO.getUnitCode());
}
Also used : DelimitedPeriodEntity(eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity) SimpleDateFormat(java.text.SimpleDateFormat) DelimitedPeriodDTO(eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO) BaseUnitilsTest(eu.europa.ec.fisheries.uvms.BaseUnitilsTest) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

DelimitedPeriodDTO (eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)5 DelimitedPeriodEntity (eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity)4 Date (java.util.Date)2 FishingActivityIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityIdentifierEntity)1 IdentifierDto (eu.europa.ec.fisheries.ers.service.dto.view.IdentifierDto)1 BaseUnitilsTest (eu.europa.ec.fisheries.uvms.BaseUnitilsTest)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 SneakyThrows (lombok.SneakyThrows)1 Test (org.junit.Test)1