Search in sources :

Example 1 with AreaIdentifierType

use of eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType 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 2 with AreaIdentifierType

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

the class SpatialModuleServiceBean method getFilteredAreaGeom.

/**
 * {@inheritDoc}
 */
@Override
public String getFilteredAreaGeom(Collection<AreaIdentifierType> areaIdentifiers) throws ServiceException {
    try {
        String request = SpatialModuleRequestMapper.mapToFilterAreaSpatialRequest(new ArrayList<>(areaIdentifiers), new ArrayList<AreaIdentifierType>());
        String correlationId = spatialProducer.sendModuleMessage(request, activityConsumer.getDestination());
        TextMessage message = activityConsumer.getMessage(correlationId, TextMessage.class);
        if (message != null && !isUserFault(message)) {
            FilterAreasSpatialRS response = SpatialModuleResponseMapper.mapToFilterAreasSpatialRSFromResponse(message, correlationId);
            return response.getGeometry();
        } else {
            throw new ServiceException("FAILED TO GET DATA FROM SPATIAL");
        }
    } catch (ServiceException | MessageException | SpatialModelMapperException e) {
        log.error("Exception in communication with spatial while retrieving filtered area", e);
        throw new ServiceException(e.getMessage(), e);
    }
}
Also used : FilterAreasSpatialRS(eu.europa.ec.fisheries.uvms.spatial.model.schemas.FilterAreasSpatialRS) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType) TextMessage(javax.jms.TextMessage) SpatialModelMapperException(eu.europa.ec.fisheries.uvms.spatial.model.exception.SpatialModelMapperException)

Example 3 with AreaIdentifierType

use of eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType 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)

Example 4 with AreaIdentifierType

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

the class UsmUtils method convertDataSetToAreaId.

public static List<AreaIdentifierType> convertDataSetToAreaId(List<Dataset> datasets) throws ServiceException {
    List<AreaIdentifierType> areaRestrictions = new ArrayList<>(datasets.size());
    for (Dataset dataset : datasets) {
        int lastIndexDelimiter = dataset.getDiscriminator().lastIndexOf(USMSpatial.DELIMITER);
        if (lastIndexDelimiter > -1) {
            AreaIdentifierType areaIdentifierType = new AreaIdentifierType();
            AreaType areaType = AreaType.valueOf(dataset.getDiscriminator().substring(0, lastIndexDelimiter));
            String areaId = dataset.getDiscriminator().substring(lastIndexDelimiter + 1);
            if (areaType != null && StringUtils.isNotBlank(areaId)) {
                areaIdentifierType.setAreaType(areaType);
                areaIdentifierType.setId(areaId);
                areaRestrictions.add(areaIdentifierType);
            }
        }
    }
    return areaRestrictions;
}
Also used : Dataset(eu.europa.ec.fisheries.wsdl.user.types.Dataset) ArrayList(java.util.ArrayList) AreaType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaType) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)

Example 5 with AreaIdentifierType

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

the class ActivityServiceBeanTest method getFishingActivityListByQuery.

@Test
@SneakyThrows
public void getFishingActivityListByQuery() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    Map<SearchFilter, String> searchCriteriaMap = new HashMap<>();
    searchCriteriaMap.put(SearchFilter.OWNER, "OWNER1");
    List<AreaIdentifierType> areaIdentifierTypes = new ArrayList<>();
    Map<SearchFilter, List<String>> searchCriteriaMapMultipleValue = new HashMap<>();
    List<String> purposeCodeList = new ArrayList<>();
    purposeCodeList.add("9");
    searchCriteriaMapMultipleValue.put(SearchFilter.PURPOSE, purposeCodeList);
    PaginationDto pagination = new PaginationDto();
    pagination.setPageSize(4);
    pagination.setOffset(1);
    query.setPagination(pagination);
    query.setSearchCriteriaMap(searchCriteriaMap);
    query.setSearchCriteriaMapMultipleValues(searchCriteriaMapMultipleValue);
    when(spatialModule.getFilteredAreaGeom(areaIdentifierTypes)).thenReturn("('MULTIPOINT (10 40, 40 30, 20 20, 30 10)')");
    when(fishingActivityDao.getFishingActivityListByQuery(query)).thenReturn(MapperUtil.getFishingActivityEntityList());
    // Trigger
    FilterFishingActivityReportResultDTO filterFishingActivityReportResultDTO = activityService.getFishingActivityListByQuery(query, null);
    Mockito.verify(fishingActivityDao, Mockito.times(1)).getFishingActivityListByQuery(Mockito.any(FishingActivityQuery.class));
    // Verify
    assertNotNull(filterFishingActivityReportResultDTO);
    assertNotNull(filterFishingActivityReportResultDTO.getResultList());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) FilterFishingActivityReportResultDTO(eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) ArrayList(java.util.ArrayList) List(java.util.List) AreaIdentifierType(eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

AreaIdentifierType (eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)6 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)3 ArrayList (java.util.ArrayList)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 ParseException (com.vividsolutions.jts.io.ParseException)2 FilterFishingActivityReportResultDTO (eu.europa.ec.fisheries.ers.service.dto.FilterFishingActivityReportResultDTO)2 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)2 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)2 PaginationDto (eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto)2 Dataset (eu.europa.ec.fisheries.wsdl.user.types.Dataset)2 HashMap (java.util.HashMap)2 List (java.util.List)2 SneakyThrows (lombok.SneakyThrows)2 Test (org.junit.Test)2 FishingActivityEntity (eu.europa.ec.fisheries.ers.fa.entities.FishingActivityEntity)1 FishingTripIdWithGeometry (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripIdWithGeometry)1 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)1 SpatialModelMapperException (eu.europa.ec.fisheries.uvms.spatial.model.exception.SpatialModelMapperException)1 AreaType (eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaType)1 FilterAreasSpatialRS (eu.europa.ec.fisheries.uvms.spatial.model.schemas.FilterAreasSpatialRS)1