Search in sources :

Example 1 with FACatchSummaryHelper

use of eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchReportServiceBean method getFACatchSummaryReportResponse.

/**
 * This method is used to create Catch Details page from Run Report.
 * So, To display summary  of catches, we need to consider all fishing Activity filters as well as aggregation factors specified by user .
 * Aggregation factors could be dynamically selected by user like veesel,period,area etc.
 * @param query
 * @return
 * @throws ServiceException
 */
@Override
public FACatchSummaryReportResponse getFACatchSummaryReportResponse(FishingActivityQuery query) throws ServiceException {
    log.debug("FACatchSummaryReportResponse creation starts");
    // get processed information in the form of DTO
    FACatchSummaryDTO faCatchSummaryDTO = getCatchSummaryReport(query, false);
    log.debug("FACatchSummaryDTO created");
    // We can not transfter DTO as it is over JMS because of JAVA maps.so, Map DTO to the type transferrable over JMS
    FACatchSummaryHelper faCatchSummaryHelper = FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.STANDARD);
    // Create response object for JMS
    FACatchSummaryReportResponse faCatchSummaryReportResponse = new FACatchSummaryReportResponse();
    faCatchSummaryReportResponse.setSummaryRecords(faCatchSummaryHelper.buildFACatchSummaryRecordList(faCatchSummaryDTO.getRecordDTOs()));
    faCatchSummaryReportResponse.setTotal(FACatchSummaryMapper.INSTANCE.mapToSummaryTable(faCatchSummaryDTO.getTotal()));
    log.debug("SummaryTable XML Schema response---->" + FACatchSummaryHelper.printJsonstructure(faCatchSummaryReportResponse));
    return faCatchSummaryReportResponse;
}
Also used : FACatchSummaryHelper(eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper) FACatchSummaryDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO) FACatchSummaryReportResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FACatchSummaryReportResponse)

Example 2 with FACatchSummaryHelper

use of eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper 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)

Example 3 with FACatchSummaryHelper

use of eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchReportServiceBean method getCatchSummaryReport.

/**
 *  This method groups FACatch Data, performs business logic to create summary report
 *  and creates FacatchSummaryDTO object as expected by web interface.
 *  isReporting : TRUE indicates that the method should be used to generate result for REPORTING module
 *                FALSE indicates that the method should be used to generate result from TRIP SUMMARY VIEW
 * @param query
 * @return
 * @throws ServiceException
 */
@Override
public FACatchSummaryDTO getCatchSummaryReport(FishingActivityQuery query, boolean isLanding) throws ServiceException {
    // get grouped data
    Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedData = faCatchDao.getGroupedFaCatchData(query, isLanding);
    // post process data to create Summary table part of Catch summary Report
    FACatchSummaryHelper faCatchSummaryHelper = isLanding ? FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.PRESENTATION) : FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.STANDARD);
    List<FACatchSummaryRecordDTO> catchSummaryList = faCatchSummaryHelper.buildFACatchSummaryRecordDTOList(groupedData);
    // Post process data to calculate Totals for each column
    SummaryTableDTO summaryTableDTOTotal = faCatchSummaryHelper.populateSummaryTableWithTotal(catchSummaryList);
    // Create DTO object to send back to the web
    FACatchSummaryDTO faCatchSummaryDTO = new FACatchSummaryDTO();
    faCatchSummaryDTO.setRecordDTOs(catchSummaryList);
    faCatchSummaryDTO.setTotal(summaryTableDTOTotal);
    return faCatchSummaryDTO;
}
Also used : FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) FACatchSummaryHelper(eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper) FACatchSummaryDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO) ArrayList(java.util.ArrayList) List(java.util.List) FACatchSummaryRecordDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryRecordDTO) SummaryTableDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.SummaryTableDTO)

Example 4 with FACatchSummaryHelper

use of eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchDao method getGroupedFaCatchData.

/**
 *  This method gets data from database and groups data as per various aggregation factors.
 *  If isLanding flag is true, then we need to gather information for Landing table as well.
 * @param query
 * @return Map<FaCatchSummaryCustomEntity,List<FaCatchSummaryCustomEntity>> key = object represnting common group, value is list of different objects which belong to  that group
 * @throws ServiceException
 */
public Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> getGroupedFaCatchData(FishingActivityQuery query, boolean isLanding) throws ServiceException {
    List<GroupCriteria> groupByFieldList = query.getGroupByFields();
    if (groupByFieldList == null || Collections.isEmpty(groupByFieldList))
        throw new ServiceException(" No Group information present to aggregate report.");
    FACatchSummaryHelper faCatchSummaryHelper = isLanding ? FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.PRESENTATION) : FACatchSummaryHelperFactory.getFACatchSummaryHelper(FACatchSummaryHelperFactory.STANDARD);
    // By default FishSize(LSC/BMS etc) and FACatch(DIS/DIM etc) type should be present in the summary table. First Query db with group FishClass
    faCatchSummaryHelper.enrichGroupCriteriaWithFishSizeAndSpecies(groupByFieldList);
    // get data with FishClass grouping factor
    List<FaCatchSummaryCustomProxy> customEntities = getRecordsForFishClassOrFACatchType(query, isLanding);
    faCatchSummaryHelper.enrichGroupCriteriaWithFACatchType(query.getGroupByFields());
    // Query database again to get records for FACatchType and combine it with previous result
    customEntities.addAll(getRecordsForFishClassOrFACatchType(query, isLanding));
    return faCatchSummaryHelper.groupByFACatchCustomEntities(customEntities);
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FACatchSummaryHelper(eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)

Aggregations

FACatchSummaryHelper (eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper)4 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)3 FACatchSummaryDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO)2 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)2 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)2 ArrayList (java.util.ArrayList)2 FACatchSummaryRecordDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryRecordDTO)1 SummaryTableDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.SummaryTableDTO)1 FACatchSearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder)1 FACatchSummaryReportResponse (eu.europa.ec.fisheries.uvms.activity.model.schemas.FACatchSummaryReportResponse)1 List (java.util.List)1