use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class PushNotificationSmsMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
final MessageMetadata metadata = MessageMetadata.fromMessage(message);
LOGGER.info("Received message of messageType: {} organisationIdentification: {} deviceIdentification: {}", this.messageType, metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
final RequestMessage requestMessage = (RequestMessage) message.getObject();
final Object dataObject = requestMessage.getRequest();
try {
final Device device = this.getDevice(metadata.getDeviceIdentification());
final PushNotificationSmsDto pushNotificationSms = (PushNotificationSmsDto) dataObject;
this.storeSmsAsEvent(pushNotificationSms);
if (pushNotificationSms.getIpAddress() != null && !"".equals(pushNotificationSms.getIpAddress())) {
LOGGER.info("Updating device {} IP address from {} to {}", metadata.getDeviceIdentification(), requestMessage.getIpAddress(), pushNotificationSms.getIpAddress());
// Convert the IP address from String to InetAddress.
final InetAddress address = InetAddress.getByName(pushNotificationSms.getIpAddress());
device.updateRegistrationData(address, device.getDeviceType());
device.updateConnectionDetailsToSuccess();
this.deviceRepository.save(device);
} else {
LOGGER.warn("Sms notification request for device = {} has no new IP address. Discard request.", metadata.getDeviceIdentification());
}
} catch (final UnknownHostException | FunctionalException e) {
final String errorMessage = String.format("%s occurred, reason: %s", e.getClass().getName(), e.getMessage());
LOGGER.error(errorMessage, e);
throw new JMSException(errorMessage);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class DaRtuDeviceRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing distribution automation request message");
final MessageMetadata messageMetadata;
final Serializable request;
try {
messageMetadata = MessageMetadata.fromMessage(message);
request = message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
this.printDomainInfo(requestMessageData);
final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
this.deviceService.getData(new DaDeviceRequest(deviceRequestBuilder, request), iec61850DeviceResponseHandler, this);
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class PublicLightingResumeScheduleRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing public lighting resume schedule request message");
MessageMetadata messageMetadata;
ResumeScheduleMessageDataContainerDto resumeScheduleMessageDataContainer;
try {
messageMetadata = MessageMetadata.fromMessage(message);
resumeScheduleMessageDataContainer = (ResumeScheduleMessageDataContainerDto) 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 ResumeScheduleDeviceRequest deviceRequest = new ResumeScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), resumeScheduleMessageDataContainer);
this.deviceService.resumeSchedule(deviceRequest);
} catch (final RuntimeException e) {
this.handleError(e, messageMetadata);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class PublicLightingSetScheduleRequestMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) {
LOGGER.debug("Processing public lighting set schedule request message");
final MessageMetadata messageMetadata;
final ScheduleDto schedule;
try {
messageMetadata = MessageMetadata.fromMessage(message);
schedule = (ScheduleDto) message.getObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
return;
}
try {
this.pendingSetScheduleRequestService.removeExpiredPendingSetScheduleRequestRecords(messageMetadata.getDeviceIdentification());
final List<PendingSetScheduleRequest> pendingSetScheduleRequestList = this.pendingSetScheduleRequestService.getAllByDeviceIdentificationNotExpired(messageMetadata.getDeviceIdentification());
if (!pendingSetScheduleRequestList.isEmpty()) {
throw new FunctionalException(FunctionalExceptionType.SET_SCHEDULE_WITH_ASTRONOMICAL_OFFSETS_IN_PROGRESS, ComponentType.PROTOCOL_OSLP, new Throwable(String.format("A set schedule with astronomical offsets is already in progress for device %s", messageMetadata.getDeviceIdentification())));
}
ScheduleMessageDataContainerDto.Builder builder = new ScheduleMessageDataContainerDto.Builder(schedule);
if (schedule.getAstronomicalSunriseOffset() != null || schedule.getAstronomicalSunsetOffset() != null) {
LOGGER.info("Set a schedule for a device with astronomical offsets");
builder = builder.withScheduleMessageType(ScheduleMessageTypeDto.RETRIEVE_CONFIGURATION);
}
final ScheduleMessageDataContainerDto scheduleMessageDataContainer = builder.build();
this.printDomainInfo(messageMetadata.getMessageType(), messageMetadata.getDomain(), messageMetadata.getDomainVersion());
final SetScheduleDeviceRequest deviceRequest = new SetScheduleDeviceRequest(DeviceRequest.newBuilder().messageMetaData(messageMetadata), scheduleMessageDataContainer, RelayTypeDto.LIGHT);
this.deviceService.setSchedule(deviceRequest);
} catch (final RuntimeException e) {
this.handleError(e, messageMetadata);
} catch (final FunctionalException e) {
this.handleFunctionalException(e, messageMetadata);
}
}
use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.
the class TariffSwitchingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.
private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
DeviceStatusDto status = null;
try {
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
status = response.getDeviceStatus();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
}
final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
responseMessageSender.send(responseMessage);
}
Aggregations