use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest 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.valueobjects.smartmetering.AddSmartMeterRequest in project open-smart-grid-platform by OSGP.
the class SmartMeterServiceTest method testStoreMeter.
@Test
void testStoreMeter() throws FunctionalException {
final String organisationIdentification = "org-1";
final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
final DeviceModel deviceModel = new DeviceModel();
final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(smartMeteringDevice, deviceModel);
final SmartMeter smartMeter = new SmartMeter();
final Manufacturer manufacturer = new Manufacturer();
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(any(), any())).thenReturn(protocolInfo);
when(this.manufacturerRepository.findByCode(any())).thenReturn(manufacturer);
when(this.deviceModelRepository.findByManufacturerAndModelCode(any(), any())).thenReturn(new org.opensmartgridplatform.domain.core.entities.DeviceModel());
when(this.smartMeterRepository.save(any())).thenReturn(smartMeter);
this.smartMeterService.storeMeter(organisationIdentification, addSmartMeterRequest, smartMeter);
verify(this.protocolInfoRepository).findByProtocolAndProtocolVersion(any(), any());
verify(this.manufacturerRepository).findByCode(any());
verify(this.deviceModelRepository).findByManufacturerAndModelCode(any(), any());
verify(this.deviceAuthorizationRepository).save(any());
verify(this.organisationRepository).findByOrganisationIdentification(organisationIdentification);
verify(this.smartMeterRepository).save(any());
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest in project open-smart-grid-platform by OSGP.
the class AddMeterRequestMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final Object dataObject) throws FunctionalException {
final AddSmartMeterRequest addSmartMeterRequest = (AddSmartMeterRequest) dataObject;
this.installationService.addMeter(deviceMessageMetadata, addSmartMeterRequest);
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest in project open-smart-grid-platform by OSGP.
the class SmartMeterServiceTest method testStoreMeterWithUnknownProtocolInfo.
@Test
void testStoreMeterWithUnknownProtocolInfo() {
final String organisationIdentification = "org-1";
final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
final DeviceModel deviceModel = new DeviceModel();
final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(smartMeteringDevice, deviceModel);
final SmartMeter smartMeter = new SmartMeter();
when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(any(), any())).thenReturn(null);
FunctionalException exception = Assertions.assertThrows(FunctionalException.class, () -> {
this.smartMeterService.storeMeter(organisationIdentification, addSmartMeterRequest, smartMeter);
});
assertThat(exception.getExceptionType()).isEqualTo(FunctionalExceptionType.UNKNOWN_PROTOCOL_NAME_OR_VERSION);
}
Aggregations