use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method setLight.
// === SET LIGHT ===
public void setLight(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final List<LightValue> lightValues, final String messageType, final int messagePriority) throws FunctionalException {
LOGGER.debug("setLight called for device {} with organisation {}", deviceIdentification, organisationIdentification);
this.findOrganisation(organisationIdentification);
final Device device = this.findActiveDevice(deviceIdentification);
final List<org.opensmartgridplatform.dto.valueobjects.LightValueDto> lightValuesDto = this.domainCoreMapper.mapAsList(lightValues, org.opensmartgridplatform.dto.valueobjects.LightValueDto.class);
final LightValueMessageDataContainerDto lightValueMessageDataContainer = new LightValueMessageDataContainerDto(lightValuesDto);
this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, lightValueMessageDataContainer), messageType, messagePriority, device.getIpAddress());
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleGetStatusResponse.
public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("handleResponse for MessageType: {}", messageType);
final GetStatusResponse response = new GetStatusResponse();
response.setOsgpException(exception);
response.setResult(deviceResult);
if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
LOGGER.error("Device Response not ok.", exception);
} else {
final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
try {
final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
this.handleLmd(status, response);
} else {
this.handleSsld(ids.getDeviceIdentification(), status, DomainType.PUBLIC_LIGHTING, response);
}
} catch (final FunctionalException e) {
LOGGER.error("Caught FunctionalException", e);
}
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method updateLmdLastCommunicationTime.
private LightMeasurementDevice updateLmdLastCommunicationTime(final LightMeasurementDevice lmd) {
final Instant now = Instant.now();
LOGGER.info("Trying to update lastCommunicationTime for light measurement device: {} at DateTime: {}", lmd.getDeviceIdentification(), Date.from(now));
lmd.setLastCommunicationTime(now);
final Device gateway = lmd.getGatewayDevice();
if (gateway != null) {
this.rtuDeviceRepository.findById(gateway.getId()).ifPresent(rtu -> this.updateGatewayLastCommunicationTime(rtu, now));
}
return this.lightMeasurementDeviceRepository.save(lmd);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method setLightSchedule.
// === SET LIGHT SCHEDULE ===
/**
* Set a light schedule.
*/
public void setLightSchedule(final CorrelationIds ids, final Schedule schedule, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
LOGGER.info("setSchedule called with organisation {} and device {}.", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
this.findOrganisation(ids.getOrganisationIdentification());
final Device device = this.findActiveDevice(ids.getDeviceIdentification());
final ScheduleDto scheduleDto = this.domainCoreMapper.map(schedule, ScheduleDto.class);
this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, scheduleDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class ScheduleManagementService method setHasSchedule.
// === SET HAS SCHEDULE ===
/**
* Method for setting the 'hasSchedule' boolean for a device.
*
* @throws FunctionalException
*/
public void setHasSchedule(final String deviceIdentification, final Boolean hasSchedule) throws FunctionalException {
LOGGER.info("setHasSchedule called for device {} with hasSchedule: {}.", deviceIdentification, hasSchedule);
final Device device = this.findActiveDevice(deviceIdentification);
final Ssld ssld = this.findSsldForDevice(device);
ssld.setHasSchedule(hasSchedule);
this.ssldRepository.save(ssld);
}
Aggregations