use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class EventServiceTest method assertEventType.
private void assertEventType(final int eventCode, final String protocol, final EventTypeDto expectedEventTypeDto) throws FunctionalException {
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(protocolInfo.getProtocol()).thenReturn(protocol);
when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
final EventDto event = new EventDto(new DateTime(), eventCode, 2, "STANDARD_EVENT_LOG");
final ArrayList<EventDto> events = new ArrayList<>();
events.add(event);
final EventMessageDataResponseDto responseDto = new EventMessageDataResponseDto(events);
this.eventService.enrichEvents(this.deviceMessageMetadata, responseDto);
assertThat(responseDto.getEvents().size()).isOne();
final EventDto eventDto = responseDto.getEvents().get(0);
assertThat(eventDto.getEventTypeDto()).isEqualTo(expectedEventTypeDto);
assertThat(eventDto.getEventCode()).isEqualTo(eventCode);
final List<EventDetailDto> eventDetails = eventDto.getEventDetails();
assertThat(eventDetails.size()).isZero();
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class ProtocolResponseMessageJmsTemplateFactory method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws SSLException {
for (final ProtocolInfo protocolInfo : this.protocolInfos) {
LOGGER.info("Initializing ProtocolResponseMessageJmsTemplate {}", protocolInfo.getKey());
this.init(protocolInfo);
}
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class ProtocolRequestMessageListenerContainerFactory method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws SSLException {
for (final ProtocolInfo protocolInfo : this.protocolInfos) {
LOGGER.info("Initializing ProtocolRequestMessageListenerContainer {}", protocolInfo.getKey());
this.init(protocolInfo);
}
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class DomainResponseMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
final ObjectMessage objectMessage = (ObjectMessage) message;
final String messageType = objectMessage.getJMSType();
final Object dataObject = objectMessage.getObject();
LOGGER.info("Received domain incoming response message of type [{}]", messageType);
ProtocolInfo protocolInfo = null;
for (final ProtocolInfo pi : this.protocolInfos) {
if ("OSLP".equals(pi.getProtocol()) && "1.0".equals(pi.getProtocolVersion())) {
protocolInfo = pi;
}
}
if (protocolInfo == null) {
throw new OsgpCoreException("No protocol info!");
}
if ("REGISTER_DEVICE".equals(messageType)) {
final ResponseMessage responseMessage = (ResponseMessage) dataObject;
this.protocolResponseService.send(responseMessage, messageType, protocolInfo, MessageMetadata.fromMessage(message));
} else {
throw new OsgpCoreException("Unknown JMSType: " + messageType);
}
} catch (final JMSException e) {
LOGGER.error("Exception: {}, StackTrace: {}", e.getMessage(), e.getStackTrace(), e);
} catch (final OsgpCoreException e) {
LOGGER.error("OsgpCoreException", e);
}
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class DeviceRequestMessageService method processMessage.
public void processMessage(final ProtocolRequestMessage message) throws FunctionalException {
try {
final Device device = this.domainHelperService.findDevice(message.getDeviceIdentification());
final ProtocolInfo protocolInfo;
if (device.getGatewayDevice() == null) {
protocolInfo = device.getProtocolInfo();
} else {
protocolInfo = device.getGatewayDevice().getProtocolInfo();
}
if (protocolInfo == null || !this.protocolRequestService.isSupported(protocolInfo)) {
if (protocolInfo == null) {
LOGGER.error("Protocol unknown for device [{}]", device.getDeviceIdentification());
} else {
LOGGER.error("Protocol [{}] with version [{}] unknown for device [{}], needs to be reloaded.", protocolInfo.getProtocol(), protocolInfo.getProtocolVersion(), device.getDeviceIdentification());
}
throw new FunctionalException(FunctionalExceptionType.PROTOCOL_UNKNOWN_FOR_DEVICE, ComponentType.OSGP_CORE);
}
LOGGER.info("Device is using protocol [{}] with version [{}]", protocolInfo.getProtocol(), protocolInfo.getProtocolVersion());
final Organisation organisation = this.domainHelperService.findOrganisation(message.getOrganisationIdentification());
this.domainHelperService.isAllowed(organisation, device, Enum.valueOf(DeviceFunction.class, message.getMessageType()));
this.protocolRequestService.send(message, protocolInfo);
} catch (final FunctionalException e) {
this.domainResponseMessageSender.send(message, e);
throw e;
}
}
Aggregations