Search in sources :

Example 1 with GroupCriteriaMapper

use of eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper 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;
}
Also used : Method(java.lang.reflect.Method) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)

Example 2 with GroupCriteriaMapper

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

the class FACatchSearchBuilder 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 3 with GroupCriteriaMapper

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

the class FACatchSearchBuilder method createGroupByPartOfTheQuery.

protected void createGroupByPartOfTheQuery(StringBuilder sql, Map<GroupCriteria, GroupCriteriaMapper> groupMappings, List<GroupCriteria> groupByFieldList) {
    sql.append(" GROUP BY  ");
    // Add group by statement based on grouping factors
    int i = 0;
    for (GroupCriteria criteria : groupByFieldList) {
        if (i != 0)
            sql.append(", ");
        GroupCriteriaMapper mapper = groupMappings.get(criteria);
        sql.append(mapper.getColumnName());
        i++;
    }
}
Also used : GroupCriteriaMapper(eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)

Example 4 with GroupCriteriaMapper

use of eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper 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 5 with GroupCriteriaMapper

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

Aggregations

GroupCriteriaMapper (eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)6 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)6 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)3 NotNull (org.jetbrains.annotations.NotNull)2 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1