use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FishingTripServiceBean method getRestrictedAreaGeom.
private Geometry getRestrictedAreaGeom(List<Dataset> datasets) throws ServiceException {
if (CollectionUtils.isEmpty(datasets)) {
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);
}
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FluxMessageServiceBean method saveFishingActivityReportDocuments.
/**
* {@inheritDoc}
*/
@Override
@Transactional(Transactional.TxType.REQUIRED)
public void saveFishingActivityReportDocuments(FLUXFAReportMessage faReportMessage, FaReportSourceEnum faReportSourceEnum) throws ServiceException {
log.info("[INFO] Going to save [ " + faReportMessage.getFAReportDocuments().size() + " ] FaReportDocuments..");
FluxFaReportMessageEntity messageEntity = new FluxFaReportMessageMapper().mapToFluxFaReportMessage(faReportMessage, faReportSourceEnum, new FluxFaReportMessageEntity());
final Set<FaReportDocumentEntity> faReportDocuments = messageEntity.getFaReportDocuments();
for (FaReportDocumentEntity faReportDocument : faReportDocuments) {
try {
updateGeometry(faReportDocument);
enrichFishingActivityWithGuiID(faReportDocument);
} catch (Exception e) {
log.error("Could not update Geometry OR enrichActivities for faReportDocument:" + faReportDocument.getId());
}
}
log.debug("fishing activity records to be saved : " + faReportDocuments.size());
fluxReportMessageDao.saveFluxFaReportMessage(messageEntity);
log.debug("Save partial FluxFaReportMessage before further processing");
updateFaReportCorrections(faReportMessage.getFAReportDocuments());
log.debug("Update FaReport Corrections is complete.");
updateFishingTripStartAndEndDate(faReportDocuments);
log.info("FluxFaReportMessage Saved successfully.");
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FluxMessageServiceBean method getGeometryFromMdr.
/**
* Find geometry for fluxLocation code in MDR
* @param fluxLocationIdentifier
* @return
*/
private Geometry getGeometryFromMdr(String fluxLocationIdentifier) {
log.debug("Get Geometry from MDR for:" + fluxLocationIdentifier);
if (fluxLocationIdentifier == null) {
return null;
}
Geometry geometry = null;
final List<String> columnsList = new ArrayList<>(Collections.singletonList("code"));
try {
Map<String, List<String>> portValuesFromMdr = mdrModuleServiceBean.getAcronymFromMdr("LOCATION", fluxLocationIdentifier, columnsList, 1, "latitude", "longitude");
List<String> latitudeValues = portValuesFromMdr.get("latitude");
List<String> longitudeValues = portValuesFromMdr.get("longitude");
Double latitude = null;
Double longitude = null;
if (CollectionUtils.isNotEmpty(latitudeValues)) {
String latitudeStr = latitudeValues.get(0);
if (latitudeStr != null) {
latitude = Double.parseDouble(latitudeStr);
}
}
if (CollectionUtils.isNotEmpty(longitudeValues)) {
String longitudeStr = longitudeValues.get(0);
if (longitudeStr != null) {
longitude = Double.parseDouble(longitudeStr);
}
}
geometry = GeometryUtils.createPoint(longitude, latitude);
} catch (ServiceException e) {
log.error("Error while retriving values from MDR.", e);
}
return geometry;
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class FluxMessageServiceBean method getGeometryFromSpatial.
/**
* Get Geometry information from spatial for FLUXLocation code
* @param fluxLocationIdentifier
* @return
*/
private Geometry getGeometryFromSpatial(String fluxLocationIdentifier) {
log.info("Get Geometry from Spatial for:" + fluxLocationIdentifier);
if (fluxLocationIdentifier == null) {
return null;
}
Geometry geometry = null;
try {
String geometryWkt = spatialModuleService.getGeometryForPortCode(fluxLocationIdentifier);
if (geometryWkt != null) {
Geometry value = GeometryMapper.INSTANCE.wktToGeometry(geometryWkt).getValue();
Coordinate[] coordinates = value.getCoordinates();
if (coordinates.length > 0) {
Coordinate coordinate = coordinates[0];
double x = coordinate.x;
double y = coordinate.y;
geometry = GeometryUtils.createPoint(x, y);
}
}
log.debug(" Geometry received from Spatial for:" + fluxLocationIdentifier + " :" + geometryWkt);
} catch (ServiceException | ParseException e) {
log.error("Exception while trying to get geometry from spatial", e);
}
return geometry;
}
use of eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException in project UVMS-ActivityModule-APP by UnionVMS.
the class MdrModuleServiceBean method getAcronymFromMdr.
@Override
public Map<String, List<String>> getAcronymFromMdr(String acronym, String filter, List<String> filterColumns, Integer nrOfResults, String... returnColumns) throws ServiceException {
Map<String, List<String>> columnNameValuesMap = prepareColumnNameValuesMap(returnColumns);
try {
String request = MdrModuleMapper.createFluxMdrGetCodeListRequest(acronym, filter, filterColumns, nrOfResults);
String correlationId = mdrProducer.sendModuleMessage(request, activityConsumer.getDestination());
TextMessage message = activityConsumer.getMessage(correlationId, TextMessage.class);
if (null != message) {
String messageStr = message.getText();
MdrGetCodeListResponse response = JAXBMarshaller.unmarshallTextMessage(messageStr, MdrGetCodeListResponse.class);
for (ObjectRepresentation objectRep : response.getDataSets()) {
for (ColumnDataType nameVal : objectRep.getFields()) {
if (columnNameValuesMap.containsKey(nameVal.getColumnName())) {
columnNameValuesMap.get(nameVal.getColumnName()).add(nameVal.getColumnValue());
}
}
}
return columnNameValuesMap;
} else {
throw new ServiceException("Unable to get data from MDR Module");
}
} catch (JMSException | MessageException | MdrModelMarshallException | ActivityModelMarshallException e) {
log.error("MdrModelMarshallException in communication with mdr", e.getCause());
throw new ServiceException("Exception caught in mdrModuleServiceBean", e.getCause());
}
}
Aggregations