Search in sources :

Example 6 with GroupCriteria

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria 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);
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with GroupCriteria

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSearchBuilder_Landing method createJoinPartOfTheQuery.

protected void createJoinPartOfTheQuery(FishingActivityQuery query, StringBuilder sql, Map<GroupCriteria, GroupCriteriaMapper> groupMAppings, List<GroupCriteria> groupByFieldList) {
    // Below is default JOIN for the query
    sql.append(FA_CATCH_JOIN);
    // Create join part of SQL query
    // Join only required tables based on filter criteria
    createJoinTablesPartForQuery(sql, query);
    // Add joins if not added by activity filtering . Below code will add joins required by FA Catch report joins
    for (GroupCriteria criteria : groupByFieldList) {
        GroupCriteriaMapper mapper = groupMAppings.get(criteria);
        if (sql.indexOf(mapper.getTableJoin()) == -1) {
            appendJoinString(sql, mapper.getTableJoin());
        }
    }
}
Also used : GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)

Example 8 with GroupCriteria

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria 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 9 with GroupCriteria

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchReportServiceBean method getCatchDetailsScreenTable.

/**
 * This method gets you table structure for Catch details summary on TRIP SUMMARY VIEW
 * @param tripId data will be returned for this tripId
 * @param isLanding If landing then summary structure will include PRESENTATION information otherwise only species information will be included
 * @return
 * @throws ServiceException
 */
public FACatchSummaryDTO getCatchDetailsScreenTable(String tripId, boolean isLanding) throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    List<GroupCriteria> groupByFields = getGroupByFields(isLanding);
    query.setGroupByFields(groupByFields);
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, tripId);
    query.setSearchCriteriaMap(searchCriteriaMap);
    return getCatchSummaryReport(query, isLanding);
}
Also used : FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) EnumMap(java.util.EnumMap) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)

Example 10 with GroupCriteria

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria 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

GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)12 GroupCriteriaMapper (eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)6 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)5 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)5 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)4 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)4 ArrayList (java.util.ArrayList)4 EnumMap (java.util.EnumMap)3 Test (org.junit.Test)3 FACatchSummaryHelper (eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper)2 List (java.util.List)2 SneakyThrows (lombok.SneakyThrows)2 NotNull (org.jetbrains.annotations.NotNull)2 FACatchDetailsDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchDetailsDTO)1 FACatchSummaryDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO)1 FACatchSearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1