Search in sources :

Example 21 with ServiceException

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

the class SearchQueryBuilder method applyValueDependingOnKey.

private void applyValueDependingOnKey(Map<SearchFilter, String> searchCriteriaMap, Query typedQuery, SearchFilter key, String value) throws ServiceException {
    switch(key) {
        case PERIOD_START:
            typedQuery.setParameter(queryParameterMappings.get(key), DateUtils.parseToUTCDate(value, DateUtils.DATE_TIME_UI_FORMAT));
            break;
        case PERIOD_END:
            typedQuery.setParameter(queryParameterMappings.get(key), DateUtils.parseToUTCDate(value, DateUtils.DATE_TIME_UI_FORMAT));
            break;
        case QUANTITY_MIN:
            typedQuery.setParameter(queryParameterMappings.get(key), SearchQueryBuilder.normalizeWeightValue(value, searchCriteriaMap.get(SearchFilter.WEIGHT_MEASURE)));
            break;
        case QUANTITY_MAX:
            typedQuery.setParameter(queryParameterMappings.get(key), SearchQueryBuilder.normalizeWeightValue(value, searchCriteriaMap.get(SearchFilter.WEIGHT_MEASURE)));
            break;
        case MASTER:
            typedQuery.setParameter(queryParameterMappings.get(key), value.toUpperCase());
            break;
        case FA_REPORT_ID:
            typedQuery.setParameter(queryParameterMappings.get(key), Integer.parseInt(value));
            break;
        case AREA_GEOM:
            Geometry geom;
            try {
                geom = GeometryMapper.INSTANCE.wktToGeometry(value).getValue();
                geom.setSRID(GeometryUtils.DEFAULT_EPSG_SRID);
            } catch (ParseException e) {
                throw new ServiceException(e.getMessage(), e);
            }
            typedQuery.setParameter(queryParameterMappings.get(key), geom);
            break;
        default:
            typedQuery.setParameter(queryParameterMappings.get(key), value);
            break;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ParseException(com.vividsolutions.jts.io.ParseException)

Example 22 with ServiceException

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

the class FACatchSearchBuilder method appendSelectGroupColumns.

@NotNull
protected void appendSelectGroupColumns(List<GroupCriteria> groupByFieldList, StringBuilder sql, Map<GroupCriteria, GroupCriteriaMapper> groupMAppings) throws ServiceException {
    if (groupByFieldList == null || Collections.isEmpty(groupByFieldList))
        throw new ServiceException(" No Group information present to aggregate report.");
    // Build SELECT part of query.
    for (GroupCriteria criteria : groupByFieldList) {
        GroupCriteriaMapper mapper = groupMAppings.get(criteria);
        sql.append(mapper.getColumnName());
        sql.append(", ");
    }
    sql.append(SUM_WEIGHT);
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with ServiceException

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

the class FACatchSearchBuilder_Landing method appendSelectGroupColumns.

@NotNull
protected void appendSelectGroupColumns(List<GroupCriteria> groupByFieldList, StringBuilder sql, Map<GroupCriteria, GroupCriteriaMapper> groupMAppings) throws ServiceException {
    if (groupByFieldList == null || Collections.isEmpty(groupByFieldList))
        throw new ServiceException(" No Group information present to aggregate report.");
    // Build SELECT part of query.
    for (GroupCriteria criteria : groupByFieldList) {
        GroupCriteriaMapper mapper = groupMAppings.get(criteria);
        sql.append(mapper.getColumnName());
        sql.append(", ");
    }
    sql.append(SUM_WEIGHT);
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with ServiceException

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

the class FaCatchDao method getRecordsForFishClassOrFACatchType.

/**
 * Get list of records from FACatch table grouped by certain aggregation criterias. Also, Activity Filtering will be applied before getting data
 * @param query
 * @return List<FaCatchSummaryCustomEntity> custom object represnting aggregation factors and its count
 * @throws ServiceException
 */
private List<FaCatchSummaryCustomProxy> getRecordsForFishClassOrFACatchType(FishingActivityQuery query, boolean isLanding) throws ServiceException {
    // create Query to get grouped data from FACatch table, also combine query to filter records as per filters provided by users
    FACatchSearchBuilder faCatchSearchBuilder = createBuilderForFACatch(isLanding);
    StringBuilder sql = faCatchSearchBuilder.createSQL(query);
    TypedQuery<Object[]> typedQuery = em.createQuery(sql.toString(), Object[].class);
    typedQuery = (TypedQuery<Object[]>) faCatchSearchBuilder.fillInValuesForTypedQuery(query, typedQuery);
    List<Object[]> list = typedQuery.getResultList();
    log.debug("size of records received from DB :" + list.size());
    // Map Raw data received from database to custom entity which will help identifing correct groups
    List<FaCatchSummaryCustomProxy> customEntities = new ArrayList<>();
    FACatchSummaryHelper faCatchSummaryHelper = isLanding ? FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.PRESENTATION) : FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.STANDARD);
    List<GroupCriteria> groupCriterias = query.getGroupByFields();
    for (Object[] objArr : list) {
        try {
            FaCatchSummaryCustomProxy entity = faCatchSummaryHelper.mapObjectArrayToFaCatchSummaryCustomEntity(objArr, groupCriterias, isLanding);
            if (entity != null) {
                customEntities.add(entity);
            }
        } catch (Exception e) {
            log.error("Could not map sql selection to FaCatchSummaryCustomProxy object", e);
        }
    }
    return customEntities;
}
Also used : FACatchSearchBuilder(eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder) FACatchSummaryHelper(eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper) ArrayList(java.util.ArrayList) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)

Example 25 with ServiceException

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

the class FishingActivityRequestMapper method extractFiltersAsMapWithMultipleValues.

/**
 * This method sorts incoming list and separates Filters with multiple values and put it into Map.
 * @param filterTypes List of searchFilters
 * @return Map<SearchFilter,List<String>> Map of SearchFilter and list of values for the filter
 * @throws ServiceException
 */
private static Map<SearchFilter, List<String>> extractFiltersAsMapWithMultipleValues(List<ListValueTypeFilter> filterTypes) throws ServiceException {
    Set<SearchFilter> filtersWithMultipleValues = FilterMap.getFiltersWhichSupportMultipleValues();
    Map<SearchFilter, List<String>> searchMap = new EnumMap<>(SearchFilter.class);
    for (ListValueTypeFilter filterType : filterTypes) {
        SearchFilter filter = filterType.getKey();
        if (!filtersWithMultipleValues.contains(filter)) {
            throw new ServiceException("Filter provided with multiple Values do not support Multiple Values. Filter name is:" + filter);
        }
        searchMap.put(filterType.getKey(), filterType.getValues());
    }
    return searchMap;
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) List(java.util.List) EnumMap(java.util.EnumMap) ListValueTypeFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.ListValueTypeFilter)

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