Search in sources :

Example 16 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class SmartMeteringInstallationEndpoint method addDevice.

@PayloadRoot(localPart = "AddDeviceRequest", namespace = SMARTMETER_INSTALLATION_NAMESPACE)
@ResponsePayload
public AddDeviceAsyncResponse addDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddDeviceRequest request, @MessagePriority final String messagePriority, @ScheduleTime final String scheduleTime, @ResponseUrl final String responseUrl, @BypassRetry final String bypassRetry) throws OsgpException {
    log.info("Incoming AddDeviceRequest for meter: {}.", request.getDevice().getDeviceIdentification());
    AsyncResponse asyncResponse = null;
    try {
        final SmartMeteringDevice device = this.installationMapper.map(request.getDevice(), SmartMeteringDevice.class);
        final DeviceModel deviceModel = new DeviceModel(request.getDeviceModel().getManufacturer(), request.getDeviceModel().getModelCode(), "");
        final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(device, deviceModel);
        final RequestMessageMetadata requestMessageMetadata = RequestMessageMetadata.newBuilder().withOrganisationIdentification(organisationIdentification).withDeviceIdentification(device.getDeviceIdentification()).withDeviceFunction(null).withMessageType(MessageType.ADD_METER).withMessagePriority(messagePriority).withScheduleTime(scheduleTime).withBypassRetry(bypassRetry).build();
        asyncResponse = this.requestService.enqueueAndSendRequest(requestMessageMetadata, addSmartMeterRequest);
        this.saveResponseUrlIfNeeded(asyncResponse.getCorrelationUid(), responseUrl);
    } catch (final ConstraintViolationException e) {
        log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
        this.handleException(e);
    }
    return this.installationMapper.map(asyncResponse, AddDeviceAsyncResponse.class);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) AddSmartMeterRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) CoupleMbusDeviceByChannelAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceByChannelAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AsyncResponse) AddDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.AddDeviceAsyncResponse) DecoupleMbusDeviceByChannelAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceByChannelAsyncResponse) DecoupleMbusDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceAsyncResponse) CoupleMbusDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 17 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class SmartMeteringMonitoringEndpoint method getRetrievePushNotificationAlarmResponse.

@PayloadRoot(localPart = "RetrievePushNotificationAlarmRequest", namespace = SMARTMETER_MONITORING_NAMESPACE)
@ResponsePayload
public RetrievePushNotificationAlarmResponse getRetrievePushNotificationAlarmResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final RetrievePushNotificationAlarmRequest request) throws OsgpException {
    log.info("Incoming RetrievePushNotificationAlarmRequest for correlation UID: {}", request.getCorrelationUid());
    RetrievePushNotificationAlarmResponse response = null;
    try {
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), PushNotificationAlarm.class, ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "retrieving the push notification alarm");
        response = this.monitoringMapper.map(responseData.getMessageData(), RetrievePushNotificationAlarmResponse.class);
    } catch (final FunctionalException e) {
        throw e;
    } catch (final Exception e) {
        log.error("Exception: {} while sending RetrievePushNotificationAlarmRequest for correlation UID: {} for organisation {}.", e.getMessage(), request.getCorrelationUid(), organisationIdentification);
        this.handleException(e);
    }
    return response;
}
Also used : ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) RetrievePushNotificationAlarmResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.monitoring.RetrievePushNotificationAlarmResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 18 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class SmartMeteringManagementEndpoint method getEnableDebuggingResponse.

@PayloadRoot(localPart = "EnableDebuggingAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public EnableDebuggingResponse getEnableDebuggingResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final EnableDebuggingAsyncRequest request) throws OsgpException {
    log.info("EnableDebugging response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
    EnableDebuggingResponse response = null;
    try {
        response = new EnableDebuggingResponse();
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "Enable Debugging");
        response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue()));
        if (responseData.getMessageData() instanceof String) {
            response.setDescription((String) responseData.getMessageData());
        }
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_SMART_METERING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) EnableDebuggingResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.EnableDebuggingResponse) SetDeviceLifecycleStatusByChannelResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.SetDeviceLifecycleStatusByChannelResponseData) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) GetGsmDiagnosticResponseData(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetGsmDiagnosticResponseData) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 19 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceRequestMessageListener method sendException.

private void sendException(final ObjectMessage objectMessage, final Exception exception) {
    try {
        final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
        final FunctionalException osgpException = new FunctionalException(FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION, ComponentType.PROTOCOL_IEC61850, exception);
        final Serializable dataObject = objectMessage.getObject();
        final MessageMetadata messageMetadata = MessageMetadata.fromMessage(objectMessage);
        final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata.builder().withScheduled(false).build()).result(result).osgpException(osgpException).dataObject(dataObject).build();
        this.deviceResponseMessageSender.send(protocolResponseMessage);
    } catch (final Exception e) {
        LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e);
    }
}
Also used : Serializable(java.io.Serializable) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)

Example 20 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class ConfigurationService method setEncryptionKeyExchangeOnGMeter.

public void setEncryptionKeyExchangeOnGMeter(final MessageMetadata messageMetadata) throws FunctionalException {
    log.info("set Encryption Key Exchange On G-Meter for organisationIdentification: {} for deviceIdentification: " + "{}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
    final SmartMeter gasDevice = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
    final Device gatewayDevice = gasDevice.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.GATEWAY_DEVICE_NOT_SET_FOR_MBUS_DEVICE, ComponentType.DOMAIN_SMART_METERING, new GatewayDeviceNotSetForMbusDeviceException());
    }
    final GMeterInfoDto requestDto = new GMeterInfoDto(gasDevice.getChannel(), gasDevice.getDeviceIdentification());
    this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
}
Also used : GatewayDeviceNotSetForMbusDeviceException(org.opensmartgridplatform.domain.smartmetering.exceptions.GatewayDeviceNotSetForMbusDeviceException) Device(org.opensmartgridplatform.domain.core.entities.Device) GMeterInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

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