Search in sources :

Example 16 with ServiceException

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

the class ActivityServiceBean method separateSingleVsMultipleFilters.

// Improve this part later on
private void separateSingleVsMultipleFilters(FishingActivityQuery query) throws ServiceException {
    Map<SearchFilter, List<String>> searchMapWithMultipleValues = query.getSearchCriteriaMapMultipleValues();
    if (searchMapWithMultipleValues == null || searchMapWithMultipleValues.size() == 0 || searchMapWithMultipleValues.get(SearchFilter.PURPOSE) == null)
        throw new ServiceException("No purpose code provided for the Fishing activity filters! At least one needed!");
    Map<SearchFilter, String> searchMap = query.getSearchCriteriaMap();
    if (searchMap == null)
        return;
    validateInputFilters(searchMapWithMultipleValues);
    Set<SearchFilter> filtersWhichSupportMultipleValues = FilterMap.getFiltersWhichSupportMultipleValues();
    Iterator<Map.Entry<SearchFilter, String>> searchMapIterator = searchMap.entrySet().iterator();
    while (searchMapIterator.hasNext()) {
        Map.Entry<SearchFilter, String> e = searchMapIterator.next();
        SearchFilter key = e.getKey();
        String value = e.getValue();
        if (value == null)
            throw new ServiceException("Null value present for the key:" + key + " Please provide correct input.");
        if (filtersWhichSupportMultipleValues.contains(key)) {
            List<String> values = new ArrayList<>();
            values.add(value);
            searchMapWithMultipleValues.put(key, values);
            searchMapIterator.remove();
        }
    }
    query.setSearchCriteriaMapMultipleValues(searchMapWithMultipleValues);
    query.setSearchCriteriaMap(searchMap);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) FaIdsListWithTripIdMap(eu.europa.ec.fisheries.uvms.activity.model.schemas.FaIdsListWithTripIdMap) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap)

Example 17 with ServiceException

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

the class ActivityServiceBean method validateInputFilters.

private void validateInputFilters(Map<SearchFilter, List<String>> searchMapWithMultipleValues) throws ServiceException {
    if (MapUtils.isNotEmpty(searchMapWithMultipleValues)) {
        Iterator<Map.Entry<SearchFilter, List<String>>> searchMapIterator = searchMapWithMultipleValues.entrySet().iterator();
        while (searchMapIterator.hasNext()) {
            Map.Entry<SearchFilter, List<String>> e = searchMapIterator.next();
            SearchFilter key = e.getKey();
            List<String> values = e.getValue();
            if (values.contains(null) || values.contains("")) {
                throw new ServiceException("Null value present for the key:" + key + " Please provide correct input.");
            }
        }
    }
}
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) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) FaIdsListWithTripIdMap(eu.europa.ec.fisheries.uvms.activity.model.schemas.FaIdsListWithTripIdMap) FilterMap(eu.europa.ec.fisheries.ers.service.search.FilterMap)

Example 18 with ServiceException

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

the class FACatchSummaryHelper method mapObjectArrayToFaCatchSummaryCustomEntity.

