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;
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations