Search in sources :

Example 1 with ActivityModuleMethod

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityMessageConsumerBean method onMessage.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onMessage(Message message) {
    TextMessage textMessage = null;
    try {
        textMessage = (TextMessage) message;
        MappedDiagnosticContext.addMessagePropertiesToThreadMappedDiagnosticContext(textMessage);
        ActivityModuleRequest request;
        request = JAXBMarshaller.unmarshallTextMessage(textMessage, ActivityModuleRequest.class);
        LOG.debug("Message unmarshalled successfully in activity");
        if (request == null) {
            LOG.error("[ Request is null ]");
            return;
        }
        ActivityModuleMethod method = request.getMethod();
        if (method == null) {
            LOG.error("[ Request method is null ]");
            return;
        }
        switch(method) {
            case GET_FLUX_FA_REPORT:
            case GET_FLUX_FA_QUERY:
                receiveFishingActivityEvent.fire(new EventMessage(textMessage, method));
                break;
            case MAP_TO_SUBSCRIPTION_REQUEST:
                mapToSubscriptionRequest.fire(new EventMessage(textMessage));
                break;
            case GET_FISHING_TRIPS:
                getFishingTripListEvent.fire(new EventMessage(textMessage));
                break;
            case GET_FA_CATCH_SUMMARY_REPORT:
                getFACatchSummaryReportEvent.fire(new EventMessage(textMessage));
                break;
            case GET_NON_UNIQUE_IDS:
                getNonUniqueIdsRequest.fire(new EventMessage(textMessage));
                break;
            case GET_FISHING_ACTIVITY_FOR_TRIPS:
                getFishingActivityForTrips.fire(new EventMessage(textMessage));
                break;
            default:
                LOG.error("[ Request method {} is not implemented ]", method.name());
                errorEvent.fire(new EventMessage(textMessage, ActivityModuleResponseMapper.createFaultMessage(FaultCode.ACTIVITY_MESSAGE, "[ Request method " + method.name() + "  is not implemented ]")));
        }
    } catch (ActivityModelMarshallException | ClassCastException e) {
        LOG.error("[ Error when receiving message in activity: ] {}", e);
        errorEvent.fire(new EventMessage(textMessage, ActivityModuleResponseMapper.createFaultMessage(FaultCode.ACTIVITY_MESSAGE, "Error when receiving message")));
    }
}
Also used : ActivityModelMarshallException(eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException) ActivityModuleMethod(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod) EventMessage(eu.europa.ec.fisheries.uvms.activity.message.event.carrier.EventMessage) TextMessage(javax.jms.TextMessage) ActivityModuleRequest(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleRequest) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 2 with ActivityModuleMethod

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityMessageConsumerBeanTest method testOnMessageMethod.

@Test
@SneakyThrows
public void testOnMessageMethod() {
    mockStatic(MappedDiagnosticContext.class);
    PowerMockito.doNothing().when(MappedDiagnosticContext.class, "addMessagePropertiesToThreadMappedDiagnosticContext", Mockito.any(TextMessage.class));
    for (ActivityModuleMethod moduleMethod : ActivityModuleMethod.values()) {
        GetNonUniqueIdsRequest request = new GetNonUniqueIdsRequest();
        request.setMethod(moduleMethod);
        ActiveMQTextMessage textMessage = new ActiveMQTextMessage(session);
        final String strReq = JAXBMarshaller.marshallJaxBObjectToString(request);
        Whitebox.setInternalState(textMessage, "text", new SimpleString(strReq));
        consumer.onMessage(textMessage);
        PowerMockito.verifyStatic();
        MappedDiagnosticContext.addMessagePropertiesToThreadMappedDiagnosticContext(textMessage);
    }
    verify(mapToSubscriptionRequest, times(1)).fire(any(EventMessage.class));
    verify(receiveFishingActivityEvent, times(2)).fire(any(EventMessage.class));
    verify(getFishingTripListEvent, times(1)).fire(any(EventMessage.class));
    verify(getFACatchSummaryReportEvent, times(1)).fire(any(EventMessage.class));
    verify(getNonUniqueIdsRequest, times(1)).fire(any(EventMessage.class));
}
Also used : ActivityModuleMethod(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod) EventMessage(eu.europa.ec.fisheries.uvms.activity.message.event.carrier.EventMessage) GetNonUniqueIdsRequest(eu.europa.ec.fisheries.uvms.activity.model.schemas.GetNonUniqueIdsRequest) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

EventMessage (eu.europa.ec.fisheries.uvms.activity.message.event.carrier.EventMessage)2 ActivityModuleMethod (eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleMethod)2 TextMessage (javax.jms.TextMessage)2 ActivityModelMarshallException (eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException)1 ActivityModuleRequest (eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityModuleRequest)1 GetNonUniqueIdsRequest (eu.europa.ec.fisheries.uvms.activity.model.schemas.GetNonUniqueIdsRequest)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 SneakyThrows (lombok.SneakyThrows)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ActiveMQTextMessage (org.apache.activemq.artemis.jms.client.ActiveMQTextMessage)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1