Search in sources :

Example 26 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class DeviceMappingTest method coreSsld.

private Ssld coreSsld() {
    final Ssld ssld = new Ssld(DEVICE_IDENTIFICATION, null, this.address(), this.gpsCoordinates(), null);
    ssld.updateRegistrationData(null, DEVICE_TYPE);
    ssld.setHasSchedule(false);
    ssld.setPublicKeyPresent(false);
    return ssld;
}
Also used : Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 27 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class DeviceMappingTest method testConvertSsldToCore.

@Test
void testConvertSsldToCore() {
    final Ssld ssld = mapper.map(this.adhocManagementSsld(), Ssld.class);
    assertThat(ssld).usingRecursiveComparison().ignoringFields("creationTime", "modificationTime").isEqualTo(this.coreSsld());
}
Also used : Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Test(org.junit.jupiter.api.Test)

Example 28 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class DeviceInstallationService method handleSsld.

private void handleSsld(final String deviceIdentification, final DeviceStatus status, final GetStatusResponse response) {
    // Find device and output settings.
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
    final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
    // Create map with external relay number as key set.
    final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
    for (final DeviceOutputSetting dos : deviceOutputSettings) {
        dosMap.put(dos.getExternalId(), dos);
    }
    if (status != null) {
        // Map the DeviceStatus for SSLD.
        final DeviceStatusMapped deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, DomainType.TARIFF_SWITCHING), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, DomainType.PUBLIC_LIGHTING), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
        deviceStatusMapped.setBootLoaderVersion(status.getBootLoaderVersion());
        deviceStatusMapped.setCurrentConfigurationBackUsed(status.getCurrentConfigurationBackUsed());
        deviceStatusMapped.setCurrentIp(status.getCurrentIp());
        deviceStatusMapped.setCurrentTime(status.getCurrentTime());
        deviceStatusMapped.setDcOutputVoltageCurrent(status.getDcOutputVoltageCurrent());
        deviceStatusMapped.setDcOutputVoltageMaximum(status.getDcOutputVoltageMaximum());
        deviceStatusMapped.setEventNotificationsMask(status.getEventNotificationsMask());
        deviceStatusMapped.setExternalFlashMemSize(status.getExternalFlashMemSize());
        deviceStatusMapped.setFirmwareVersion(status.getFirmwareVersion());
        deviceStatusMapped.setHardwareId(status.getHardwareId());
        deviceStatusMapped.setInternalFlashMemSize(status.getInternalFlashMemSize());
        deviceStatusMapped.setLastInternalTestResultCode(status.getLastInternalTestResultCode());
        deviceStatusMapped.setMacAddress(status.getMacAddress());
        deviceStatusMapped.setMaximumOutputPowerOnDcOutput(status.getMaximumOutputPowerOnDcOutput());
        deviceStatusMapped.setName(status.getName());
        deviceStatusMapped.setNumberOfOutputs(status.getNumberOfOutputs());
        deviceStatusMapped.setSerialNumber(status.getSerialNumber());
        deviceStatusMapped.setStartupCounter(status.getStartupCounter());
        // Return mapped status using GetStatusResponse instance.
        response.setDeviceStatusMapped(deviceStatusMapped);
    } else {
        // No status received, create bad response.
        response.setDeviceStatusMapped(null);
        response.setOsgpException(new TechnicalException(ComponentType.DOMAIN_CORE, "SSLD was not able to report relay status", new NoDeviceResponseException()));
        response.setResult(ResponseMessageResultType.NOT_OK);
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) NoDeviceResponseException(org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException) HashMap(java.util.HashMap) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 29 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class RelayStatusSteps method aDeviceRelayStatus.

@Given("^a device relay status$")
public void aDeviceRelayStatus(final Map<String, String> settings) {
    final Ssld ssld = this.ssldDeviceSteps.findByDeviceIdentification(settings);
    final RelayStatus relayStatus = this.relayStatusFactory.fromMap(ssld, settings);
    ssld.addOrUpdateRelayStatus(relayStatus);
    this.ssldDeviceSteps.saveSsld(ssld);
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given)

Example 30 with Ssld

use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.

the class SsldDeviceSteps method createAnSsldDevice.

private Ssld createAnSsldDevice(final Map<String, String> settings) {
    // Set the required stuff
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final Ssld ssld = new Ssld(deviceIdentification);
    ssld.setPublicKeyPresent(getBoolean(settings, PlatformKeys.KEY_PUBLICKEYPRESENT, PlatformDefaults.DEFAULT_PUBLICKEYPRESENT));
    ssld.setHasSchedule(getBoolean(settings, PlatformKeys.KEY_HAS_SCHEDULE, PlatformDefaults.DEFAULT_HASSCHEDULE));
    if (settings.containsKey(PlatformKeys.KEY_INTERNALID) || settings.containsKey(PlatformKeys.KEY_EXTERNALID) || settings.containsKey(PlatformKeys.KEY_RELAY_TYPE)) {
        final List<DeviceOutputSetting> dosList = new ArrayList<>();
        final int internalId = getInteger(settings, PlatformKeys.KEY_INTERNALID, PlatformDefaults.DEFAULT_INTERNALID), externalId = getInteger(settings, PlatformKeys.KEY_EXTERNALID, PlatformDefaults.DEFAULT_EXTERNALID);
        final RelayType relayType = getEnum(settings, PlatformKeys.KEY_RELAY_TYPE, RelayType.class, RelayType.LIGHT);
        if (relayType != null) {
            dosList.add(new DeviceOutputSetting(internalId, externalId, relayType));
            ssld.updateOutputSettings(dosList);
        }
    }
    ssld.updateInMaintenance(getBoolean(settings, PlatformKeys.DEVICE_IN_MAINTENANCE, PlatformDefaults.DEVICE_IN_MAINTENANCE));
    ssld.setFailedConnectionCount(getInteger(settings, PlatformKeys.KEY_FAILED_CONNECTION_COUNT, PlatformDefaults.DEFAULT_FAILED_CONNECTION_COUNT));
    final DateTime lastSuccessfulConnectionTimestamp = getDate(settings, PlatformKeys.KEY_LAST_COMMUNICATION_TIME, DateTime.now());
    ssld.setLastSuccessfulConnectionTimestamp(lastSuccessfulConnectionTimestamp.toDate());
    if (settings.containsKey(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION)) {
        final LightMeasurementDevice lmd = this.lmdRepository.findByDeviceIdentification(settings.get(PlatformKeys.KEY_LIGHTMEASUREMENT_DEVICE_IDENTIFICATION));
        ssld.setLightMeasurementDevice(lmd);
    }
    this.ssldRepository.save(ssld);
    // now update the common stuff of the SSLD device.
    this.updateDevice(deviceIdentification, settings);
    // Return the updated ssld device.
    return this.ssldRepository.findByDeviceIdentification(deviceIdentification);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DateTime(org.joda.time.DateTime) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)50 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)16 Device (org.opensmartgridplatform.domain.core.entities.Device)13 ArrayList (java.util.ArrayList)12 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)11 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 Test (org.junit.jupiter.api.Test)9 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9 Given (io.cucumber.java.en.Given)8 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)8 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)5 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)5 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)5 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)4 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)4 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)4