use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FluxMessageServiceBean method interpolatePointFromMovements.
private Geometry interpolatePointFromMovements(List<MovementType> movements, Date activityDate) throws ServiceException {
if (movements == null || movements.isEmpty()) {
return null;
}
Geometry faReportGeom;
Collections.sort(movements, new MovementTypeComparator());
Map<String, MovementType> movementTypeMap = getPreviousAndNextMovement(movements, activityDate);
MovementType nextMovement = movementTypeMap.get(NEXT);
MovementType previousMovement = movementTypeMap.get(PREVIOUS);
try {
if (previousMovement == null && nextMovement == null) {
faReportGeom = null;
} else if (nextMovement == null) {
faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(previousMovement.getWkt()).getValue();
faReportGeom.setSRID(dialect.defaultSRID());
} else if (previousMovement == null) {
faReportGeom = GeometryMapper.INSTANCE.wktToGeometry(nextMovement.getWkt()).getValue();
faReportGeom.setSRID(dialect.defaultSRID());
} else {
faReportGeom = calculateIntermediatePoint(previousMovement, nextMovement, activityDate);
}
} catch (ParseException e) {
throw new ServiceException(e.getMessage(), e);
}
return faReportGeom;
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class SpatialModuleServiceBean method getGeometryForPortCode.
@Override
public String getGeometryForPortCode(String portCode) throws ServiceException {
log.info("Inside getGeometryForPortCode :" + portCode);
try {
String request = SpatialModuleRequestMapper.mapToGeometryByPortCodeRequest(portCode);
String correlationId = spatialProducer.sendModuleMessage(request, activityConsumer.getDestination());
TextMessage message = activityConsumer.getMessage(correlationId, TextMessage.class);
if (message != null && !isUserFault(message)) {
GeometryByPortCodeResponse response = SpatialModuleResponseMapper.mapGeometryByPortCodeResponseToString(message, correlationId);
return response.getPortGeometry();
} else {
throw new ServiceException("FAILED TO GET GEOMETRY FROM SPATIAL");
}
} catch (ServiceException | MessageException | SpatialModelMapperException e) {
log.error("Exception in communication with spatial while retrieving GEOMETRY", 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 ActivityEventServiceBean method getFishingActivityMessage.
@Override
public void getFishingActivityMessage(@Observes @ReceiveFishingActivityRequestEvent EventMessage eventMessage) {
log.info(GOT_JMS_INSIDE_ACTIVITY_TO_GET + "SetFLUXFAReportOrQueryMessageRequest");
try {
TextMessage jmsMessage = eventMessage.getJmsMessage();
SetFLUXFAReportOrQueryMessageRequest request = JAXBMarshaller.unmarshallTextMessage(jmsMessage, SetFLUXFAReportOrQueryMessageRequest.class);
log.info("SetFLUXFAReportOrQueryMessageRequest unmarshalled");
if (request == null) {
log.error("Unmarshalled SetFLUXFAReportOrQueryMessageRequest is null. Something went wrong during jms comm?!");
return;
}
switch(eventMessage.getMethod()) {
case GET_FLUX_FA_REPORT:
FLUXFAReportMessage fluxFAReportMessage = JAXBMarshaller.unmarshallTextMessage(request.getRequest(), FLUXFAReportMessage.class);
deleteDuplicatedReportsFromXMLDocument(fluxFAReportMessage);
if (CollectionUtils.isNotEmpty(fluxFAReportMessage.getFAReportDocuments())) {
fluxMessageService.saveFishingActivityReportDocuments(fluxFAReportMessage, extractPluginType(request.getPluginType()));
} else {
log.error("[ERROR] After checking faReportDocuments IDs, all of them exist already in Activity DB.. So nothing will be saved!!");
}
break;
case GET_FLUX_FA_QUERY:
log.error("TODO : FAQUERY mappers NOT implemented yet....");
FLUXFAQueryMessage fluxFAQueryMessage = JAXBMarshaller.unmarshallTextMessage(request.getRequest(), FLUXFAQueryMessage.class);
// TODO : Implement me... Map tp real HQl/SQL query and run the query and map the results to FLUXFAReportMessage and send it to
FLUXFAReportMessage faRepQueryResponseAfterMapping = new FLUXFAReportMessage();
activityRulesModuleServiceBean.sendSyncAsyncFaReportToRules(faRepQueryResponseAfterMapping, "getTheOnValueFromSomewahre", request.getRequestType(), jmsMessage.getJMSMessageID());
break;
}
} catch (ActivityModelMarshallException | ServiceException | ActivityModuleException | JMSException e) {
sendError(eventMessage, e);
}
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class ActivityServiceBean method getFishingActivityForView.
/**
* Gets a FishingActivityEntity with a certain activityId and maps it to a FishingActivityViewDTO representation layer POJO.
*
* @param activityId
* @param datasets
* @return
* @throws ServiceException
*/
@Override
public FishingActivityViewDTO getFishingActivityForView(Integer activityId, String tripId, List<Dataset> datasets, ActivityViewEnum view) throws ServiceException {
Geometry geom = getRestrictedAreaGeometry(datasets);
FishingActivityEntity activityEntity = fishingActivityDao.getFishingActivityById(activityId, geom);
if (activityEntity == null)
throw new ServiceException("Could not find FishingActivityEntity for the given id:" + activityId);
log.debug("FishingActivityEntity fetched from database with id:" + activityEntity.getId());
FishingActivityViewDTO fishingActivityViewDTO = ActivityViewMapperFactory.getMapperForView(view).mapFaEntityToFaDto(activityEntity);
fishingActivityViewDTO.setTripDetails(fishingTripServiceBean.getTripWidgetDto(activityEntity, tripId));
log.debug("fishingActivityView generated after mapping is :" + fishingActivityViewDTO);
addPortDescriptions(fishingActivityViewDTO, "LOCATION");
fishingActivityViewDTO.setTripDetails(fishingTripServiceBean.getTripWidgetDto(activityEntity, tripId));
fishingActivityViewDTO.setHistory(getActivityHistoryDto(activityEntity));
log.debug("fishingActivityView generated after mapping is :" + fishingActivityViewDTO);
return fishingActivityViewDTO;
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class ActivityServiceBean method getRestrictedAreaGeometry.
private Geometry getRestrictedAreaGeometry(List<Dataset> datasets) throws ServiceException {
if (datasets == null || datasets.isEmpty()) {
return null;
}
try {
List<AreaIdentifierType> areaIdentifierTypes = UsmUtils.convertDataSetToAreaId(datasets);
String areaWkt = spatialModule.getFilteredAreaGeom(areaIdentifierTypes);
Geometry geometry = GeometryMapper.INSTANCE.wktToGeometry(areaWkt).getValue();
geometry.setSRID(GeometryUtils.DEFAULT_EPSG_SRID);
return geometry;
} catch (ParseException e) {
throw new ServiceException(e.getMessage(), e);
}
}
Aggregations