use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class OsgpCoreResponseSteps method protocolResponseMessage.
private ProtocolResponseMessage protocolResponseMessage(final Map<String, String> map) {
final String deviceIdentification = map.get("device_identification");
final Iec60870Device device = this.deviceSteps.getDevice(deviceIdentification).orElse(null);
final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(device.getDeviceType());
final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.GET_LIGHT_SENSOR_STATUS.name()).withDomain(domainInfo.getDomain()).withDomainVersion(domainInfo.getDomainVersion()).build();
return ProtocolResponseMessage.newBuilder().messageMetadata(deviceMessageMetadata).dataObject(new LightSensorStatusDto(LightSensorStatusTypeDto.valueOf(map.get("status")))).result(ResponseMessageResultType.OK).build();
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class OsgpCoreResponseSteps method connectResponseMessage.
private ProtocolResponseMessage connectResponseMessage(final Map<String, String> map) {
final String deviceIdentification = map.get("device_identification");
final Iec60870Device device = this.deviceSteps.getDevice(deviceIdentification).orElse(null);
final DomainInfo domainInfo = DomainInfoFactory.forDeviceType(device.getDeviceType());
final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withMessageType(MessageType.CONNECT.name()).withDomain(domainInfo.getDomain()).withDomainVersion(domainInfo.getDomainVersion()).build();
return ProtocolResponseMessage.newBuilder().messageMetadata(deviceMessageMetadata).result(ResponseMessageResultType.OK).build();
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class AbstractMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.info("Processing message.");
MessageMetadata messageMetadata = null;
try {
messageMetadata = MessageMetadata.fromMessage(message);
final RequestMetadata requestMetadata = RequestMetadata.newBuilder().messageMetadata(messageMetadata).build();
final ClientConnection deviceConnection = this.iec60870DeviceConnectionService.getConnection(requestMetadata);
this.process(deviceConnection, requestMetadata);
} catch (final ProtocolAdapterException e) {
this.handleError(messageMetadata, e);
} catch (final Exception e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleSetSchedule.
public void handleSetSchedule(final String deviceUid) throws TechnicalException {
final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceUidNotExpired(deviceUid);
if (pendingSetScheduleRequestList.isEmpty()) {
// schedule with astronomical offsets
return;
}
if (pendingSetScheduleRequestList.size() > 1) {
throw new TechnicalException(String.format("Currently there are %d pending set schedule requests for device %s. Only one is allowed.", pendingSetScheduleRequestList.size(), deviceUid));
}
final PendingSetScheduleRequest pendingSetScheduleRequest = pendingSetScheduleRequestList.get(0);
final ScheduleMessageDataContainerDto dto = pendingSetScheduleRequest.getScheduleMessageDataContainerDto();
ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(dto.getSchedule());
builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE);
final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
final DeviceRequest deviceRequest = pendingSetScheduleRequest.getDeviceRequest();
final MessageMetadata messageMetadata = this.getMessageMetadataFromDeviceRequest(deviceRequest);
final SetScheduleDeviceRequest newDeviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
this.deviceService.setSchedule(newDeviceRequest);
this.pendingSetScheduleRequestService.remove(pendingSetScheduleRequest);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class CommonSetEventNotificationsRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing common set event notifications request message");
MessageMetadata messageMetadata;
EventNotificationMessageDataContainerDto eventNotificationMessageDataContainer;
try {
messageMetadata = MessageMetadata.fromMessage(message);
eventNotificationMessageDataContainer = (EventNotificationMessageDataContainerDto) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
try {
this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
final SetEventNotificationsDeviceRequest deviceRequest = new SetEventNotificationsDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), eventNotificationMessageDataContainer);
this.deviceService.setEventNotifications(deviceRequest);
} catch (final RuntimeException e) {
this.handleError(e, messageMetadata);
}
}
Aggregations