Search in sources :

Example 1 with MovementMapResponseType

use of eu.europa.ec.fisheries.schema.movement.search.v1.MovementMapResponseType in project UVMS-ActivityModule-APP by UnionVMS.

the class MovementModuleServiceBean method getMovement.

/**
 * {@inheritDoc}
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<MovementType> getMovement(List<String> vesselIds, Date startDate, Date endDate) throws ServiceException {
    try {
        MovementQuery movementQuery = new MovementQuery();
        addListCriteria(vesselIds, movementQuery);
        addRangeCriteria(startDate, endDate, movementQuery);
        movementQuery.setExcludeFirstAndLastSegment(true);
        String request = MovementModuleRequestMapper.mapToGetMovementMapByQueryRequest(movementQuery);
        String moduleMessage = movementProducer.sendModuleMessage(request, activityConsumer.getDestination());
        TextMessage response = activityConsumer.getMessage(moduleMessage, TextMessage.class);
        if (response != null && !isUserFault(response)) {
            List<MovementMapResponseType> mapResponseTypes = MovementModuleResponseMapper.mapToMovementMapResponse(response);
            List<MovementType> movements = new ArrayList<>();
            for (MovementMapResponseType movementMap : mapResponseTypes) {
                movements.addAll(movementMap.getMovements());
            }
            return movements;
        } else {
            throw new ServiceException("FAILED TO GET DATA FROM MOVEMENT");
        }
    } catch (MovementDuplicateException | MovementFaultException | ServiceException | MessageException | JMSException | ModelMapperException e) {
        log.error("Exception in communication with movements", e);
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : MovementQuery(eu.europa.ec.fisheries.schema.movement.search.v1.MovementQuery) MovementFaultException(eu.europa.ec.fisheries.uvms.movement.model.exception.MovementFaultException) MovementDuplicateException(eu.europa.ec.fisheries.uvms.movement.model.exception.MovementDuplicateException) ArrayList(java.util.ArrayList) MovementMapResponseType(eu.europa.ec.fisheries.schema.movement.search.v1.MovementMapResponseType) JMSException(javax.jms.JMSException) MovementType(eu.europa.ec.fisheries.schema.movement.v1.MovementType) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) ModelMapperException(eu.europa.ec.fisheries.uvms.movement.model.exception.ModelMapperException) TextMessage(javax.jms.TextMessage) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

MovementMapResponseType (eu.europa.ec.fisheries.schema.movement.search.v1.MovementMapResponseType)1 MovementQuery (eu.europa.ec.fisheries.schema.movement.search.v1.MovementQuery)1 MovementType (eu.europa.ec.fisheries.schema.movement.v1.MovementType)1 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 ModelMapperException (eu.europa.ec.fisheries.uvms.movement.model.exception.ModelMapperException)1 MovementDuplicateException (eu.europa.ec.fisheries.uvms.movement.model.exception.MovementDuplicateException)1 MovementFaultException (eu.europa.ec.fisheries.uvms.movement.model.exception.MovementFaultException)1 ArrayList (java.util.ArrayList)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1