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);
}
}
}
}
}
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);
}
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();
}
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;
}
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();
}
Aggregations