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