Search in sources :

Example 11 with Address

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;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)

Example 12 with Address

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;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Ssld(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)

Example 13 with Address

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;
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightMeasurementDevice) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)

Example 14 with Address

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);
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) Test(org.junit.jupiter.api.Test)

Example 15 with Address

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);
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) InetAddress(java.net.InetAddress) Instant(java.time.Instant) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Date(java.util.Date) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Aggregations

Address (org.opensmartgridplatform.domain.core.valueobjects.Address)21 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)18 Test (org.junit.jupiter.api.Test)6 InetAddress (java.net.InetAddress)5 Device (org.opensmartgridplatform.domain.core.entities.Device)4 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)4 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)4 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 Given (io.cucumber.java.en.Given)2 UnknownHostException (java.net.UnknownHostException)2 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice)2 Ssld (org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld)2 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Instant (java.time.Instant)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 LightMeasurementDevice (org.opensmartgridplatform.adapter.ws.schema.core.deviceinstallation.LightMeasurementDevice)1