Search in sources :

Example 1 with RelayMap

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

Example 2 with RelayMap

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

the class ConfigurationManagementService method updateDeviceOutputSettings.

private void updateDeviceOutputSettings(final Device device, final Configuration configuration) {
    // Check if device output settings can/should be updated
    if (device == null || configuration == null || configuration.getRelayConfiguration() == null) {
        // Nothing to update
        return;
    }
    if (configuration.getRelayConfiguration().getRelayMap() == null || configuration.getRelayConfiguration().getRelayMap().isEmpty()) {
        // Nothing to update
        return;
    }
    final List<DeviceOutputSetting> outputSettings = new ArrayList<>();
    for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
        outputSettings.add(new DeviceOutputSetting(rm.getAddress(), rm.getIndex(), rm.getRelayType(), rm.getAlias()));
    }
    final Ssld ssld = this.findSsldForDevice(device);
    ssld.updateOutputSettings(outputSettings);
    this.ssldRepository.save(ssld);
}
Also used : ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 3 with RelayMap

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

the class OslpDeviceSteps method aSetConfigurationOslpMessageIsSentToDevice.

/**
 * Verify that a set configuration OSLP message is sent to the device.
 *
 * @param deviceIdentification The device identification expected in the message to the device.
 */
@Then("^a set configuration \"([^\"]*)\" message is sent to device \"([^\"]*)\"$")
public void aSetConfigurationOslpMessageIsSentToDevice(final String protocol, final String deviceIdentification, final Map<String, String> expectedResponseData) throws DeviceSimulatorException {
    final Message receivedMessage = this.oslpMockServer.waitForRequest(this.getDeviceUid(expectedResponseData), MessageType.SET_CONFIGURATION);
    assertThat(receivedMessage).isNotNull();
    assertThat(receivedMessage.hasSetConfigurationRequest()).isTrue();
    final SetConfigurationRequest receivedConfiguration = receivedMessage.getSetConfigurationRequest();
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_LIGHTTYPE)) && receivedConfiguration.getLightType() != null) {
        final LightType expectedLightType = getEnum(expectedResponseData, PlatformKeys.KEY_LIGHTTYPE, LightType.class);
        assertThat(receivedConfiguration.getLightType()).isEqualTo(expectedLightType);
        switch(expectedLightType) {
            case DALI:
                final DaliConfiguration receivedDaliConfiguration = receivedConfiguration.getDaliConfiguration();
                if (receivedDaliConfiguration != null) {
                    if (expectedResponseData.containsKey(PlatformKeys.DC_LIGHTS) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_LIGHTS))) {
                        assertThat(OslpUtils.byteStringToInteger(receivedDaliConfiguration.getNumberOfLights())).isEqualTo(getInteger(expectedResponseData, PlatformKeys.DC_LIGHTS));
                    }
                    if (expectedResponseData.containsKey(PlatformKeys.DC_MAP) && StringUtils.isNotBlank(expectedResponseData.get(PlatformKeys.DC_MAP))) {
                        assertThat(receivedDaliConfiguration.getAddressMapList()).isNotNull();
                        final String[] expectedDcMapArray = getString(expectedResponseData, PlatformKeys.DC_MAP).split(";");
                        assertThat(receivedDaliConfiguration.getAddressMapList().size()).isEqualTo(expectedDcMapArray.length);
                        final List<IndexAddressMap> receivedIndexAddressMapList = receivedDaliConfiguration.getAddressMapList();
                        for (int i = 0; i < expectedDcMapArray.length; i++) {
                            final String[] expectedDcMapArrayElements = expectedDcMapArray[i].split(",");
                            assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getIndex())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[0]));
                            assertThat(OslpUtils.byteStringToInteger(receivedIndexAddressMapList.get(i).getAddress())).isEqualTo((Integer) Integer.parseInt(expectedDcMapArrayElements[1]));
                        }
                    }
                }
                break;
            case RELAY:
                final RelayConfiguration receivedRelayConfiguration = receivedConfiguration.getRelayConfiguration();
                if (receivedRelayConfiguration != null) {
                    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.RELAY_CONF)) && receivedRelayConfiguration.getAddressMapList() != null) {
                        // Construct sorted list of received relay maps
                        final List<RelayMap> receivedRelayMapList = RelayMapConverter.convertIndexAddressMapListToRelayMapList(receivedRelayConfiguration.getAddressMapList());
                        Collections.sort(receivedRelayMapList);
                        // Construct sorted list of expected relay maps
                        final String[] expectedRelayMapArray = getString(expectedResponseData, PlatformKeys.RELAY_CONF).split(";");
                        final List<RelayMap> expectedRelayMapList = RelayMapConverter.convertStringsListToRelayMapList(expectedRelayMapArray);
                        Collections.sort(expectedRelayMapList);
                        assertThat(CollectionUtils.isEmpty(receivedRelayMapList)).as("Either the expected or the received relay maps are empty, but not both").isEqualTo(CollectionUtils.isEmpty(expectedRelayMapList));
                        if (!CollectionUtils.isEmpty(receivedRelayMapList) && !CollectionUtils.isEmpty(expectedRelayMapList)) {
                            assertThat(receivedRelayMapList.size()).as("Size of expected and received relay map list differs").isEqualTo(expectedRelayMapList.size());
                        }
                        // Compare the contents of each relay map
                        for (int i = 0; i < expectedRelayMapList.size(); i++) {
                            assertThat(receivedRelayMapList.get(i)).as("Expected and received relay map differs for " + i).isEqualTo(expectedRelayMapList.get(i));
                        }
                    }
                }
                break;
            case ONE_TO_TEN_VOLT:
            case ONE_TO_TEN_VOLT_REVERSE:
            case LT_NOT_SET:
            default:
                assertThat(receivedConfiguration.getDaliConfiguration().getAddressMapList().size()).isEqualTo(0);
                assertThat(receivedConfiguration.getRelayConfiguration().getAddressMapList().size()).isEqualTo(0);
        }
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_PREFERRED_LINKTYPE)) && receivedConfiguration.getPreferredLinkType() != null) {
        assertThat(receivedConfiguration.getPreferredLinkType()).isEqualTo(getEnum(expectedResponseData, PlatformKeys.KEY_PREFERRED_LINKTYPE, LinkType.class));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS))) {
        assertThat(OslpDeviceSteps.convertIpAddress(receivedConfiguration.getOspgIpAddress())).isEqualTo(expectedResponseData.get(PlatformKeys.OSGP_IP_ADDRESS));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.OSGP_PORT))) {
        assertThat(receivedConfiguration.getOsgpPortNumber()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.OSGP_PORT)));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET))) {
        assertThat(receivedConfiguration.getAstroGateSunRiseOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNRISE_OFFSET)));
    }
    if (!StringUtils.isEmpty(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET))) {
        assertThat(receivedConfiguration.getAstroGateSunSetOffset()).isEqualTo(Integer.parseInt(expectedResponseData.get(PlatformKeys.KEY_ASTRONOMICAL_SUNSET_OFFSET)));
    }
}
Also used : LightType(org.opensmartgridplatform.oslp.Oslp.LightType) DaliConfiguration(org.opensmartgridplatform.oslp.Oslp.DaliConfiguration) Message(org.opensmartgridplatform.oslp.Oslp.Message) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) ByteString(com.google.protobuf.ByteString) IndexAddressMap(org.opensmartgridplatform.oslp.Oslp.IndexAddressMap) SetConfigurationRequest(org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest) RelayConfiguration(org.opensmartgridplatform.oslp.Oslp.RelayConfiguration) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) LinkType(org.opensmartgridplatform.oslp.Oslp.LinkType) Then(io.cucumber.java.en.Then)

