use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class AssetModuleServiceBean method getAssetGuids.
@Override
public List<String> getAssetGuids(String vesselSearchStr, String vesselGroupSearch) throws ServiceException {
List<String> guidsFromVesselSearchStr = null;
List<String> guidsFromVesselGroup = null;
String request;
// Get the list of guids from assets if vesselSearchStr is provided
if (StringUtils.isNotEmpty(vesselSearchStr)) {
try {
request = AssetModuleRequestMapper.createAssetListModuleRequest(createAssetListQuery(vesselSearchStr));
} catch (AssetModelMapperException e) {
log.error("Error while trying to map the request for assets Module.", e);
throw new ServiceException(e.getMessage(), e.getCause());
}
guidsFromVesselSearchStr = getGuidsFromAssets(request);
}
// If the list of guids is not empty then we have to provide this on the query also
if (StringUtils.isNotEmpty(vesselGroupSearch)) {
try {
request = AssetModuleRequestMapper.createAssetListModuleRequest(createAssetGroupQuery(vesselGroupSearch));
} catch (AssetModelMapperException e) {
log.error("Error while trying to map the request for assets Module.", e);
throw new ServiceException(e.getMessage(), e.getCause());
}
guidsFromVesselGroup = getGuidsFromAssets(request);
}
return joinResults(guidsFromVesselSearchStr, guidsFromVesselGroup);
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class AssetModuleServiceBean method getGuidsFromAssets.
@NotNull
protected List<String> getGuidsFromAssets(String request) throws ServiceException {
try {
String correlationId = assetProducer.sendModuleMessage(request, activityConsumer.getDestination());
TextMessage response = activityConsumer.getMessage(correlationId, TextMessage.class);
if (response != null && !isUserFault(response)) {
List<Asset> assets = AssetModuleResponseMapper.mapToAssetListFromResponse(response, correlationId);
List<String> assetGuids = new ArrayList<>();
for (Asset asset : assets) {
assetGuids.add(asset.getAssetId().getGuid());
}
return assetGuids;
} else {
throw new ServiceException("FAILED TO GET DATA FROM ASSET");
}
} catch (ServiceException | MessageException | AssetModelMapperException e) {
log.error("Exception in communication with movements", e);
throw new ServiceException(e.getMessage(), e);
}
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripServiceBean method getTripWidgetDto.
@Override
public /**
* Returns TripWidgetDto based on the tripId and activityId
*/
TripWidgetDto getTripWidgetDto(FishingActivityEntity activityEntity, String tripId) {
if (activityEntity == null && tripId == null) {
return null;
}
TripWidgetDto tripWidgetDto = new TripWidgetDto();
try {
if (tripId != null) {
log.debug("Trip Id found for Fishing Activity. Get TripWidget information for tripID :" + tripId);
TripOverviewDto tripOverviewDto = getTripOverviewDto(activityEntity, tripId);
List<TripOverviewDto> tripOverviewDtoList = new ArrayList<>();
tripOverviewDtoList.add(tripOverviewDto);
tripWidgetDto.setTrips(tripOverviewDtoList);
if (activityEntity != null && activityEntity.getFaReportDocument() != null && CollectionUtils.isNotEmpty(activityEntity.getFaReportDocument().getVesselTransportMeans())) {
Set<VesselTransportMeansEntity> vesselTransportMeansEntities = activityEntity.getFaReportDocument().getVesselTransportMeans();
for (VesselTransportMeansEntity vesselTransportMeansEntity : vesselTransportMeansEntities) {
if (vesselTransportMeansEntity.getFishingActivity() == null) {
tripWidgetDto.setVesselDetails(getVesselDetailsDTO(vesselTransportMeansEntity, activityEntity));
break;
}
}
}
// VesselDetailsDTO detailsDTO = getVesselDetailsForFishingTrip(tripId);
// tripWidgetDto.setVesselDetails(detailsDTO);
log.debug("tripWidgetDto set for tripID :" + tripId);
} else {
log.debug("TripId is not received for the screen. Try to get TripSummary information for all the tripIds specified for FishingActivity:" + activityEntity.getId());
return createTripWidgetDtoWithFishingActivity(activityEntity);
}
} catch (ServiceException e) {
log.error("Error while creating TripWidgetDto.", e);
}
return tripWidgetDto;
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripServiceBean method getMdrCodesEnrichWithAssetsModuleDataIfNeeded.
// To process MDR code list and compare with database:vesselTransportMeansDao and then enrich with asset module
private void getMdrCodesEnrichWithAssetsModuleDataIfNeeded(VesselDetailsDTO vesselDetailsDTO) {
final String ACRONYM = "FLUX_VESSEL_ID_TYPE";
final String filter = "*";
final List<String> columnsList = new ArrayList<String>();
Integer nrOfResults = 9999999;
if (vesselDetailsDTO != null) {
List<String> codeList = null;
try {
codeList = mdrModuleService.getAcronymFromMdr(ACRONYM, filter, columnsList, nrOfResults, "code").get("code");
Set<AssetIdentifierDto> vesselIdentifiers = vesselDetailsDTO.getVesselIdentifiers();
List<AssetListCriteriaPair> assetListCriteriaPairs = BaseMapper.mapMdrCodeListToAssetListCriteriaPairList(vesselIdentifiers, codeList);
log.info("Asset Criteria Pair List size is :" + assetListCriteriaPairs.size());
log.info("Got code list of size from mdr:" + codeList.size());
if (null != assetListCriteriaPairs && !CollectionUtils.isEmpty(assetListCriteriaPairs)) {
AssetListCriteria criteria = new AssetListCriteria();
// need to set this
criteria.setIsDynamic(false);
criteria.getCriterias().addAll(assetListCriteriaPairs);
AssetListQuery query = new AssetListQuery();
AssetListPagination assetListPagination = new AssetListPagination();
// need to set this
assetListPagination.setPage(1);
// need to set this
assetListPagination.setListSize(1000);
query.setPagination(assetListPagination);
query.setAssetSearchCriteria(criteria);
List<Asset> assetList = assetModuleService.getAssetListResponse(query);
if (null != assetList && !CollectionUtils.isEmpty(assetList)) {
vesselDetailsDTO.enrichIdentifiers(assetList.get(0));
}
}
} catch (ServiceException e) {
log.error("Error while trying to send message to Assets module.", e);
}
}
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripServiceBean method checkThresholdForFishingTripList.
public void checkThresholdForFishingTripList(Set<FishingTripId> fishingTripIds) throws ServiceException {
if (CollectionUtils.isNotEmpty(fishingTripIds)) {
String tresholdTrips = activityConfigurationDao.getPropertyValue(ActivityConfiguration.LIMIT_FISHING_TRIPS);
if (tresholdTrips != null) {
int threshold = Integer.parseInt(tresholdTrips);
log.debug("fishing trip threshold value:" + threshold);
if (fishingTripIds.size() > threshold)
throw new ServiceException("Fishing Trips found for matching criteria exceed threshold value. Please restrict resultset by modifying filters");
log.info("fishing trip list size is within threshold value:" + fishingTripIds.size());
}
}
}
Aggregations