Search in sources :

Example 1 with Device

use of org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device in project open-smart-grid-platform by OSGP.

the class DeviceConverterHelper method initJaxb.

Device initJaxb(final T source) {
    final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device destination = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device();
    destination.setAlias(source.getAlias());
    destination.setActivated(source.isActivated());
    destination.setDeviceLifecycleStatus(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceLifecycleStatus.valueOf(source.getDeviceLifecycleStatus().name()));
    destination.setContainerAddress(this.mapper.map(source.getContainerAddress(), org.opensmartgridplatform.adapter.ws.schema.core.common.Address.class));
    destination.setDeviceIdentification(source.getDeviceIdentification());
    destination.setDeviceType(source.getDeviceType());
    destination.setTechnicalInstallationDate(this.mapper.map(source.getTechnicalInstallationDate(), XMLGregorianCalendar.class));
    if (!Objects.isNull(source.getGpsCoordinates())) {
        final GpsCoordinates gpsCoordinates = source.getGpsCoordinates();
        if (gpsCoordinates.getLatitude() != null) {
            destination.setGpsLatitude(Float.toString(gpsCoordinates.getLatitude()));
        }
        if (gpsCoordinates.getLongitude() != null) {
            destination.setGpsLongitude(Float.toString(gpsCoordinates.getLongitude()));
        }
    }
    destination.setNetworkAddress(source.getNetworkAddress() == null ? null : source.getNetworkAddress().toString());
    destination.setOwner(source.getOwner() == null ? "" : source.getOwner().getName());
    destination.getOrganisations().addAll(source.getOrganisations());
    destination.setInMaintenance(source.isInMaintenance());
    final List<org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceAuthorization> deviceAuthorizations = new ArrayList<>();
    for (final DeviceAuthorization deviceAuthorisation : source.getAuthorizations()) {
        final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceAuthorization newDeviceAuthorization = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceAuthorization();
        newDeviceAuthorization.setFunctionGroup(deviceAuthorisation.getFunctionGroup().name());
        newDeviceAuthorization.setOrganisation(deviceAuthorisation.getOrganisation().getOrganisationIdentification());
        deviceAuthorizations.add(newDeviceAuthorization);
    }
    destination.getDeviceAuthorizations().addAll(deviceAuthorizations);
    if (source.getDeviceModel() != null) {
        final DeviceModel deviceModel = new DeviceModel();
        deviceModel.setDescription(source.getDeviceModel().getDescription());
        if (source.getDeviceModel().getManufacturer() != null) {
            final Manufacturer manufacturer = new Manufacturer();
            manufacturer.setManufacturerId(source.getDeviceModel().getManufacturer().getCode());
            manufacturer.setName(source.getDeviceModel().getManufacturer().getName());
            manufacturer.setUsePrefix(source.getDeviceModel().getManufacturer().isUsePrefix());
            deviceModel.setManufacturer(manufacturer);
        }
        deviceModel.setModelCode(source.getDeviceModel().getModelCode());
        destination.setDeviceModel(deviceModel);
    }
    destination.setLastCommunicationTime(this.mapper.map(source.getLastSuccessfulConnectionTimestamp(), XMLGregorianCalendar.class));
    if (source instanceof LightMeasurementDevice) {
        final LightMeasurementDevice sourceLmd = (LightMeasurementDevice) source;
        final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.LightMeasurementDevice destinationLmd = new org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.LightMeasurementDevice();
        destinationLmd.setDescription(sourceLmd.getDescription());
        destinationLmd.setCode(sourceLmd.getCode());
        destinationLmd.setColor(sourceLmd.getColor());
        destinationLmd.setDigitalInput(sourceLmd.getDigitalInput());
        destinationLmd.setLastCommunicationTime(this.mapper.map(sourceLmd.getLastCommunicationTime(), XMLGregorianCalendar.class));
        destination.setLightMeasurementDevice(destinationLmd);
    }
    return destination;
}
Also used : DeviceModel(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceModel) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) ArrayList(java.util.ArrayList) Device(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Manufacturer(org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Manufacturer)

Aggregations

ArrayList (java.util.ArrayList)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Device (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device)1 DeviceModel (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.DeviceModel)1 Manufacturer (org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Manufacturer)1 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)1 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)1 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)1 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)1