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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations