use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse in project open-smart-grid-platform by OSGP.
the class EventMessageDataContainerMappingTest method testWithNullList.
// Test if mapping with a null List succeeds
@Test
public void testWithNullList() {
// build test data
final EventMessageDataResponseDto containerDto = new EventMessageDataResponseDto(null);
// actual mapping
final EventMessagesResponse container = this.managementMapper.map(containerDto, EventMessagesResponse.class);
// test mapping
assertThat(container).isNotNull();
assertThat(container.getEvents()).isNull();
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse in project open-smart-grid-platform by OSGP.
the class ManagementService method findEventsByCorrelationUid.
public List<Event> findEventsByCorrelationUid(final String organisationIdentification, final String correlationUid) throws OsgpException {
log.info("findEventsByCorrelationUid called with organisation {}}", organisationIdentification);
this.domainHelperService.findOrganisation(organisationIdentification);
final ResponseData responseData = this.responseDataRepository.findByCorrelationUid(correlationUid);
final List<Event> events = new ArrayList<>();
final Serializable messageData = responseData.getMessageData();
if (messageData instanceof EventMessagesResponse) {
events.addAll(((EventMessagesResponse) messageData).getEvents());
log.info("deleting ResponseData for correlation uid {}.", correlationUid);
this.responseDataRepository.delete(responseData);
} else {
/**
* If the returned data is not an EventMessageContainer but a String, there has been an
* exception. The exception message has been put in the messageData.
*
* <p>As there is no way of knowing what the type of the exception was (because it is passed
* as a String) it is thrown as a TechnicalException because the user is most probably not to
* blame for the exception.
*/
if (messageData instanceof String) {
throw new TechnicalException(ComponentType.UNKNOWN, (String) messageData);
}
log.info("findEventsByCorrelationUid found other type of meter response data: {} for correlation UID: {}", messageData.getClass().getName(), correlationUid);
}
log.info("returning a list containing {} events", events.size());
return events;
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse in project open-smart-grid-platform by OSGP.
the class ManagementService method handleFindEventsResponse.
public void handleFindEventsResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType resultType, final OsgpException osgpException, final EventMessageDataResponseDto eventMessageDataContainerDto) throws FunctionalException {
this.eventService.enrichEvents(messageMetadata, eventMessageDataContainerDto);
final EventMessagesResponse eventMessageDataContainer = this.managementMapper.map(eventMessageDataContainerDto, EventMessagesResponse.class);
// Send the response containing the events to the webservice-adapter
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(resultType).withOsgpException(osgpException).withDataObject(eventMessageDataContainer).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse in project open-smart-grid-platform by OSGP.
the class EventMessageDataContainerMappingTest method testWithEmptyList.
// Test if mapping with an empty list succeeds
@Test
public void testWithEmptyList() {
// build test data
final EventMessageDataResponseDto containerDto = new EventMessageDataResponseDto(new ArrayList<EventDto>());
// actual mapping
final EventMessagesResponse container = this.managementMapper.map(containerDto, EventMessagesResponse.class);
// test mapping
assertThat(container).isNotNull();
assertThat(container.getEvents()).isNotNull();
assertThat(container.getEvents()).isEmpty();
}
use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse in project open-smart-grid-platform by OSGP.
the class EventMessageDataContainerMappingTest method testWithFilledList.
// Test if mapping with a filled List succeeds
@Test
public void testWithFilledList() {
// build test data
final EventDto event = new EventDto(new DateTime(), new Integer(1), new Integer(2), "STANDARD_EVENT_LOG");
event.setEventTypeDto(EventTypeDto.POWER_FAILURE);
final ArrayList<EventDto> events = new ArrayList<>();
events.add(event);
final EventMessageDataResponseDto containerDto = new EventMessageDataResponseDto(events);
// actual mapping
final EventMessagesResponse container = this.managementMapper.map(containerDto, EventMessagesResponse.class);
// test mapping
assertThat(container).isNotNull();
assertThat(container.getEvents()).isNotNull();
assertThat(container.getEvents().get(0).getTimestamp()).isEqualTo(containerDto.getEvents().get(0).getTimestamp());
assertThat(container.getEvents().get(0).getEventCode()).isEqualTo(containerDto.getEvents().get(0).getEventCode());
assertThat(container.getEvents().get(0).getEventType().name()).isEqualTo(containerDto.getEvents().get(0).getEventTypeDto().name());
assertThat(container.getEvents().get(0).getEventCounter()).isEqualTo(containerDto.getEvents().get(0).getEventCounter());
}
Aggregations