Search in sources :

Example 11 with DeviceOutputSetting

use of org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting 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)

Example 12 with DeviceOutputSetting

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

the class DeviceOutputSettingsSteps method deviceOutputSettingsForLightValues.

@Given("^device output settings for lightvalues$")
public void deviceOutputSettingsForLightValues(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
    final String[] lightValues = getString(settings, PlatformKeys.KEY_LIGHTVALUES, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION).split(PlatformKeys.SEPARATOR_SEMICOLON);
    final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
    for (int i = 0; i < lightValues.length; i++) {
        final String[] lightValueParts = lightValues[i].split(PlatformKeys.SEPARATOR_COMMA);
        final String[] deviceOutputSettingsPart = deviceOutputSettings[i].split(PlatformKeys.SEPARATOR_COMMA);
        final DeviceOutputSetting deviceOutputSettingsForLightValue = new DeviceOutputSetting(Integer.parseInt(deviceOutputSettingsPart[0]), Integer.parseInt(lightValueParts[0]), Enum.valueOf(RelayType.class, deviceOutputSettingsPart[1]), deviceOutputSettingsPart[2]);
        outputSettings.add(deviceOutputSettingsForLightValue);
    }
    this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given)

Example 13 with DeviceOutputSetting

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

the class DeviceOutputSettingsSteps method deviceOutputSettings.

@Given("^device output settings$")
public void deviceOutputSettings(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
    final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
    for (final String deviceOutputSetting : deviceOutputSettings) {
        final String[] deviceOutputSettingsPart = deviceOutputSetting.split(PlatformKeys.SEPARATOR_COMMA);
        final DeviceOutputSetting deviceOutputSettingsForLightValue = new DeviceOutputSetting(Integer.parseInt(deviceOutputSettingsPart[0]), Integer.parseInt(deviceOutputSettingsPart[1]), Enum.valueOf(RelayType.class, deviceOutputSettingsPart[2]), deviceOutputSettingsPart[3]);
        outputSettings.add(deviceOutputSettingsForLightValue);
    }
    this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given)

Example 14 with DeviceOutputSetting

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

the class DeviceOutputSettingsSteps method aDeviceOutputSetting.

@Given("^a device output setting$")
public void aDeviceOutputSetting(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
    final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
    final DeviceOutputSetting deviceOutputSetting = new DeviceOutputSetting(getInteger(settings, PlatformKeys.KEY_INTERNALID, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_INTERNALID), getInteger(settings, PlatformKeys.KEY_EXTERNALID, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_EXTERNALID), getEnum(settings, PlatformKeys.KEY_RELAY_TYPE, RelayType.class, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_RELAY_TYPE), getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_DEVICE_OUTPUT_SETTING_ALIAS));
    outputSettings.add(deviceOutputSetting);
    this.saveDeviceOutputSettingsAndRelayStatuses(outputSettings, device);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given)

Example 15 with DeviceOutputSetting

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

the class AdHocManagementService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final DomainType allowedDomainType, final CorrelationIds ids, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    ResponseMessageResultType result = deviceResult;
    OsgpException osgpException = exception;
    DeviceStatusMapped deviceStatusMapped = null;
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", osgpException);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
        final List<DeviceOutputSetting> deviceOutputSettings = ssld.getOutputSettings();
        final Map<Integer, DeviceOutputSetting> dosMap = new HashMap<>();
        for (final DeviceOutputSetting dos : deviceOutputSettings) {
            dosMap.put(dos.getExternalId(), dos);
        }
        if (status != null) {
            deviceStatusMapped = new DeviceStatusMapped(FilterLightAndTariffValuesHelper.filterTariffValues(status.getLightValues(), dosMap, allowedDomainType), FilterLightAndTariffValuesHelper.filterLightValues(status.getLightValues(), dosMap, allowedDomainType), status.getPreferredLinkType(), status.getActualLinkType(), status.getLightType(), status.getEventNotificationsMask());
            this.updateDeviceRelayOverview(ssld, deviceStatusMapped);
        } else {
            result = ResponseMessageResultType.NOT_OK;
            osgpException = new TechnicalException(ComponentType.DOMAIN_TARIFF_SWITCHING, "Device was not able to report status", new NoDeviceResponseException());
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(deviceStatusMapped).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) NoDeviceResponseException(org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException) HashMap(java.util.HashMap) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DeviceStatusMapped(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Aggregations

DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)19 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)16 ArrayList (java.util.ArrayList)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)7 Given (io.cucumber.java.en.Given)6 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)6 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)4 HashMap (java.util.HashMap)3 RelayStatus (org.opensmartgridplatform.domain.core.entities.RelayStatus)3 DeviceStatusMapped (org.opensmartgridplatform.domain.core.valueobjects.DeviceStatusMapped)3 NoDeviceResponseException (org.opensmartgridplatform.shared.exceptionhandling.NoDeviceResponseException)3 Date (java.util.Date)2 Ean (org.opensmartgridplatform.domain.core.entities.Ean)2 RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)2 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1