Example 4 with RelayMap

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

the class RelayMapConverter method convertIndexAddressMapToRelayMap.

/**
 * Converts an IndexAddressMap received from an OSLP device to a RelayMap
 *
 * @param indexAddressMap the IndexAddressMap to convert.
 * @return the created RelayMap.
 */
private static RelayMap convertIndexAddressMapToRelayMap(final IndexAddressMap indexAddressMap) {
    final RelayType relayType = RelayType.valueOf(indexAddressMap.getRelayType().toString());
    final Integer relayIndex = OslpUtils.byteStringToInteger(indexAddressMap.getIndex());
    final Integer relayAddress = OslpUtils.byteStringToInteger(indexAddressMap.getAddress());
    return new RelayMap(relayIndex, relayAddress, relayType, null);
}
Also used : RelayType(org.opensmartgridplatform.domain.core.valueobjects.RelayType) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap)

Example 5 with RelayMap

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

the class ConfigurationManagementService method setConfiguration.

// === SET CONFIGURATION ===
public void setConfiguration(final CorrelationIds ids, final Configuration configuration, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.debug("setConfiguration called with organisation {} and device {}", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    if (configuration == null) {
        LOGGER.info("Configuration is empty, skip sending a request to device");
        return;
    }
    // First, persist the configuration of the device output settings.
    this.updateDeviceOutputSettings(device, configuration);
    // contain a TARIFF_REVERSED enum entry.
    if (configuration.getRelayConfiguration() != null && configuration.getRelayConfiguration().getRelayMap() != null) {
        for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
            if (rm.getRelayType().equals(RelayType.TARIFF_REVERSED)) {
                rm.changeRelayType(RelayType.TARIFF);
            }
        }
    }
    final org.opensmartgridplatform.dto.valueobjects.ConfigurationDto configurationDto = this.domainCoreMapper.map(configuration, org.opensmartgridplatform.dto.valueobjects.ConfigurationDto.class);
    this.osgpCoreRequestMessageSender.sendWithScheduledTime(new RequestMessage(ids, configurationDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)

Aggregations

RelayMap (org.opensmartgridplatform.domain.core.valueobjects.RelayMap)6 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)2 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)2 ByteString (com.google.protobuf.ByteString)1 Then (io.cucumber.java.en.Then)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 Configuration (org.opensmartgridplatform.domain.core.valueobjects.Configuration)1 RelayConfiguration (org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration)1 RelayType (org.opensmartgridplatform.domain.core.valueobjects.RelayType)1 ConfigurationDto (org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)1 DaliConfiguration (org.opensmartgridplatform.oslp.Oslp.DaliConfiguration)1 IndexAddressMap (org.opensmartgridplatform.oslp.Oslp.IndexAddressMap)1 LightType (org.opensmartgridplatform.oslp.Oslp.LightType)1 LinkType (org.opensmartgridplatform.oslp.Oslp.LinkType)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1 RelayConfiguration (org.opensmartgridplatform.oslp.Oslp.RelayConfiguration)1 SetConfigurationRequest (org.opensmartgridplatform.oslp.Oslp.SetConfigurationRequest)1