private void updateInterruptCapability( InterruptCapability interruptCapability, InterruptCapabilityDto interruptCapabilityDto) { interruptCapability.setMaxDtus(interruptCapabilityDto.getMaxDtus()); interruptCapability.setType( UdiEventTransformer.transformToModel(interruptCapabilityDto.getType())); LOGGER.debug("Updated interrupt-capability with id [{}] ", interruptCapabilityDto.getId()); }
private void createUdiEventFromDto(UdiEventDto udiEventDto, LocalDate period) { Udi udi = udiRepository.findByEndpoint(udiEventDto.getUdiEndpoint(), period); UdiEvent udiEvent = UdiEventTransformer.transformToModel(udiEventDto, udi); udiEventRepository.persist(udiEvent); LOGGER.debug("Created new udi event with id [{}]", udiEvent.getId()); udiEventDto .getDeviceCapabilities() .forEach(deviceCapabilityDto -> createDeviceCapability(deviceCapabilityDto, udiEvent)); }
private void updateUdiEventFromDto(UdiEvent originalUdiEvent, UdiEventDto udiEventDto) { // should not change but you never know, let's allow it for now originalUdiEvent.setPeriod(udiEventDto.getPeriod()); originalUdiEvent.setUdiEventType( UdiEventTransformer.transformToModel(udiEventDto.getUdiEventType())); // may change originalUdiEvent.setStartDtu(udiEventDto.getStartDtu()); originalUdiEvent.setEndDtu(udiEventDto.getEndDtu()); originalUdiEvent.setStartAfterDtu(udiEventDto.getStartAfterDtu()); originalUdiEvent.setFinishBeforeDtu(udiEventDto.getFinishBeforeDtu()); originalUdiEvent.setDeviceSelector(udiEventDto.getDeviceSelector()); Map<String, DeviceCapability> dbCapabilitiesPerId = originalUdiEvent .getDeviceCapabilities() .stream() .collect(Collectors.toMap(DeviceCapability::getId, Function.identity())); LOGGER.debug("Updated udi event with id [{}]", originalUdiEvent.getId()); // update of create udiEventDto .getDeviceCapabilities() .stream() .forEach( deviceCapabilityDto -> { if (!dbCapabilitiesPerId.containsKey(deviceCapabilityDto.getId())) { createDeviceCapability(deviceCapabilityDto, originalUdiEvent); } else { updateDeviceCapability( dbCapabilitiesPerId.get(deviceCapabilityDto.getId()), deviceCapabilityDto); } }); // remove capabilities that are not given back in the updated id list Set<String> updatedCapabilitiesId = udiEventDto .getDeviceCapabilities() .stream() .map(DeviceCapabilityDto::getId) .collect(Collectors.toSet()); dbCapabilitiesPerId .values() .stream() .filter(deviceCapability -> !updatedCapabilitiesId.contains(deviceCapability.getId())) .forEach( deviceCapability -> { LOGGER.debug( "Deleted device capability with id [{}] for udi event with id [{}]", deviceCapability.getId(), deviceCapability.getUdiEvent().getId()); originalUdiEvent.getDeviceCapabilities().remove(deviceCapability); }); }
private InterruptCapability createInterruptCapability( InterruptCapabilityDto interruptCapabilityDto, UdiEvent udiEvent) { InterruptCapability interruptCapability = new InterruptCapability(); interruptCapability.setId(getDeviceCapabilityId(interruptCapabilityDto)); interruptCapability.setMaxDtus(interruptCapabilityDto.getMaxDtus()); interruptCapability.setType( UdiEventTransformer.transformToModel(interruptCapabilityDto.getType())); interruptCapability.setUdiEvent(udiEvent); interruptCapabilityRepository.persist(interruptCapability); LOGGER.debug( "Created new interrupt-capability with id [{}] for event with id [{}]", interruptCapabilityDto.getId(), udiEvent.getId()); return interruptCapability; }
private ReduceCapability createReduceCapability( ReduceCapabilityDto reduceCapabilityDto, UdiEvent udiEvent) { ReduceCapability reduceCapability = new ReduceCapability(); reduceCapability.setId(getDeviceCapabilityId(reduceCapabilityDto)); reduceCapability.setMaxDtus(reduceCapabilityDto.getMaxDtus()); reduceCapability.setPowerStep(reduceCapabilityDto.getPowerStep()); reduceCapability.setMinPower(reduceCapabilityDto.getMinPower()); reduceCapability.setDurationMultiplier(reduceCapabilityDto.getDurationMultiplier()); reduceCapability.setConsumptionProductionType( UdiEventTransformer.transformToModel(reduceCapabilityDto.getConsumptionProductionType())); reduceCapability.setUdiEvent(udiEvent); reduceCapabilityRepository.persist(reduceCapability); LOGGER.debug( "Created new reduce-capability with id [{}] for event with id [{}]", reduceCapabilityDto.getId(), udiEvent.getId()); return reduceCapability; }
private IncreaseCapability createIncreaseCapability( IncreaseCapabilityDto increaseCapabilityDto, UdiEvent udiEvent) { IncreaseCapability increaseCapability = new IncreaseCapability(); increaseCapability.setId(getDeviceCapabilityId(increaseCapabilityDto)); increaseCapability.setMaxDtus(increaseCapabilityDto.getMaxDtus()); increaseCapability.setPowerStep(increaseCapabilityDto.getPowerStep()); increaseCapability.setMaxPower(increaseCapabilityDto.getMaxPower()); increaseCapability.setDurationMultiplier(increaseCapabilityDto.getDurationMultiplier()); increaseCapability.setConsumptionProductionType( UdiEventTransformer.transformToModel(increaseCapabilityDto.getConsumptionProductionType())); increaseCapability.setUdiEvent(udiEvent); increaseCapabilityRepository.persist(increaseCapability); LOGGER.debug( "Created new increase-capability with id [{}] for event with id [{}]", increaseCapabilityDto.getId(), udiEvent.getId()); return increaseCapability; }