Search in sources :

Example 6 with ServiceException

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

the class FishingTripServiceBean method getRestrictedAreaGeom.

private Geometry getRestrictedAreaGeom(List<Dataset> datasets) throws ServiceException {
    if (CollectionUtils.isEmpty(datasets)) {
        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 : FishingTripIdWithGeometry(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry) 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)

Example 7 with ServiceException

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

the class FluxMessageServiceBean method saveFishingActivityReportDocuments.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(Transactional.TxType.REQUIRED)
public void saveFishingActivityReportDocuments(FLUXFAReportMessage faReportMessage, FaReportSourceEnum faReportSourceEnum) throws ServiceException {
    log.info("[INFO] Going to save [ " + faReportMessage.getFAReportDocuments().size() + " ] FaReportDocuments..");
    FluxFaReportMessageEntity messageEntity = new FluxFaReportMessageMapper().mapToFluxFaReportMessage(faReportMessage, faReportSourceEnum, new FluxFaReportMessageEntity());
    final Set<FaReportDocumentEntity> faReportDocuments = messageEntity.getFaReportDocuments();
    for (FaReportDocumentEntity faReportDocument : faReportDocuments) {
        try {
            updateGeometry(faReportDocument);
            enrichFishingActivityWithGuiID(faReportDocument);
        } catch (Exception e) {
            log.error("Could not update Geometry OR enrichActivities for faReportDocument:" + faReportDocument.getId());
        }
    }
    log.debug("fishing activity records to be saved : " + faReportDocuments.size());
    fluxReportMessageDao.saveFluxFaReportMessage(messageEntity);
    log.debug("Save partial FluxFaReportMessage before further processing");
    updateFaReportCorrections(faReportMessage.getFAReportDocuments());
    log.debug("Update FaReport Corrections is complete.");
    updateFishingTripStartAndEndDate(faReportDocuments);
    log.info("FluxFaReportMessage Saved successfully.");
}
Also used : FaReportDocumentEntity(eu.europa.ec.fisheries.ers.fa.entities.FaReportDocumentEntity) FluxFaReportMessageMapper(eu.europa.ec.fisheries.ers.service.mapper.FluxFaReportMessageMapper) FluxFaReportMessageEntity(eu.europa.ec.fisheries.ers.fa.entities.FluxFaReportMessageEntity) ParseException(com.vividsolutions.jts.io.ParseException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) Transactional(javax.transaction.Transactional)

Example 8 with ServiceException

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

the class FluxMessageServiceBean method getGeometryFromMdr.

/**
 * Find geometry for fluxLocation code in MDR
 * @param fluxLocationIdentifier
 * @return
 */
private Geometry getGeometryFromMdr(String fluxLocationIdentifier) {
    log.debug("Get Geometry from MDR for:" + fluxLocationIdentifier);
    if (fluxLocationIdentifier == null) {
        return null;
    }
    Geometry geometry = null;
    final List<String> columnsList = new ArrayList<>(Collections.singletonList("code"));
    try {
        Map<String, List<String>> portValuesFromMdr = mdrModuleServiceBean.getAcronymFromMdr("LOCATION", fluxLocationIdentifier, columnsList, 1, "latitude", "longitude");
        List<String> latitudeValues = portValuesFromMdr.get("latitude");
        List<String> longitudeValues = portValuesFromMdr.get("longitude");
        Double latitude = null;
        Double longitude = null;
        if (CollectionUtils.isNotEmpty(latitudeValues)) {
            String latitudeStr = latitudeValues.get(0);
            if (latitudeStr != null) {
                latitude = Double.parseDouble(latitudeStr);
            }
        }
        if (CollectionUtils.isNotEmpty(longitudeValues)) {
            String longitudeStr = longitudeValues.get(0);
            if (longitudeStr != null) {
                longitude = Double.parseDouble(longitudeStr);
            }
        }
        geometry = GeometryUtils.createPoint(longitude, latitude);
    } catch (ServiceException e) {
        log.error("Error while retriving values from MDR.", e);
    }
    return geometry;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with ServiceException

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

the class FluxMessageServiceBean method getGeometryFromSpatial.

/**
 * Get Geometry information from spatial for FLUXLocation code
 * @param fluxLocationIdentifier
 * @return
 */
private Geometry getGeometryFromSpatial(String fluxLocationIdentifier) {
    log.info("Get Geometry from Spatial for:" + fluxLocationIdentifier);
    if (fluxLocationIdentifier == null) {
        return null;
    }
    Geometry geometry = null;
    try {
        String geometryWkt = spatialModuleService.getGeometryForPortCode(fluxLocationIdentifier);
        if (geometryWkt != null) {
            Geometry value = GeometryMapper.INSTANCE.wktToGeometry(geometryWkt).getValue();
            Coordinate[] coordinates = value.getCoordinates();
            if (coordinates.length > 0) {
                Coordinate coordinate = coordinates[0];
                double x = coordinate.x;
                double y = coordinate.y;
                geometry = GeometryUtils.createPoint(x, y);
            }
        }
        log.debug(" Geometry received from Spatial for:" + fluxLocationIdentifier + "  :" + geometryWkt);
    } catch (ServiceException | ParseException e) {
        log.error("Exception while trying to get geometry from spatial", e);
    }
    return geometry;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) Coordinate(com.vividsolutions.jts.geom.Coordinate) ParseException(com.vividsolutions.jts.io.ParseException)

Example 10 with ServiceException

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

the class MdrModuleServiceBean method getAcronymFromMdr.

@Override
public Map<String, List<String>> getAcronymFromMdr(String acronym, String filter, List<String> filterColumns, Integer nrOfResults, String... returnColumns) throws ServiceException {
    Map<String, List<String>> columnNameValuesMap = prepareColumnNameValuesMap(returnColumns);
    try {
        String request = MdrModuleMapper.createFluxMdrGetCodeListRequest(acronym, filter, filterColumns, nrOfResults);
        String correlationId = mdrProducer.sendModuleMessage(request, activityConsumer.getDestination());
        TextMessage message = activityConsumer.getMessage(correlationId, TextMessage.class);
        if (null != message) {
            String messageStr = message.getText();
            MdrGetCodeListResponse response = JAXBMarshaller.unmarshallTextMessage(messageStr, MdrGetCodeListResponse.class);
            for (ObjectRepresentation objectRep : response.getDataSets()) {
                for (ColumnDataType nameVal : objectRep.getFields()) {
                    if (columnNameValuesMap.containsKey(nameVal.getColumnName())) {
                        columnNameValuesMap.get(nameVal.getColumnName()).add(nameVal.getColumnValue());
                    }
                }
            }
            return columnNameValuesMap;
        } else {
            throw new ServiceException("Unable to get data from MDR Module");
        }
    } catch (JMSException | MessageException | MdrModelMarshallException | ActivityModelMarshallException e) {
        log.error("MdrModelMarshallException in communication with mdr", e.getCause());
        throw new ServiceException("Exception caught in mdrModuleServiceBean", e.getCause());
    }
}
Also used : MdrModelMarshallException(eu.europa.ec.fisheries.uvms.mdr.model.exception.MdrModelMarshallException) ColumnDataType(un.unece.uncefact.data.standard.mdr.communication.ColumnDataType) JMSException(javax.jms.JMSException) ActivityModelMarshallException(eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MdrGetCodeListResponse(un.unece.uncefact.data.standard.mdr.communication.MdrGetCodeListResponse) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) ArrayList(java.util.ArrayList) List(java.util.List) TextMessage(javax.jms.TextMessage) ObjectRepresentation(un.unece.uncefact.data.standard.mdr.communication.ObjectRepresentation)

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