Search in sources :

Example 31 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class FluxMessageServiceBean method interpolatePointFromMovements.

private Geometry interpolatePointFromMovements(List<MovementType> movements, Date activityDate) throws ServiceException {
    if (movements == null || movements.isEmpty()) {
        return null;
    }
    Geometry faReportGeom;
    Collections.sort(movements, new MovementTypeComparator());
    Map<String, MovementType> movementTypeMap = getPreviousAndNextMovement(movements, activityDate);
    MovementType nextMovement = movementTypeMap.get(NEXT);
    MovementType previousMovement = movementTypeMap.get(PREVIOUS);
    try {
        if (previousMovement == null && nextMovement == null) {
            faReportGeom = null;
        } else if (nextMovement == null) {
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else if (previousMovement == null) {
            faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
            faReportGeom.setSRID(dialect.defaultSRID());
        } else {
            faReportGeom = calculateIntermediatePoint(previousMovement, nextMovement, activityDate);
        }
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
    return faReportGeom;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MovementTypeComparator(eu.europa.ec.fisheries.ers.fa.utils.MovementTypeComparator) ParseException(com.vividsolutions.jts.io.ParseException) MovementType(eu.europa.ec.fisheries.schema.movement.v1.MovementType)

Example 32 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class SpatialModuleServiceBean method getGeometryForPortCode.

@Override
public String getGeometryForPortCode(String portCode) throws ServiceException {
    log.info("Inside getGeometryForPortCode :" + portCode);
    try {
        String request = SpatialModuleRequestMapper.mapToGeometryByPortCodeRequest(portCode);
        String correlationId = spatialProducer.sendModuleMessage(request, activityConsumer.getDestination());
        TextMessage message = activityConsumer.getMessage(correlationId, TextMessage.class);
        if (message != null && !isUserFault(message)) {
            GeometryByPortCodeResponse response = SpatialModuleResponseMapper.mapGeometryByPortCodeResponseToString(message, correlationId);
            return response.getPortGeometry();
        } else {
            throw new ServiceException("FAILED TO GET GEOMETRY FROM SPATIAL");
        }
    } catch (ServiceException | MessageException | SpatialModelMapperException e) {
        log.error("Exception in communication with spatial while retrieving GEOMETRY", e);
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) GeometryByPortCodeResponse(eu.europa.ec.fisheries.uvms.spatial.model.schemas.GeometryByPortCodeResponse) TextMessage(javax.jms.TextMessage) SpatialModelMapperException(eu.europa.ec.fisheries.uvms.spatial.model.exception.SpatialModelMapperException)

Example 33 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityEventServiceBean method getFishingActivityMessage.

@Override
public void getFishingActivityMessage(@Observes @ReceiveFishingActivityRequestEvent EventMessage eventMessage) {
    log.info(GOT_JMS_INSIDE_ACTIVITY_TO_GET + "SetFLUXFAReportOrQueryMessageRequest");
    try {
        TextMessage jmsMessage = eventMessage.getJmsMessage();
        SetFLUXFAReportOrQueryMessageRequest request = JAXBMarshaller.unmarshallTextMessage(jmsMessage, SetFLUXFAReportOrQueryMessageRequest.class);
        log.info("SetFLUXFAReportOrQueryMessageRequest unmarshalled");
        if (request == null) {
            log.error("Unmarshalled SetFLUXFAReportOrQueryMessageRequest is null. Something went wrong during jms comm?!");
            return;
        }
        switch(eventMessage.getMethod()) {
            case GET_FLUX_FA_REPORT:
                FLUXFAReportMessage fluxFAReportMessage = JAXBMarshaller.unmarshallTextMessage(request.getRequest(), FLUXFAReportMessage.class);
                deleteDuplicatedReportsFromXMLDocument(fluxFAReportMessage);
                if (CollectionUtils.isNotEmpty(fluxFAReportMessage.getFAReportDocuments())) {
                    fluxMessageService.saveFishingActivityReportDocuments(fluxFAReportMessage, extractPluginType(request.getPluginType()));
                } else {
                    log.error("[ERROR] After checking faReportDocuments IDs, all of them exist already in Activity DB.. So nothing will be saved!!");
                }
                break;
            case GET_FLUX_FA_QUERY:
                log.error("TODO : FAQUERY mappers NOT implemented yet....");
                FLUXFAQueryMessage fluxFAQueryMessage = JAXBMarshaller.unmarshallTextMessage(request.getRequest(), FLUXFAQueryMessage.class);
                // TODO : Implement me... Map tp real HQl/SQL query and run the query and map the results to FLUXFAReportMessage and send it to
                FLUXFAReportMessage faRepQueryResponseAfterMapping = new FLUXFAReportMessage();
                activityRulesModuleServiceBean.sendSyncAsyncFaReportToRules(faRepQueryResponseAfterMapping, "getTheOnValueFromSomewahre", request.getRequestType(), jmsMessage.getJMSMessageID());
                break;
        }
    } catch (ActivityModelMarshallException | ServiceException | ActivityModuleException | JMSException e) {
        sendError(eventMessage, e);
    }
}
Also used : SetFLUXFAReportOrQueryMessageRequest(eu.europa.ec.fisheries.uvms.activity.model.schemas.SetFLUXFAReportOrQueryMessageRequest) ActivityModelMarshallException(eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FLUXFAReportMessage(un.unece.uncefact.data.standard.fluxfareportmessage._3.FLUXFAReportMessage) FLUXFAQueryMessage(un.unece.uncefact.data.standard.fluxfaquerymessage._3.FLUXFAQueryMessage) JMSException(javax.jms.JMSException) ActivityModuleException(eu.europa.ec.fisheries.ers.service.exception.ActivityModuleException) TextMessage(javax.jms.TextMessage)

Example 34 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBean method getFishingActivityForView.

/**
 * Gets a FishingActivityEntity with a certain activityId and maps it to a FishingActivityViewDTO representation layer POJO.
 *
 * @param activityId
 * @param datasets
 * @return
 * @throws ServiceException
 */
@Override
public FishingActivityViewDTO getFishingActivityForView(Integer activityId, String tripId, List<Dataset> datasets, ActivityViewEnum view) throws ServiceException {
    Geometry geom = getRestrictedAreaGeometry(datasets);
    FishingActivityEntity activityEntity = fishingActivityDao.getFishingActivityById(activityId, geom);
    if (activityEntity == null)
        throw new ServiceException("Could not find FishingActivityEntity for the given id:" + activityId);
    log.debug("FishingActivityEntity fetched from database with id:" + activityEntity.getId());
    FishingActivityViewDTO fishingActivityViewDTO = ActivityViewMapperFactory.getMapperForView(view).mapFaEntityToFaDto(activityEntity);
    fishingActivityViewDTO.setTripDetails(fishingTripServiceBean.getTripWidgetDto(activityEntity, tripId));
    log.debug("fishingActivityView generated after mapping is :" + fishingActivityViewDTO);
    addPortDescriptions(fishingActivityViewDTO, "LOCATION");
    fishingActivityViewDTO.setTripDetails(fishingTripServiceBean.getTripWidgetDto(activityEntity, tripId));
    fishingActivityViewDTO.setHistory(getActivityHistoryDto(activityEntity));
    log.debug("fishingActivityView generated after mapping is :" + fishingActivityViewDTO);
    return fishingActivityViewDTO;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FishingActivityViewDTO(eu.europa.ec.fisheries.ers.service.dto.view.parent.FishingActivityViewDTO) FishingActivityEntity(eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)

Example 35 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBean method getRestrictedAreaGeometry.

private Geometry getRestrictedAreaGeometry(List<Dataset> datasets) throws ServiceException {
    if (datasets == null || datasets.isEmpty()) {
        return null;
    }
    try {
        List<AreaIdentifierType> areaIdentifierTypes = UsmUtils.convertDataSetToAreaId(datasets);
        String areaWkt = spatialModule.getFilteredAreaGeom(areaIdentifierTypes);
        Geometry geometry = GeometryMapper.INSTANCE.wktToGeometry(areaWkt).getValue();
        geometry.setSRID(GeometryUtils.DEFAULT_EPSG_SRID);
        return geometry;
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ParseException(com.vividsolutions.jts.io.ParseException) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)

Aggregations

ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)42 ArrayList (java.util.ArrayList)11 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)9 Geometry (com.vividsolutions.jts.geom.Geometry)8 ParseException (com.vividsolutions.jts.io.ParseException)7 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)7 TextMessage (javax.jms.TextMessage)7 List (java.util.List)6 ActivityModelMarshallException (eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException)5 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)5 JMSException (javax.jms.JMSException)5 FilterMap (eu.europa.ec.fisheries.ers.service.search.FilterMap)4 Map (java.util.Map)4 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)3 VesselTransportMeansEntity (eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity)3 GroupCriteriaMapper (eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)3 AssetModelMapperException (eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException)3 AreaIdentifierType (eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)3 EnumMap (java.util.EnumMap)3 NotNull (org.jetbrains.annotations.NotNull)3