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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations