use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class ConfigurationService method getKeys.
public void getKeys(final MessageMetadata messageMetadata, final GetKeysRequestData getKeysRequestData) throws FunctionalException {
log.info("getKeys for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final List<SecretTypeDto> secretTypes = getKeysRequestData.getSecretTypes().stream().map(secretType -> SecretTypeDto.valueOf(secretType.name())).collect(Collectors.toList());
final GetKeysRequestDto requestDto = new GetKeysRequestDto(secretTypes);
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class ConfigurationService method getMbusEncryptionKeyStatus.
public void getMbusEncryptionKeyStatus(final MessageMetadata messageMetadata) throws FunctionalException {
log.info("getMbusEncryptionKeyStatus for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter mbusDevice = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final Device gatewayDevice = mbusDevice.getGatewayDevice();
if (gatewayDevice == null) {
throw new FunctionalException(FunctionalExceptionType.GATEWAY_DEVICE_NOT_SET_FOR_MBUS_DEVICE, ComponentType.DOMAIN_SMART_METERING, new GatewayDeviceNotSetForMbusDeviceException());
}
final GetMbusEncryptionKeyStatusRequestDto requestDto = new GetMbusEncryptionKeyStatusRequestDto(mbusDevice.getDeviceIdentification(), mbusDevice.getChannel());
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class ConfigurationService method requestFirmwareVersion.
/**
* Delegates the requests of the retrieval of the firmware version(s) from the protocol adapter
* layer to the core layer
*
* @param messageMetadata contains the message meta data
* @param getFirmwareVersionQuery
* @throws FunctionalException is thrown when the device cannot be found in the database or when
* the device is a G meter and the channel and/or gateway is not configured
*/
public void requestFirmwareVersion(final MessageMetadata messageMetadata, final GetFirmwareVersionQuery getFirmwareVersionQuery) throws FunctionalException {
log.info("requestFirmwareVersion for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
if (getFirmwareVersionQuery.isMbusDevice()) {
if (smartMeter.getChannel() == null) {
/*
* For now, throw a FunctionalException. As soon as we can
* communicate with some types of gas meters directly, and not
* through an M-Bus port of an energy meter, this will have to
* be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Retrieving firmware version for gas meter. No channel configured."));
}
final Device gatewayDevice = smartMeter.getGatewayDevice();
if (gatewayDevice == null) {
/*
* For now throw a FunctionalException, based on the same
* reasoning as with the channel a couple of lines up. As soon
* as we have scenario's with direct communication with gas
* meters this will have to be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Retrieving firmware version for gas meter. No gateway device found."));
}
final GetFirmwareVersionQueryDto requestDto = new GetFirmwareVersionQueryDto(ChannelDto.fromNumber(smartMeter.getChannel()), messageMetadata.getDeviceIdentification());
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
} else {
final GetFirmwareVersionQueryDto requestDto = new GetFirmwareVersionQueryDto();
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class MonitoringService method requestPeriodicMeterReads.
public void requestPeriodicMeterReads(final MessageMetadata messageMetadata, final PeriodicMeterReadsQuery periodicMeterReadsValueQuery) throws FunctionalException {
LOGGER.info("requestPeriodicMeterReads for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
if (periodicMeterReadsValueQuery.isMbusDevice()) {
if (smartMeter.getChannel() == null) {
/*
* For now, throw a FunctionalException. As soon as we can
* communicate with some types of gas meters directly, and not
* through an M-Bus port of an energy meter, this will have to
* be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have a channel configured."));
}
final PeriodicMeterReadsRequestDto requestDto = new PeriodicMeterReadsRequestDto(PeriodTypeDto.valueOf(periodicMeterReadsValueQuery.getPeriodType().name()), periodicMeterReadsValueQuery.getBeginDate(), periodicMeterReadsValueQuery.getEndDate(), ChannelDto.fromNumber(smartMeter.getChannel()));
final Device gatewayDevice = smartMeter.getGatewayDevice();
if (gatewayDevice == null) {
/*
* For now throw a FunctionalException, based on the same
* reasoning as with the channel a couple of lines up. As soon
* as we have scenario's with direct communication with gas
* meters this will have to be changed.
*/
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have an energy meter as gateway device."));
}
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
} else {
final PeriodicMeterReadsRequestDto requestDto = this.monitoringMapper.map(periodicMeterReadsValueQuery, PeriodicMeterReadsRequestDto.class);
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class GetFirmwareVersionResponseMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) throws FunctionalException {
if (responseMessage.getDataObject() instanceof ArrayList) {
@SuppressWarnings("unchecked") final List<FirmwareVersionDto> firmwareVersionList = (List<FirmwareVersionDto>) responseMessage.getDataObject();
this.configurationService.handleGetFirmwareVersionResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, firmwareVersionList);
} else if (responseMessage.getDataObject() instanceof FirmwareVersionGasDto) {
this.configurationService.handleGetFirmwareVersionGasResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, (FirmwareVersionGasDto) responseMessage.getDataObject());
} else {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new OsgpException(ComponentType.DOMAIN_SMART_METERING, "DataObject for response message should be of type ArrayList"));
}
}
Aggregations