Search in sources :

Example 1 with EventMessagesResponse

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();
}
Also used : EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) Test(org.junit.jupiter.api.Test)

Example 2 with EventMessagesResponse

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;
}
Also used : Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) ArrayList(java.util.ArrayList) Event(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)

Example 3 with EventMessagesResponse

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());
}
Also used : EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 4 with EventMessagesResponse

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();
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) Test(org.junit.jupiter.api.Test)

Example 5 with EventMessagesResponse

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());
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) EventMessagesResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

EventMessagesResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.EventMessagesResponse)5 Test (org.junit.jupiter.api.Test)3 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)3 ArrayList (java.util.ArrayList)2 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)2 Serializable (java.io.Serializable)1 DateTime (org.joda.time.DateTime)1 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 Event (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.Event)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1