Search in sources :

Example 36 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityServiceBean method addPortDescriptions.

private void addPortDescriptions(FishingActivityViewDTO fishingActivityViewDTO, String fluxLocationIdSchemeId) {
    if (fishingActivityViewDTO == null || StringUtils.isBlank(fluxLocationIdSchemeId)) {
        return;
    }
    final String ACRONYM = "LOCATION";
    String filter = null;
    final List<String> columnsList = new ArrayList<String>(Arrays.asList("code"));
    Integer nrOfResults = 1;
    if (CollectionUtils.isNotEmpty(fishingActivityViewDTO.getLocations())) {
        for (FluxLocationDto fluxLocationDto : fishingActivityViewDTO.getLocations()) {
            if (fluxLocationIdSchemeId.equals(fluxLocationDto.getFluxLocationIdentifierSchemeId())) {
                try {
                    filter = fluxLocationDto.getFluxLocationIdentifier();
                    List<String> codeDescriptions = mdrModuleService.getAcronymFromMdr(ACRONYM, filter, columnsList, nrOfResults, "description").get("description");
                    String codeDescription = codeDescriptions.get(0);
                    fluxLocationDto.setPortDescription(codeDescription);
                } catch (ServiceException e) {
                    log.error("Error while trying to set port description on FluxLocationDto.", e);
                } catch (IndexOutOfBoundsException iobe) {
                    log.error("Error while trying to set port description on FluxLocationDto! Description for code: " + fluxLocationDto.getTypeCode() + " doesn't exist", iobe);
                }
            }
        }
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) ArrayList(java.util.ArrayList) FluxLocationDto(eu.europa.ec.fisheries.ers.service.dto.view.FluxLocationDto)

Example 37 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException 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)

Example 38 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityDao method getFishingActivityListForFishingTrip.

/**
 * This method will retrieve all the fishingActivities received for the trip order by Activity type and then by FAReport accepted date.
 * so that we know which are corrected activities received.
 * @param fishingTripId
 * @param multipolgon
 * @return
 * @throws ServiceException
 */
public List<FishingActivityEntity> getFishingActivityListForFishingTrip(String fishingTripId, Geometry multipolgon) throws ServiceException {
    if (fishingTripId == null || fishingTripId.length() == 0)
        throw new ServiceException("fishing Trip Id is null or empty. ");
    String queryName = FishingActivityEntity.ACTIVITY_FOR_FISHING_TRIP;
    if (multipolgon == null)
        queryName = FishingActivityEntity.FIND_FA_DOCS_BY_TRIP_ID_WITHOUT_GEOM;
    Query query = getEntityManager().createNamedQuery(queryName);
    query.setParameter("fishingTripId", fishingTripId);
    if (multipolgon != null)
        query.setParameter("area", multipolgon);
    return query.getResultList();
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)

Example 39 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingTripDao method getFishingTripIdsForMatchingFilterCriteria.

/**
 * Get all the Fishing Trip entities for matching Filters
 *
 * @param query FishingActivityQuery
 * @return
 * @throws ServiceException
 */
public Set<FishingTripId> getFishingTripIdsForMatchingFilterCriteria(FishingActivityQuery query) throws ServiceException {
    Query listQuery = getQueryForFilterFishingTripIds(query);
    PaginationDto pagination = query.getPagination();
    if (pagination != null && pagination.getOffset() != null) {
        listQuery.setFirstResult(pagination.getOffset());
        listQuery.setMaxResults(pagination.getPageSize());
    }
    List<Object[]> resultList = listQuery.getResultList();
    if (CollectionUtils.isEmpty(resultList))
        return Collections.emptySet();
    Set<FishingTripId> fishingTripIds = new HashSet<>();
    for (Object[] objArr : resultList) {
        try {
            if (objArr != null && objArr.length == 2) {
                fishingTripIds.add(new FishingTripId((String) objArr[0], (String) objArr[1]));
            }
        } catch (Exception e) {
            log.error("Could not map sql selection to FishingTripId object", e);
        }
    }
    return fishingTripIds;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) FishingActivityQuery(eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery) PaginationDto(eu.europa.ec.fisheries.uvms.commons.rest.dto.PaginationDto) FishingTripId(eu.europa.ec.fisheries.ers.service.search.FishingTripId) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) HashSet(java.util.HashSet)

Example 40 with ServiceException

use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.

the class UserRoleInterceptor method interceptRequest.

@AroundInvoke
public Object interceptRequest(final InvocationContext ic) throws Exception {
    IUserRoleInterceptor iUserRoleInterceptor = ic.getMethod().getAnnotation(IUserRoleInterceptor.class);
    // Get User role defined in the Rest service
    ActivityFeaturesEnum[] features = iUserRoleInterceptor.requiredUserRole();
    // Request parameters
    Object[] parameters = ic.getParameters();
    HttpServletRequest req = getHttpServletRequest(parameters);
    boolean isUserAuthorized = false;
    for (ActivityFeaturesEnum activityFeaturesEnum : features) {
        isUserAuthorized = req.isUserInRole(activityFeaturesEnum.value());
    }
    if (!isUserAuthorized) {
        throw new ServiceException(ErrorCodes.NOT_AUTHORIZED);
    }
    return ic.proceed();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActivityFeaturesEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.ActivityFeaturesEnum) ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)42 ArrayList (java.util.ArrayList)11 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)9 Geometry (com.vividsolutions.jts.geom.Geometry)8 ParseException (com.vividsolutions.jts.io.ParseException)7 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)7 TextMessage (javax.jms.TextMessage)7 List (java.util.List)6 ActivityModelMarshallException (eu.europa.ec.fisheries.uvms.activity.model.exception.ActivityModelMarshallException)5 GroupCriteria (eu.europa.ec.fisheries.uvms.activity.model.schemas.GroupCriteria)5 JMSException (javax.jms.JMSException)5 FilterMap (eu.europa.ec.fisheries.ers.service.search.FilterMap)4 Map (java.util.Map)4 FaCatchSummaryCustomProxy (eu.europa.ec.fisheries.ers.fa.dao.proxy.FaCatchSummaryCustomProxy)3 VesselTransportMeansEntity (eu.europa.ec.fisheries.ers.fa.entities.VesselTransportMeansEntity)3 GroupCriteriaMapper (eu.europa.ec.fisheries.ers.service.search.GroupCriteriaMapper)3 AssetModelMapperException (eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException)3 AreaIdentifierType (eu.europa.ec.fisheries.uvms.spatial.model.schemas.AreaIdentifierType)3 EnumMap (java.util.EnumMap)3 NotNull (org.jetbrains.annotations.NotNull)3