Search in sources :

Example 1 with FaCatchSummaryCustomProxy

use of eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy in project UVMS-ActivityModule-APP by UnionVMS.

the class MapperUtil method getGroupedFaCatchSummaryCustomEntityData.

public static Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> getGroupedFaCatchSummaryCustomEntityData() {
    FaCatchSummaryCustomProxy customEntityKey = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "GUT", "37F8", "XEU", "27.4.b", "A", null, null, null, "LSC", "PLE", null, 200);
    FaCatchSummaryCustomProxy customEntityValue1 = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "GUT", "37F8", "XEU", "27.4.b", "A", null, null, null, "LSC", "PLE", null, 200);
    FaCatchSummaryCustomProxy customEntityValue2 = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "GUT", "37F8", "XEU", "27.4.b", "A", null, null, null, "BMS", "SOL", null, 200);
    FaCatchSummaryCustomProxy customEntityValue3 = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "WHL", "37F8", "XEU", "27.4.b", "A", null, null, null, "BMS", "PLE", null, 200);
    FaCatchSummaryCustomProxy customEntityValue4 = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "ROE-C", "37F8", "XEU", "27.4.b", "A", null, null, null, "LSC", "PLE", null, 200);
    FaCatchSummaryCustomProxy customEntityValue5 = new FaCatchSummaryCustomProxy("15", null, null, null, null, null, null, "GUT", "37F8", "XEU", "27.4.b", "A", null, null, null, "LSC", "COD", null, 200);
    Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedData = new HashMap<>();
    List<FaCatchSummaryCustomProxy> valueList1 = new ArrayList<>();
    valueList1.add(customEntityValue1);
    valueList1.add(customEntityValue2);
    valueList1.add(customEntityValue3);
    valueList1.add(customEntityValue4);
    valueList1.add(customEntityValue5);
    groupedData.put(customEntityKey, valueList1);
    return groupedData;
}
Also used : FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with FaCatchSummaryCustomProxy

use of eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy in project UVMS-ActivityModule-APP by UnionVMS.

the class FaCatchReportServiceBeanTest method testGetCatchSummaryReport.

@Test
@SneakyThrows
public void testGetCatchSummaryReport() throws ServiceException {
    FishingActivityQuery query = new FishingActivityQuery();
    List<GroupCriteria> groupByFields = new ArrayList<>();
    groupByFields.add(GroupCriteria.DATE_DAY);
    groupByFields.add(GroupCriteria.FAO_AREA);
    groupByFields.add(GroupCriteria.TERRITORY);
    groupByFields.add(GroupCriteria.EFFORT_ZONE);
    groupByFields.add(GroupCriteria.GFCM_GSA);
    groupByFields.add(GroupCriteria.GFCM_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.ICES_STAT_RECTANGLE);
    groupByFields.add(GroupCriteria.RFMO);
    groupByFields.add(GroupCriteria.SPECIES);
    query.setGroupByFields(groupByFields);
    Map<SearchFilter, String> searchCriteriaMap = new EnumMap<SearchFilter, String>(SearchFilter.class);
    searchCriteriaMap.put(SearchFilter.TRIP_ID, "NOR-TRP-20160517234053706");
    query.setSearchCriteriaMap(searchCriteriaMap);
    Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedData = MapperUtil.getGroupedFaCatchSummaryCustomEntityData();
    when((faCatchDao).getGroupedFaCatchData(any(FishingActivityQuery.class), any(Boolean.class))).thenReturn(groupedData);
    // when(faCatchDao.getGroupedFaCatchData(query,true)).thenReturn(MapperUtil.getGroupedFaCatchSummaryCustomEntityData());
    // when(vesselIdentifiersDao.getLatestVesselIdByTrip("NOR-TRP-20160517234053706")).thenReturn(MapperUtil.getVesselIdentifiersList());
    // Trigger
    FACatchSummaryDTO fACatchSummaryDTO = faCatchReportService.getCatchSummaryReport(query, false);
    Mockito.verify(faCatchDao, Mockito.times(1)).getGroupedFaCatchData(Mockito.any(FishingActivityQuery.class), Mockito.any(Boolean.class));
    // Verify
    assertNotNull(fACatchSummaryDTO);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter) GroupCriteria(eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) FACatchSummaryDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with FaCatchSummaryCustomProxy

use of eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryPresentationHelper method buildFACatchSummaryRecordDTOList.

/**
 *  Post process data received from database to create FACatchSummaryRecordDTO. Every record will have summary calculated for it.
 *
 * @param groupedMap
 * @return List<FACatchSummaryRecordDTO> Processed records having summary data
 */
