Search in sources :

Example 96 with FunctionalException

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());
}
Also used : Arrays(java.util.Arrays) AdministrativeStatusType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AdministrativeStatusType) SpecialDaysRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequest) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) GetKeysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetKeysRequestData) SetRandomisationSettingsRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetRandomisationSettingsRequestData) GetConfigurationObjectResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetConfigurationObjectResponse) ChannelDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelDto) AlarmNotifications(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AlarmNotifications) SetKeysRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetKeysRequestData) UpdateFirmwareResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.UpdateFirmwareResponse) GetKeysResponseData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetKeysResponseData) DefinableLoadProfileConfigurationDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DefinableLoadProfileConfigurationDto) GetMbusEncryptionKeyStatusRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusRequestDto) SetConfigurationObjectRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetConfigurationObjectRequestDto) GetMbusEncryptionKeyStatusByChannelRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetMbusEncryptionKeyStatusByChannelRequestData) AdministrativeStatusTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AdministrativeStatusTypeDto) PushSetupAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupAlarmDto) GetKeysResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetKeysResponse) PushSetupSmsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushSetupSmsDto) FirmwareVersionGasResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FirmwareVersionGasResponse) UpdateFirmwareRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.UpdateFirmwareRequestData) FirmwareVersionGasDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionGasDto) Collectors(java.util.stream.Collectors) ActivityCalendar(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActivityCalendar) GetMbusEncryptionKeyStatusByChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusByChannelRequestDataDto) PushSetupAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigurationMapper(org.opensmartgridplatform.adapter.domain.smartmetering.application.mapping.ConfigurationMapper) GetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysRequestDto) SetRandomisationSettingsRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetRandomisationSettingsRequestDataDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) AlarmNotificationsDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.AlarmNotificationsDto) JmsMessageSender(org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.JmsMessageSender) GetMbusEncryptionKeyStatusResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusResponseDto) GMeterInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto) GetMbusEncryptionKeyStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusByChannelResponseDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SecretType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SecretType) FunctionalExceptionType(org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType) GetFirmwareVersionQueryDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetFirmwareVersionQueryDto) WebServiceResponseMessageSender(org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.WebServiceResponseMessageSender) SetConfigurationObjectRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetConfigurationObjectRequest) DefinableLoadProfileConfigurationData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.DefinableLoadProfileConfigurationData) Service(org.springframework.stereotype.Service) GetFirmwareVersionQuery(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetFirmwareVersionQuery) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GetConfigurationObjectRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetConfigurationObjectRequestDto) KeyDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.KeyDto) UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) EncryptionKeyStatusType(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EncryptionKeyStatusType) SetClockConfigurationRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetClockConfigurationRequestDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) GetConfigurationObjectRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.GetConfigurationObjectRequest) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) GatewayDeviceNotSetForMbusDeviceException(org.opensmartgridplatform.domain.smartmetering.exceptions.GatewayDeviceNotSetForMbusDeviceException) SpecialDaysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDto) SecretTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SecretTypeDto) SetClockConfigurationRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetClockConfigurationRequestData) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) GetConfigurationObjectResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetConfigurationObjectResponseDto) Device(org.opensmartgridplatform.domain.core.entities.Device) FirmwareVersionResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FirmwareVersionResponse) GetKeysResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysResponseDto) SetMbusUserKeyByChannelRequestData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetMbusUserKeyByChannelRequestData) PushSetupSms(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms) SetMbusUserKeyByChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetMbusUserKeyByChannelRequestDataDto) ActivityCalendarDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActivityCalendarDto) Transactional(org.springframework.transaction.annotation.Transactional) GetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysRequestDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) SecretTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SecretTypeDto)

Example 97 with FunctionalException

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());
}
Also used : GetMbusEncryptionKeyStatusRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMbusEncryptionKeyStatusRequestDto) GatewayDeviceNotSetForMbusDeviceException(org.opensmartgridplatform.domain.smartmetering.exceptions.GatewayDeviceNotSetForMbusDeviceException) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 98 with FunctionalException

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());
    }
}
Also used : GetFirmwareVersionQueryDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetFirmwareVersionQueryDto) Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 99 with FunctionalException

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());
    }
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) PeriodicMeterReadsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PeriodicMeterReadsRequestDto)

Example 100 with FunctionalException

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"));
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersionGasDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionGasDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)

Aggregations

FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)155 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)63 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)54 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)54 ConstraintViolationException (javax.validation.ConstraintViolationException)51 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 Device (org.opensmartgridplatform.domain.core.entities.Device)32 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)31 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)22 Transactional (org.springframework.transaction.annotation.Transactional)19 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)15 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)12 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)11 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)10 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)9 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9