Search in sources :

Example 1 with FACatchSearchBuilder

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

Aggregations

FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)1 FACatchSummaryHelper (eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper)1 FACatchSearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder)1 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)1 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)1 ArrayList (java.util.ArrayList)1