Search in sources :

Example 1 with AssetModelMapperException

use of eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeAssetServiceBean method getAsset.

@Override
public Asset getAsset(String assetGuid) throws ExchangeServiceException {
    try {
        String request = AssetModuleRequestMapper.createGetAssetModuleRequest(assetGuid, AssetIdType.GUID);
        String messageId = producer.sendMessageOnQueue(request, MessageQueue.VESSEL);
        TextMessage response = consumer.getMessage(messageId, TextMessage.class);
        return AssetModuleResponseMapper.mapToAssetFromResponse(response, messageId);
    } catch (ExchangeMessageException | MessageException e) {
        LOG.error("Couldn't send message to vessel module");
        throw new ExchangeServiceException("Couldn't send message to vessel module");
    } catch (AssetModelMapperException e) {
        LOG.error("Couldn't map asset object by guid:  {}", assetGuid);
        throw new ExchangeServiceException("Couldn't map asset object by guid:  " + assetGuid);
    }
}
Also used : MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) AssetModelMapperException(eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException) ExchangeMessageException(eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException) TextMessage(javax.jms.TextMessage) ExchangeServiceException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)

Example 2 with AssetModelMapperException

use of eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException 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);
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) AssetModelMapperException(eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException)

Example 3 with AssetModelMapperException

use of eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException 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);
    }
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) AssetModelMapperException(eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException) TextMessage(javax.jms.TextMessage) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AssetModelMapperException

use of eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException in project UVMS-ActivityModule-APP by UnionVMS.

the class AssetModuleServiceBean method getAssetListResponse.

@Override
public List<Asset> getAssetListResponse(AssetListQuery assetListQuery) throws ServiceException {
    List<Asset> assetList;
    try {
        String assetsRequest = AssetModuleRequestMapper.createAssetListModuleRequest(assetListQuery);
        String correlationID = assetProducer.sendModuleMessage(assetsRequest, activityConsumer.getDestination());
        TextMessage response = activityConsumer.getMessage(correlationID, TextMessage.class);
        assetList = AssetModuleResponseMapper.mapToAssetListFromResponse(response, correlationID);
    } catch (AssetModelMapperException | MessageException e) {
        log.error("Error while trying to send message to Assets module.", e);
        throw new ServiceException(e.getMessage(), e.getCause());
    }
    return assetList;
}
Also used : ServiceException(eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException) MessageException(eu.europa.ec.fisheries.uvms.commons.message.api.MessageException) AssetModelMapperException(eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException) TextMessage(javax.jms.TextMessage)

Aggregations

AssetModelMapperException (eu.europa.ec.fisheries.uvms.asset.model.exception.AssetModelMapperException)4 MessageException (eu.europa.ec.fisheries.uvms.commons.message.api.MessageException)3 ServiceException (eu.europa.ec.fisheries.uvms.commons.service.exception.ServiceException)3 TextMessage (javax.jms.TextMessage)3 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)1 ExchangeServiceException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeServiceException)1 NotNull (org.jetbrains.annotations.NotNull)1