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")));
}
}
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));
}
Aggregations