/**
 * This method maps raw data fetched from database to customEntity.
 * @param catchSummaryArr
 * @param groupList
 * @param isLanding
 * @return
 * @throws ServiceException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public FaCatchSummaryCustomProxy mapObjectArrayToFaCatchSummaryCustomEntity(Object[] catchSummaryArr, List<GroupCriteria> groupList, boolean isLanding) throws ServiceException {
    if (ArrayUtils.isEmpty(catchSummaryArr))
        return new FaCatchSummaryCustomProxy();
    int objectArrSize = catchSummaryArr.length - 1;
    if (// do not include count field from object array
    objectArrSize != groupList.size())
        throw new ServiceException("selected number of SQL fields do not match with grouping criterias asked by user ");
    Class cls = null;
    try {
        cls = Class.forName(faCatchSummaryCustomClassName);
        Object faCatchSummaryCustomEntityObj = cls.newInstance();
        Class parameterType = String.class;
        Map<GroupCriteria, GroupCriteriaMapper> groupMappings = FilterMap.getGroupByMapping();
        for (int i = 0; i < objectArrSize; i++) {
            GroupCriteria criteria = groupList.get(i);
            Object value = catchSummaryArr[i];
            if (value == null) {
                continue;
            }
            if (GroupCriteria.DATE_DAY.equals(criteria) || GroupCriteria.DATE_MONTH.equals(criteria) || GroupCriteria.DATE_YEAR.equals(criteria) || GroupCriteria.DATE.equals(criteria)) {
                value = extractValueFromDate((Date) value, criteria);
            }
            GroupCriteriaMapper mapper = groupMappings.get(criteria);
            Method method = cls.getDeclaredMethod(mapper.getMethodName(), parameterType);
            method.invoke(faCatchSummaryCustomEntityObj, value);
        }
        Method method = cls.getDeclaredMethod("setCount", Double.TYPE);
        method.invoke(faCatchSummaryCustomEntityObj, catchSummaryArr[objectArrSize]);
        if (isLanding)
            return (FaCatchSummaryCustomChildProxy) faCatchSummaryCustomEntityObj;
        else
            return (FaCatchSummaryCustomProxy) faCatchSummaryCustomEntityObj;
    } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        log.debug("Error while trying to map FaCatchSummaryCustomProxy. ", e);
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)

Example 19 with ServiceException

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

the class FishingActivityRequestMapper method extractFiltersAsMap.

/**
 * Some search Filters expect only single value. Others support multiple values for search.
 * This method sorts Filter list and separates filters with single values and return the map with its value.
 * @param filterTypes
 * @return Map<SearchFilter,String> Map of SearchFilter and its value
 * @throws ServiceException
 */
private static Map<SearchFilter, String> extractFiltersAsMap(List<SingleValueTypeFilter> filterTypes) throws ServiceException {
    Set<SearchFilter> filtersWithMultipleValues = FilterMap.getFiltersWhichSupportMultipleValues();
    Map<SearchFilter, String> searchMap = new EnumMap<>(SearchFilter.class);
    for (SingleValueTypeFilter filterType : filterTypes) {
        SearchFilter filter = filterType.getKey();
        if (filtersWithMultipleValues.contains(filter)) {
            throw new ServiceException("Filter provided with Single Value. Application Expects values as List for the Filter :" + filter);
        }
        searchMap.put(filterType.getKey(), filterType.getValue());
    }
    return searchMap;
}
Also used : SingleValueTypeFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SingleValueTypeFilter) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) EnumMap(java.util.EnumMap)

Example 20 with ServiceException

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

the class SearchQueryBuilder method createSortPartForQuery.

/**
 * Create sorting part for the Query
 * @param sql
 * @param query
 * @return
 * @throws ServiceException
 */
public StringBuilder createSortPartForQuery(StringBuilder sql, FishingActivityQuery query) throws ServiceException {
    LOG.debug("Create Sorting part of Query");
    SortKey sort = query.getSorting();
    if (sort != null && sort.getSortBy() != null) {
        SearchFilter field = sort.getSortBy();
        // if (SearchFilter.PERIOD_START.equals(field) || SearchFilter.PERIOD_END.equals(field)) {
        if (SearchFilter.PERIOD_END.equals(field)) {
            getSqlForStartAndEndDateSorting(sql, field, query);
        }
        String orderby = " ASC ";
        if (sort.isReversed()) {
            orderby = " DESC ";
        }
        String sortFieldMapping = FilterMap.getFilterSortMappings().get(field);
        if (sortFieldMapping == null) {
            throw new ServiceException("Information about which database field to be used for sorting is unavailable");
        }
        sql.append(" order by ").append(sortFieldMapping).append(orderby);
    } else {
        sql.append(" order by fa.acceptedDatetime ASC ");
    }
    // LOG.debug("Generated Query After Sort :" + sql);
    return sql;
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) SortKey(eu.europa.ec.fisheries.ers.service.search.SortKey) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)

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