Search in sources :

Example 6 with InputArgumentException

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

the class ExchangeLogModelBean method getExchangeLogStatusHistoryByQuery.

@Override
public List<ExchangeLogStatusType> getExchangeLogStatusHistoryByQuery(ExchangeHistoryListQuery query) throws ExchangeModelException {
    if (query == null) {
        throw new InputArgumentException("Exchange status list query is null");
    }
    try {
        List<ExchangeLogStatusType> logStatusHistoryList = new ArrayList<>();
        String sql = SearchFieldMapper.createSearchSql(query);
        List<ExchangeLogStatus> logList = logDao.getExchangeLogStatusHistory(sql, query);
        Set<String> uniqueExchangeLogGuid = new HashSet<>();
        Map<String, TypeRefType> logTypeMap = new HashMap<>();
        for (ExchangeLogStatus log : logList) {
            uniqueExchangeLogGuid.add(log.getLog().getGuid());
            logTypeMap.put(log.getLog().getGuid(), log.getLog().getTypeRefType());
        }
        // TODO not two db-calls?
        for (String guid : uniqueExchangeLogGuid) {
            ExchangeLog log = logDao.getExchangeLogByGuid(guid);
            ExchangeLogStatusType statusType = LogMapper.toStatusModel(log);
            logStatusHistoryList.add(statusType);
        }
        return logStatusHistoryList;
    } catch (ExchangeDaoException e) {
        LOG.error("[ Error when get Exchange log status history {}] {} ", query, e.getMessage());
        throw new ExchangeModelException("Error when get Exchange log status history ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) TypeRefType(eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) HashSet(java.util.HashSet)

Example 7 with InputArgumentException

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

the class UnsentModelBean method createMessage.

@Override
public String createMessage(UnsentMessageType message, String username) throws ExchangeModelException {
    if (message == null) {
        throw new InputArgumentException("No message to create");
    }
    try {
        UnsentMessage entity = UnsentMessageMapper.toEntity(message, username);
        UnsentMessage persistedEntity = dao.create(entity);
        UnsentMessageType model = UnsentMessageMapper.toModel(persistedEntity);
        return model.getMessageId();
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
        throw new ExchangeModelException("Error when creating unsent message ");
    }
}
Also used : UnsentMessageType(eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 8 with InputArgumentException

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

the class UnsentModelBean method removeMessage.

@Override
public String removeMessage(String unsentMessageId) throws ExchangeModelException {
    if (unsentMessageId == null) {
        throw new InputArgumentException("No message to remove");
    }
    try {
        UnsentMessage entity = dao.getByGuid(unsentMessageId);
        if (entity != null) {
            String guid = entity.getGuid();
            dao.remove(entity);
            return guid;
        } else {
            LOG.error("[ Error when removing unsent message ]");
            throw new ExchangeModelException("Error when removing unsent message ");
        }
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when creating unsent message ] {}", ex.getMessage());
        throw new ExchangeModelException("Error when creating unsent message ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) UnsentMessage(eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Aggregations

ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)8 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)8 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)8 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)5 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)3 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)3 UnsentMessage (eu.europa.ec.fisheries.uvms.exchange.entity.unsent.UnsentMessage)3 ArrayList (java.util.ArrayList)3 UnsentMessageType (eu.europa.ec.fisheries.schema.exchange.v1.UnsentMessageType)2 ExchangeLogStatusHistoryType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType)1 ExchangeLogStatusType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType)1 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)1 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)1 ListResponseDto (eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)1 ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)1 SearchValue (eu.europa.ec.fisheries.uvms.exchange.search.SearchValue)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1