Search in sources :

Example 1 with DeviceOutputSetting

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

the class SsldDeviceSteps method aSwitchingEventRelayStatus.

@Given("^a switching event relay status$")
@Transactional("txMgrCore")
public void aSwitchingEventRelayStatus(final Map<String, String> settings) {
    final Ssld ssld = this.ssldRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final String[] deviceOutputSettings = getString(settings, PlatformKeys.DEVICE_OUTPUT_SETTINGS, PlatformDefaults.DEVICE_OUTPUT_SETTINGS).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final String[] relayStatuses = getString(settings, PlatformKeys.RELAY_STATUSES, PlatformDefaults.RELAY_STATUSES).replaceAll(" ", "").split(PlatformKeys.SEPARATOR_SEMICOLON);
    final List<DeviceOutputSetting> dosList = new ArrayList<>();
    for (final String dos : deviceOutputSettings) {
        final String[] deviceOutputSetting = dos.split(PlatformKeys.SEPARATOR_COMMA);
        dosList.add(new DeviceOutputSetting(Integer.parseInt(deviceOutputSetting[0]), Integer.parseInt(deviceOutputSetting[1]), RelayType.valueOf(deviceOutputSetting[2]), deviceOutputSetting[3]));
    }
    ssld.updateOutputSettings(dosList);
    for (final String rs : relayStatuses) {
        final String[] relayStatus = rs.split(PlatformKeys.SEPARATOR_COMMA);
        final int index = Integer.parseInt(relayStatus[0]);
        final boolean lastSwitchingEventState = Boolean.parseBoolean(relayStatus[1]);
        final Date lastSwitchingEventTime = getDateTime2(relayStatus[2], DateTime.now()).toDate();
        final RelayStatus currentRelayStatus = ssld.getRelayStatusByIndex(index);
        if (currentRelayStatus == null) {
            this.relayStatusRepository.save(new RelayStatus.Builder(ssld, index).withLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime).build());
        } else {
            currentRelayStatus.updateLastSwitchingEventState(lastSwitchingEventState, lastSwitchingEventTime);
            this.relayStatusRepository.save(currentRelayStatus);
        }
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Date(java.util.Date) ReadSettingsHelper.getDate(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getDate) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DeviceOutputSetting

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

the class DeviceConfigurationSteps method aDeviceOutputSetting.

@Given("^a device configuration$")
public void aDeviceOutputSetting(final Map<String, String> settings) throws Throwable {
    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);
    device.updateOutputSettings(outputSettings);
    this.ssldRepository.save(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 3 with DeviceOutputSetting

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

the class DeviceConfigurationSteps method deviceOutputSettingsForLightValues.

@Given("^device configuration for lightvalues$")
public void deviceOutputSettingsForLightValues(final Map<String, String> settings) throws Throwable {
    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);
    }
    device.updateOutputSettings(outputSettings);
    this.ssldRepository.save(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 4 with DeviceOutputSetting

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

the class DeviceOutputSettingsSteps method saveDeviceOutputSettingsAndRelayStatuses.

private void saveDeviceOutputSettingsAndRelayStatuses(final List<DeviceOutputSetting> deviceOutputSettings, final Ssld device) {
    device.updateOutputSettings(deviceOutputSettings);
    this.ssldRepository.save(device);
    // Create a dummy relay status for each device output setting
    for (final DeviceOutputSetting deviceOutputSetting : deviceOutputSettings) {
        final RelayStatus relayStatus = new RelayStatus.Builder(device, deviceOutputSetting.getExternalId()).withLastSwitchingEventState(false, new Date()).build();
        this.relayStatusRepository.save(relayStatus);
    }
}
Also used : RelayStatus(org.opensmartgridplatform.domain.core.entities.RelayStatus) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) Date(java.util.Date)

Example 5 with DeviceOutputSetting

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

the class ConfigurationManagementService method handleGetConfigurationResponse.

public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    Configuration configuration = null;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
        final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
        this.replaceEmptyOutputSettings(configurationDto, outputSettings);
        configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
        // TARIFF_REVERSED will be changed to the correct RelayType.
        for (final DeviceOutputSetting dos : outputSettings) {
            if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
                for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
                    if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
                        rm.changeRelayType(RelayType.TARIFF_REVERSED);
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) 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