use of eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder 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;
}
Aggregations