@Override
public List<FACatchSummaryRecordDTO> buildFACatchSummaryRecordDTOList(Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedMap) {
    List<FACatchSummaryRecordDTO> faCatchSummaryRecordDTOs = new ArrayList<>();
    for (Map.Entry<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> entry : groupedMap.entrySet()) {
        FaCatchSummaryCustomProxy customEntity = entry.getKey();
        // We dont want Presentation to be part of group criteria. We want to display this information in summmary table so, remove it
        customEntity.setPresentation(null);
        FACatchSummaryRecordDTO faCatchSummaryDTO = FACatchSummaryMapper.INSTANCE.mapToFACatchSummaryRecordDTOWithPresentation(entry.getKey(), entry.getValue());
        if (CollectionUtils.isEmpty(faCatchSummaryDTO.getGroups())) {
            // Do not add record to the list if no data for grouping factors found
            log.error("No data for the grouping factors found :" + faCatchSummaryDTO);
            continue;
        }
        // If there is Group but no data for Summary table for the group, do not send it to frontend
        if (faCatchSummaryDTO.getSummaryTable() == null || (faCatchSummaryDTO.getSummaryTable().getSummaryFaCatchType() == null && faCatchSummaryDTO.getSummaryTable().getSummaryFishSize() == null)) {
            log.error("No data for the summary found :" + faCatchSummaryDTO);
            continue;
        }
        faCatchSummaryRecordDTOs.add(faCatchSummaryDTO);
    }
    return faCatchSummaryRecordDTOs;
}
Also used : FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) ArrayList(java.util.ArrayList) FACatchSummaryRecordDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryRecordDTO) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with FaCatchSummaryCustomProxy

use of eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryReportHelper method buildFACatchSummaryRecordDTOList.

/**
 *  Post process data received from database to create FACatchSummaryRecordDTO. Every record will have summary calculated for it.
 *
 * @param groupedMap
 * @return List<FACatchSummaryRecordDTO> Processed records having summary data
 */
@Override
public List<FACatchSummaryRecordDTO> buildFACatchSummaryRecordDTOList(Map<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> groupedMap) {
    List<FACatchSummaryRecordDTO> faCatchSummaryRecordDTOs = new ArrayList<>();
    for (Map.Entry<FaCatchSummaryCustomProxy, List<FaCatchSummaryCustomProxy>> entry : groupedMap.entrySet()) {
        FACatchSummaryRecordDTO faCatchSummaryDTO = FACatchSummaryMapper.INSTANCE.mapToFACatchSummaryRecordDTO(entry.getKey(), entry.getValue());
        if (CollectionUtils.isEmpty(faCatchSummaryDTO.getGroups())) {
            // Do not add record to the list if no data for grouping factors found
            log.error("No data for the grouping factors found :" + faCatchSummaryDTO);
            continue;
        }
        // If there is Group but no data for Summary table for the group, do not send it to frontend
        if (faCatchSummaryDTO.getSummaryTable() == null || (faCatchSummaryDTO.getSummaryTable().getSummaryFaCatchType() == null && faCatchSummaryDTO.getSummaryTable().getSummaryFishSize() == null)) {
            log.error("No data for the summary found :" + faCatchSummaryDTO);
            continue;
        }
        faCatchSummaryRecordDTOs.add(faCatchSummaryDTO);
    }
    return faCatchSummaryRecordDTOs;
}
Also used : FaCatchSummaryCustomProxy(eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy) ArrayList(java.util.ArrayList) FACatchSummaryRecordDTO(eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryRecordDTO) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 5 with FaCatchSummaryCustomProxy

use of eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy 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)

Aggregations

FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)12 ArrayList (java.util.ArrayList)8 List (java.util.List)7 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 FACatchSummaryRecordDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryRecordDTO)3 FACatchSummaryHelper (eu.europa.ec.fisheries.ers.service.facatch.FACatchSummaryHelper)3 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)3 EnumMap (java.util.EnumMap)3 FACatchSummaryDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.FACatchSummaryDTO)2 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)2 BaseUnitilsTest (eu.europa.ec.fisheries.uvms.BaseUnitilsTest)2 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)2 Map (java.util.Map)2 SummaryTableDTO (eu.europa.ec.fisheries.ers.service.dto.fareport.summary.SummaryTableDTO)1 GroupCriteriaMapper (eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)1 FACatchSearchBuilder (eu.europa.ec.fisheries.ers.service.search.builder.FACatchSearchBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1