Search in sources :

Example 1 with Configuration

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

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

the class DomainCoreMapperTest method convertsConfigurationDtoToConfiguration.

@Test
void convertsConfigurationDtoToConfiguration() {
    final ConfigurationDto source = this.aConfigurationDto();
    final Configuration result = this.mapper.map(source, Configuration.class);
    assertThat(result).usingRecursiveComparison().isEqualTo(this.toConfiguration(source));
}
Also used : DaliConfigurationDto(org.opensmartgridplatform.dto.valueobjects.DaliConfigurationDto) RelayConfigurationDto(org.opensmartgridplatform.dto.valueobjects.RelayConfigurationDto) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) RelayConfiguration(org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration) DaliConfiguration(org.opensmartgridplatform.domain.core.valueobjects.DaliConfiguration) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) Test(org.junit.jupiter.api.Test)

Example 3 with Configuration

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

the class ConfigurationManagementEndpoint method getGetConfigurationResponse.

@PayloadRoot(localPart = "GetConfigurationAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetConfigurationResponse getGetConfigurationResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetConfigurationAsyncRequest request) throws OsgpException {
    LOGGER.info("GetConfigurationRequest received from organisation: {} for device: {}.", organisationIdentification, request.getAsyncRequest().getDeviceId());
    final GetConfigurationResponse response = new GetConfigurationResponse();
    try {
        final ResponseMessage responseMessage = this.getResponseMessage(request.getAsyncRequest());
        if (responseMessage != null) {
            throwExceptionIfResultNotOk(responseMessage, "getting configuration");
            response.setResult(OsgpResultType.fromValue(responseMessage.getResult().getValue()));
            if (responseMessage.getDataObject() != null) {
                final Configuration configuration = (Configuration) responseMessage.getDataObject();
                response.setConfiguration(this.configurationManagementMapper.map(configuration, org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.Configuration.class));
            }
        } else {
            LOGGER.debug("Get Configuration data is null");
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) GetConfigurationResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 4 with Configuration

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

the class ConfigurationManagementEndpoint method setConfiguration.

@PayloadRoot(localPart = "SetConfigurationRequest", namespace = NAMESPACE)
@ResponsePayload
public SetConfigurationAsyncResponse setConfiguration(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetConfigurationRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Configuration Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetConfigurationAsyncResponse response = new SetConfigurationAsyncResponse();
    try {
        // Get the request parameters, make sure that they are in UTC.
        // Maybe add an adapter to the service, so that all date-time are
        // converted to UTC automatically.
        final DateTime scheduleTime = request.getScheduledTime() == null ? null : new DateTime(request.getScheduledTime().toGregorianCalendar()).toDateTime(DateTimeZone.UTC);
        final Configuration configuration = this.configurationManagementMapper.map(request.getConfiguration(), Configuration.class);
        final String correlationUid = this.configurationManagementService.enqueueSetConfigurationRequest(organisationIdentification, request.getDeviceIdentification(), configuration, scheduleTime, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : SetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse) SwitchConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SwitchConfigurationAsyncResponse) SetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse) GetConfigurationAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationAsyncResponse) DateTime(org.joda.time.DateTime) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 5 with Configuration

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

the class ConfigurationConverter method convertTo.

@Override
public Configuration convertTo(final org.opensmartgridplatform.dto.valueobjects.ConfigurationDto source, final Type<Configuration> destinationType, final MappingContext context) {
    final LightType lightType = this.mapperFacade.map(source.getLightType(), LightType.class);
    final DaliConfiguration daliConfiguration = this.mapperFacade.map(source.getDaliConfiguration(), DaliConfiguration.class);
    final RelayConfiguration relayConfiguration = this.mapperFacade.map(source.getRelayConfiguration(), RelayConfiguration.class);
    final LinkType preferredLinkType = this.mapperFacade.map(source.getPreferredLinkType(), LinkType.class);
    final Configuration.Builder builder = new Configuration.Builder().withLightType(lightType).withDaliConfiguration(daliConfiguration).withRelayConfiguration(relayConfiguration).withPreferredLinkType(preferredLinkType).withTimeSyncFrequency(source.getTimeSyncFrequency()).withDhcpEnabled(source.isDhcpEnabled()).withTlsEnabled(source.isTlsEnabled()).withTlsPortNumber(source.getTlsPortNumber()).withCommonNameString(source.getCommonNameString()).withCommunicationTimeout(source.getCommunicationTimeout()).withCommunicationNumberOfRetries(source.getCommunicationNumberOfRetries()).withCommunicationPauseTimeBetweenConnectionTrials(source.getCommunicationPauseTimeBetweenConnectionTrials()).withOsgpIpAddress(source.getOsgpIpAddres()).withOsgpPortNumber(source.getOsgpPortNumber()).withNtpHost(source.getNtpHost()).withNtpEnabled(source.getNtpEnabled()).withNtpSyncInterval(source.getNtpSyncInterval()).withTestButtonEnabled(source.isTestButtonEnabled()).withAutomaticSummerTimingEnabled(source.isAutomaticSummerTimingEnabled()).withAstroGateSunRiseOffset(source.getAstroGateSunRiseOffset()).withAstroGateSunSetOffset(source.getAstroGateSunSetOffset()).withSwitchingDelays(source.getSwitchingDelays()).withRelayRefreshing(source.isRelayRefreshing()).withSummerTimeDetails(source.getSummerTimeDetails()).withWinterTimeDetails(source.getWinterTimeDetails());
    if (source.getRelayLinking() != null) {
        builder.withRelayLinking(this.mapperFacade.mapAsList(source.getRelayLinking(), org.opensmartgridplatform.domain.core.valueobjects.RelayMatrix.class));
    }
    if (source.getDeviceFixedIp() != null) {
        builder.withDeviceFixedIp(this.mapperFacade.map(source.getDeviceFixedIp(), DeviceFixedIp.class));
    }
    return builder.build();
}
Also used : LightType(org.opensmartgridplatform.domain.core.valueobjects.LightType) DaliConfiguration(org.opensmartgridplatform.domain.core.valueobjects.DaliConfiguration) DeviceFixedIp(org.opensmartgridplatform.domain.core.valueobjects.DeviceFixedIp) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) DaliConfiguration(org.opensmartgridplatform.domain.core.valueobjects.DaliConfiguration) RelayConfiguration(org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration) RelayConfiguration(org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration) LinkType(org.opensmartgridplatform.domain.core.valueobjects.LinkType)

Aggregations

Configuration (org.opensmartgridplatform.domain.core.valueobjects.Configuration)6 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 ConstraintViolationException (javax.validation.ConstraintViolationException)2 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)2 DaliConfiguration (org.opensmartgridplatform.domain.core.valueobjects.DaliConfiguration)2 RelayConfiguration (org.opensmartgridplatform.domain.core.valueobjects.RelayConfiguration)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)2 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)2 JMSException (javax.jms.JMSException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.jupiter.api.Test)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)1 GetConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationAsyncResponse)1 GetConfigurationResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.GetConfigurationResponse)1 SetConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SetConfigurationAsyncResponse)1 SwitchConfigurationAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.SwitchConfigurationAsyncResponse)1 DeviceOutputSetting (org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting)1 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)1