use of org.opensmartgridplatform.domain.core.valueobjects.Address in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertFrom.
@Override
public org.opensmartgridplatform.domain.core.entities.Ssld convertFrom(final Ssld source, final Type<org.opensmartgridplatform.domain.core.entities.Ssld> destinationType, final MappingContext mappingContext) {
final String deviceIdentification = source.getDeviceIdentification();
final Integer containerNumber = source.getContainerNumber() == null ? null : Integer.valueOf(source.getContainerNumber());
final Address containerAddress = new Address(source.getContainerCity(), source.getContainerPostalCode(), source.getContainerStreet(), containerNumber, null, null);
final GpsCoordinates gpsCoordinates = new GpsCoordinates(source.getGpsLatitude(), source.getGpsLongitude());
final org.opensmartgridplatform.domain.core.entities.Ssld ssld = new org.opensmartgridplatform.domain.core.entities.Ssld(deviceIdentification, null, containerAddress, gpsCoordinates, null);
ssld.updateRegistrationData(null, source.getDeviceType());
ssld.setHasSchedule(source.isHasSchedule());
ssld.setPublicKeyPresent(source.isPublicKeyPresent());
return ssld;
}
use of org.opensmartgridplatform.domain.core.valueobjects.Address in project open-smart-grid-platform by OSGP.
the class SsldConverter method convertTo.
@Override
public Ssld convertTo(final org.opensmartgridplatform.domain.core.entities.Ssld source, final Type<Ssld> destinationType, final MappingContext mappingContext) {
final Ssld ssld = new Ssld();
final String deviceIdentification = source.getDeviceIdentification();
ssld.setDeviceUid(Base64.encodeBase64String(deviceIdentification.getBytes(StandardCharsets.US_ASCII)));
ssld.setDeviceIdentification(deviceIdentification);
final Address containerAddress = source.getContainerAddress();
if (containerAddress != null) {
ssld.setContainerPostalCode(containerAddress.getPostalCode());
ssld.setContainerCity(containerAddress.getCity());
ssld.setContainerStreet(containerAddress.getStreet());
if (containerAddress.getNumber() != null) {
ssld.setContainerNumber(containerAddress.getNumber().toString());
}
}
final GpsCoordinates gpsCoordinates = source.getGpsCoordinates();
if (gpsCoordinates != null) {
ssld.setGpsLatitude(gpsCoordinates.getLatitude());
ssld.setGpsLongitude(gpsCoordinates.getLongitude());
}
ssld.setDeviceType(source.getDeviceType());
ssld.setActivated(source.isActivated());
ssld.setHasSchedule(source.getHasSchedule());
ssld.setPublicKeyPresent(source.isPublicKeyPresent());
return ssld;
}
use of org.opensmartgridplatform.domain.core.valueobjects.Address in project open-smart-grid-platform by OSGP.
the class DeviceInstallationMapperTest method createLmd.
private org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice createLmd() {
final Address containerAddress = this.createAddress();
final GpsCoordinates gps = new GpsCoordinates(GPS_LATITUDE, GPS_LONGITUDE);
final org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice lmd = new org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice(DEVICE_IDENTIFICATION, ALIAS, containerAddress, gps, null);
lmd.setDescription(DESCRIPTION);
lmd.setCode(CODE);
lmd.setColor(COLOR);
lmd.setDigitalInput(DIGITAL_INPUT);
return lmd;
}
use of org.opensmartgridplatform.domain.core.valueobjects.Address in project open-smart-grid-platform by OSGP.
the class AddressConversionTest method shouldConvertAddressToContainer.
@Test
public void shouldConvertAddressToContainer() {
// Arrange
final Address source = this.createAddress();
final org.opensmartgridplatform.adapter.ws.schema.core.common.Address expected = this.createWsAddress();
// Act
final org.opensmartgridplatform.adapter.ws.schema.core.common.Address actual = this.mapper.map(source, org.opensmartgridplatform.adapter.ws.schema.core.common.Address.class);
// Assert
assertThat(actual).isEqualToComparingFieldByField(expected);
}
use of org.opensmartgridplatform.domain.core.valueobjects.Address in project open-smart-grid-platform by OSGP.
the class DeviceConverterTest method testSsldConversion.
@Test
public void testSsldConversion() throws Exception {
final Instant instant = ZonedDateTime.of(2020, 1, 1, 14, 0, 0, 0, ZoneOffset.UTC).toInstant();
final Date date = Date.from(instant);
final GregorianCalendar gregorianCalendar = GregorianCalendar.from(instant.atZone(ZoneOffset.UTC));
final XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
final Ssld device = new Ssld("id", "alias", new Address("city", "postal", "street", 42, "nr", "munic"), new GpsCoordinates(12f, 13f), null);
device.updateRegistrationData(InetAddress.getByName("localhost"), Ssld.SSLD_TYPE);
device.getOutputSettings();
device.setTechnicalInstallationDate(date);
when(this.ssldRepository.findByDeviceIdentification(anyString())).thenReturn(device);
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device jaxbDevice = this.deviceManagementMapper.map(device, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device.class);
assertThat(jaxbDevice.getDeviceIdentification()).isEqualTo("id");
assertThat(jaxbDevice.getAlias()).isEqualTo("alias");
assertThat(jaxbDevice.getContainerAddress().getCity()).isEqualTo("city");
assertThat(jaxbDevice.getContainerAddress().getPostalCode()).isEqualTo("postal");
assertThat(jaxbDevice.getContainerAddress().getStreet()).isEqualTo("street");
assertThat(jaxbDevice.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
assertThat(jaxbDevice.getContainerAddress().getNumberAddition()).isEqualTo("nr");
assertThat(jaxbDevice.getContainerAddress().getMunicipality()).isEqualTo("munic");
assertThat(jaxbDevice.getGpsLatitude()).isEqualTo("12.0");
assertThat(jaxbDevice.getGpsLongitude()).isEqualTo("13.0");
assertThat(jaxbDevice.getNetworkAddress()).isEqualTo("localhost/127.0.0.1");
assertThat(jaxbDevice.getDeviceType()).isEqualTo(Ssld.SSLD_TYPE);
assertThat(jaxbDevice.getOutputSettings().size()).isEqualTo(3);
for (int i = 0; i < 3; i++) {
assertThat(device.getOutputSettings().get(i).getAlias()).isEqualTo(jaxbDevice.getOutputSettings().get(i).getAlias());
}
assertThat(jaxbDevice.getTechnicalInstallationDate()).isEqualTo(xmlGregorianCalendar);
final Ssld mappedBack = this.deviceManagementMapper.map(jaxbDevice, Ssld.class);
assertThat(mappedBack.getDeviceIdentification()).isEqualTo("id");
assertThat(mappedBack.getAlias()).isEqualTo("alias");
assertThat(mappedBack.getContainerAddress().getCity()).isEqualTo("city");
assertThat(mappedBack.getContainerAddress().getPostalCode()).isEqualTo("postal");
assertThat(mappedBack.getContainerAddress().getStreet()).isEqualTo("street");
assertThat(mappedBack.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
assertThat(mappedBack.getContainerAddress().getNumberAddition()).isEqualTo("nr");
assertThat(mappedBack.getContainerAddress().getMunicipality()).isEqualTo("munic");
assertThat(mappedBack.getGpsCoordinates().getLatitude()).isEqualTo(12.0f);
assertThat(mappedBack.getGpsCoordinates().getLongitude()).isEqualTo(13.0f);
// alas networkaddress in jaxb device is just a string, need parsing to
// convert that to InetAddress
assertThat(mappedBack.getNetworkAddress()).isEqualTo(null);
assertThat(mappedBack.getDeviceType()).isEqualTo(Ssld.SSLD_TYPE);
assertThat(mappedBack.getOutputSettings().size()).isEqualTo(3);
for (int i = 0; i < 3; i++) {
assertThat(device.getOutputSettings().get(i).getAlias()).isEqualTo(mappedBack.getOutputSettings().get(i).getAlias());
}
assertThat(mappedBack.getTechnicalInstallationDate()).isEqualTo(date);
}
Aggregations