Search in sources :

Example 1 with DelimitedPeriodEntity

use of eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityMapper method getDelimitedPeriodEntities.

protected Set<DelimitedPeriodEntity> getDelimitedPeriodEntities(List<DelimitedPeriod> delimitedPeriods, FishingActivityEntity fishingActivityEntity) {
    if (delimitedPeriods == null || delimitedPeriods.isEmpty()) {
        return Collections.emptySet();
    }
    Set<DelimitedPeriodEntity> delimitedPeriodEntities = new HashSet<>();
    for (DelimitedPeriod delimitedPeriod : delimitedPeriods) {
        DelimitedPeriodEntity delimitedPeriodEntity = DelimitedPeriodMapper.INSTANCE.mapToDelimitedPeriodEntity(delimitedPeriod);
        delimitedPeriodEntity.setFishingActivity(fishingActivityEntity);
        delimitedPeriodEntities.add(delimitedPeriodEntity);
    }
    return delimitedPeriodEntities;
}
Also used : DelimitedPeriodEntity(eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity) DelimitedPeriod(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.DelimitedPeriod) HashSet(java.util.HashSet)

Example 2 with DelimitedPeriodEntity

use of eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity 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 3 with DelimitedPeriodEntity

use of eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity 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 DelimitedPeriodEntity

use of eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity 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 DelimitedPeriodEntity

use of eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity 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

DelimitedPeriodEntity (eu.europa.ec.fisheries.ers.fa.entities.DelimitedPeriodEntity)8 DelimitedPeriodDTO (eu.europa.ec.fisheries.ers.service.dto.DelimitedPeriodDTO)4 Test (org.junit.Test)4 DelimitedPeriod (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.DelimitedPeriod)3 FishingActivityIdentifierEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityIdentifierEntity)2 Date (java.util.Date)2 FaCatchEntity (eu.europa.ec.fisheries.ers.fa.entities.FaCatchEntity)1 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 FishingGearEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingGearEntity)1 FishingTripEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingTripEntity)1 FluxCharacteristicEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxCharacteristicEntity)1 FluxLocationEntity (eu.europa.ec.fisheries.ers.fa.entities.FluxLocationEntity)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 HashSet (java.util.HashSet)1 SneakyThrows (lombok.SneakyThrows)1 FishingActivity (un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._20.FishingActivity)1