Search in sources :

Example 6 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class SmartMeteringManagementEndpoint method clearMBusStatusOnAllChannelsResponse.

@PayloadRoot(localPart = "ClearMBusStatusOnAllChannelsAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public ClearMBusStatusOnAllChannelsResponse clearMBusStatusOnAllChannelsResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ClearMBusStatusOnAllChannelsAsyncRequest request) throws OsgpException {
    log.info("Clear M-Bus Status On All Channels response for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
    ClearMBusStatusOnAllChannelsResponse response = null;
    try {
        response = new ClearMBusStatusOnAllChannelsResponse();
        final ResponseData responseData = this.responseDataService.get(request.getCorrelationUid(), ComponentType.WS_SMART_METERING);
        this.throwExceptionIfResultNotOk(responseData, "Clear M-Bus Status On All Channels");
        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) 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) ClearMBusStatusOnAllChannelsResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.ClearMBusStatusOnAllChannelsResponse) 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 7 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException 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 8 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException 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 9 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class TariffSwitchingAdHocManagementEndpoint method getDevices.

@PayloadRoot(localPart = "GetDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDevicesResponse getDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDevicesRequest request) throws OsgpException {
    LOGGER.info("Get Devices Request received from organisation: {}.", organisationIdentification);
    final GetDevicesResponse response = new GetDevicesResponse();
    try {
        final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, request.getPage());
        final DevicePage devicePage = new DevicePage();
        devicePage.setTotalPages(page.getTotalPages());
        devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(page.getContent(), org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.Device.class));
        response.setDevicePage(devicePage);
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_TARIFF_SWITCHING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Device(org.opensmartgridplatform.domain.core.entities.Device) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.DevicePage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) GetDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.tariffswitching.adhocmanagement.GetDevicesResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 10 with ValidationException

use of org.opensmartgridplatform.domain.core.exceptions.ValidationException in project open-smart-grid-platform by OSGP.

the class DeviceManagementEndpoint method getProtocolInfos.

@PayloadRoot(localPart = "GetProtocolInfosRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public GetProtocolInfosResponse getProtocolInfos(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetProtocolInfosRequest request) throws OsgpException {
    LOGGER.info("Get protocol infos for organisation: {}.", organisationIdentification);
    final GetProtocolInfosResponse getProtocolInfosResponse = new GetProtocolInfosResponse();
    try {
        final List<org.opensmartgridplatform.domain.core.entities.ProtocolInfo> protocolInfos = this.deviceManagementService.getProtocolInfos(organisationIdentification);
        getProtocolInfosResponse.getProtocolInfos().addAll(this.deviceManagementMapper.mapAsList(protocolInfos, org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.ProtocolInfo.class));
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return getProtocolInfosResponse;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) GetProtocolInfosResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.GetProtocolInfosResponse) ProtocolInfo(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.ProtocolInfo) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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)

Aggregations

ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)47 ConstraintViolationException (javax.validation.ConstraintViolationException)44 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)44 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)44 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)44 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)21 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9 TransactionSystemException (org.springframework.transaction.TransactionSystemException)8 Device (org.opensmartgridplatform.domain.core.entities.Device)7 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)6 GetGsmDiagnosticResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.GetGsmDiagnosticResponseData)6 SetDeviceLifecycleStatusByChannelResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.management.SetDeviceLifecycleStatusByChannelResponseData)6 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)6 DateTime (org.joda.time.DateTime)4 SetDeviceLifecycleStatusAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceLifecycleStatusAsyncResponse)4 SetDeviceVerificationKeyAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetDeviceVerificationKeyAsyncResponse)4 SetEventNotificationsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.SetEventNotificationsAsyncResponse)4 UpdateDeviceCdmaSettingsAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceCdmaSettingsAsyncResponse)4 UpdateDeviceSslCertificationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.UpdateDeviceSslCertificationAsyncResponse)4