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);
}
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));
}
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;
}
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;
}
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();
}
Aggregations