use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.
the class InstallationMapperTest method mapsSmartMeteringDeviceToSmartMeter.
@Test
public void mapsSmartMeteringDeviceToSmartMeter() {
final SmartMeteringDevice source = new SmartMeteringDevice();
source.setDeviceIdentification("device1");
source.setDeviceType("typeA");
source.setCommunicationMethod("skype");
source.setCommunicationProvider("theInternet");
source.setIccId("value");
source.setProtocolName("protocolName");
source.setProtocolVersion("latestVersion");
source.setMasterKey("masterKey".getBytes());
source.setGlobalEncryptionUnicastKey("globalEncryptionUnicastKey".getBytes());
source.setAuthenticationKey("authenticationKey".getBytes());
source.setSupplier("supplier");
source.setHls3Active(true);
source.setHls4Active(true);
source.setHls3Active(true);
source.setDeliveryDate(new Date());
source.setMbusIdentificationNumber("12345678");
source.setMbusManufacturerIdentification("XYZ");
source.setMbusVersion((short) 66);
source.setMbusDeviceTypeIdentification((short) 3);
source.setMbusDefaultKey("mbusDefaultKey".getBytes());
final SmartMeter result = this.mapperFactory.getMapperFacade().map(source, SmartMeter.class);
final SmartMeter expected = this.toSmartMeter(source);
assertThat(result).isEqualToIgnoringGivenFields(expected, "id", "creationTime", "modificationTime", "version");
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice 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.SmartMeteringDevice 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.SmartMeteringDevice in project open-smart-grid-platform by OSGP.
the class InstallationMapperTest method testSmartMeteringDeviceToSmartMeteringDeviceDtoMapping.
@Test
public void testSmartMeteringDeviceToSmartMeteringDeviceDtoMapping() {
final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
smartMeteringDevice.setDeviceIdentification("device1");
smartMeteringDevice.setDeviceType("typeA");
smartMeteringDevice.setCommunicationMethod("skype");
smartMeteringDevice.setCommunicationProvider("theInternet");
smartMeteringDevice.setIccId("value");
smartMeteringDevice.setProtocolName("protocolName");
smartMeteringDevice.setProtocolVersion("latestVersion");
smartMeteringDevice.setMasterKey("masterKey".getBytes());
smartMeteringDevice.setGlobalEncryptionUnicastKey("globalEncryptionUnicastKey".getBytes());
smartMeteringDevice.setAuthenticationKey("authenticationKey".getBytes());
smartMeteringDevice.setSupplier("supplier");
smartMeteringDevice.setHls3Active(true);
smartMeteringDevice.setHls4Active(true);
smartMeteringDevice.setHls5Active(true);
smartMeteringDevice.setDeliveryDate(new Date());
smartMeteringDevice.setMbusIdentificationNumber("12345678");
smartMeteringDevice.setMbusManufacturerIdentification("XYZ");
smartMeteringDevice.setMbusVersion((short) 112);
smartMeteringDevice.setMbusDeviceTypeIdentification((short) 3);
smartMeteringDevice.setMbusDefaultKey("mbusDefaultKey".getBytes());
final SmartMeteringDeviceDto smartMeteringDeviceDto = this.mapperFactory.getMapperFacade().map(smartMeteringDevice, SmartMeteringDeviceDto.class);
assertThat(smartMeteringDevice).isNotNull();
assertThat(smartMeteringDeviceDto).isNotNull();
assertThat(smartMeteringDeviceDto).isEqualToIgnoringGivenFields(smartMeteringDevice, "hls3Active", "hls4Active", "hls5Active");
assertThat(smartMeteringDeviceDto.isHls3Active()).isEqualTo(smartMeteringDevice.isHls3Active());
assertThat(smartMeteringDeviceDto.isHls4Active()).isEqualTo(smartMeteringDevice.isHls4Active());
assertThat(smartMeteringDeviceDto.isHls5Active()).isEqualTo(smartMeteringDevice.isHls5Active());
assertThat(smartMeteringDeviceDto).isNotNull().isEqualToIgnoringGivenFields(smartMeteringDevice, "ipAddress", "btsId", "cellId");
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.
the class InstallationService method addMeter.
public void addMeter(final MessageMetadata messageMetadata, final AddSmartMeterRequest addSmartMeterRequest) throws FunctionalException {
final String organisationId = messageMetadata.getOrganisationIdentification();
final String deviceId = messageMetadata.getDeviceIdentification();
LOGGER.debug("addMeter for organisationIdentification: {} for deviceIdentification: {}", organisationId, deviceId);
final SmartMeteringDevice smartMeteringDevice = addSmartMeterRequest.getDevice();
final String deviceIdentification = messageMetadata.getDeviceIdentification();
this.smartMeterService.validateSmartMeterDoesNotExist(deviceIdentification);
final SmartMeter smartMeter = this.smartMeterService.convertSmartMeter(smartMeteringDevice);
this.smartMeterService.storeMeter(organisationId, addSmartMeterRequest, smartMeter);
final SmartMeteringDeviceDto requestDto = this.mapperFactory.getMapperFacade().map(smartMeteringDevice, SmartMeteringDeviceDto.class);
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata);
}
Aggregations