Search in sources :

Example 16 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method createExchangeLog.

@Override
public ExchangeLogType createExchangeLog(ExchangeLogType log, String username) throws ExchangeModelException {
    if (log == null) {
        throw new InputArgumentException("No log to create");
    }
    if (log.getType() == null) {
        throw new InputArgumentException("No type in log to create");
    }
    try {
        ExchangeLog exchangeLog = LogMapper.toNewEntity(log, username);
        ExchangeLog persistedLog = logDao.createLog(exchangeLog);
        return LogMapper.toModel(persistedLog);
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when creating Exchange log {} {}] {}", log, username, ex.getMessage());
        throw new ExchangeModelException("Error when creating Exchange log ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 17 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogByGuidAndType.

@Override
public ExchangeLogType getExchangeLogByGuidAndType(String guid, TypeRefType typeRefType) throws ExchangeModelException {
    ExchangeLogType exchangeLogType;
    try {
        ExchangeLog exchangeLogByGuid = logDao.getExchangeLogByGuid(guid, typeRefType);
        exchangeLogType = LogMapper.toModel(exchangeLogByGuid);
    } catch (Exception e) {
        LOG.error("[ Error when getting exchange log by GUID. {}] {}", guid, e.getMessage());
        exchangeLogType = null;
    }
    return exchangeLogType;
}
Also used : ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 18 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogListByQuery.

@Override
public ListResponseDto getExchangeLogListByQuery(ExchangeListQuery query) throws ExchangeModelException {
    if (query == null) {
        throw new InputArgumentException("Exchange list query is null");
    }
    if (query.getPagination() == null) {
        throw new InputArgumentException("Pagination in Exchange query is null");
    }
    if (query.getExchangeSearchCriteria() == null) {
        throw new InputArgumentException("No search criterias in Exchange query");
    }
    try {
        ListResponseDto response = new ListResponseDto();
        List<ExchangeLogType> exchLogTypes = new ArrayList<>();
        Integer page = query.getPagination().getPage();
        Integer listSize = query.getPagination().getListSize();
        List<SearchValue> searchKeyValues = SearchFieldMapper.mapSearchField(query.getExchangeSearchCriteria().getCriterias());
        String sql = SearchFieldMapper.createSelectSearchSql(searchKeyValues, true, query.getSorting());
        LOG.info("sql:" + sql);
        String countSql = SearchFieldMapper.createCountSearchSql(searchKeyValues, true);
        LOG.info("countSql:" + countSql);
        Long numberMatches = logDao.getExchangeLogListSearchCount(countSql, searchKeyValues);
        List<ExchangeLog> exchangeLogEntityList = logDao.getExchangeLogListPaginated(page, listSize, sql, searchKeyValues);
        for (ExchangeLog entity : exchangeLogEntityList) {
            exchLogTypes.add(LogMapper.toModel(entity));
        }
        // Enriches the "first level logs" with info related to the related logs.
        enrichDtosWithRelatedLogsInfo(exchLogTypes);
        int numberOfPages = (int) (numberMatches / listSize);
        if (numberMatches % listSize != 0) {
            numberOfPages += 1;
        }
        response.setTotalNumberOfPages(numberOfPages);
        response.setCurrentPage(query.getPagination().getPage());
        response.setExchangeLogList(exchLogTypes);
        return response;
    } catch (ExchangeSearchMapperException | ExchangeDaoException | ParseException ex) {
        LOG.error("[ Error when getting ExchangeLogs by query {}] {} ", query, ex.getMessage());
        throw new ExchangeModelException(ex.getMessage());
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) SearchValue(eu.europa.ec.fisheries.uvms.exchange.search.SearchValue) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)

Example 19 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method setPollStatus.

@Override
public ExchangeLogType setPollStatus(PollStatus pollStatus, String username) throws ExchangeModelException {
    ExchangeLogType log = null;
    if (pollStatus == null || pollStatus.getPollGuid() == null) {
        throw new InputArgumentException("No poll id to update status");
    }
    try {
        List<ExchangeLog> exchangeLogByTypesRefAndGuid = logDao.getExchangeLogByTypesRefAndGuid(pollStatus.getPollGuid(), Collections.singletonList(TypeRefType.POLL));
        if (CollectionUtils.isNotEmpty(exchangeLogByTypesRefAndGuid)) {
            List<ExchangeLogStatus> statusList = exchangeLogByTypesRefAndGuid.get(0).getStatusHistory();
            statusList.add(LogMapper.toNewStatusEntity(exchangeLogByTypesRefAndGuid.get(0), pollStatus.getStatus(), username));
            exchangeLogByTypesRefAndGuid.get(0).setStatus(pollStatus.getStatus());
            ExchangeLog retEntity = logDao.updateLog(exchangeLogByTypesRefAndGuid.get(0));
            log = LogMapper.toModel(retEntity);
        }
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when set poll status {} {}] {}", pollStatus, username, ex.getMessage());
        throw new ExchangeModelException("Error when update status of Exchange log ");
    }
    return log;
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 20 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogByGuid.

@Override
public ExchangeLogType getExchangeLogByGuid(String guid) throws ExchangeModelException {
    ExchangeLogType exchangeLogType;
    try {
        ExchangeLog exchangeLog = logDao.getExchangeLogByGuid(guid, null);
        exchangeLogType = LogMapper.toModel(exchangeLog);
        // Enriches the "first level logs" with info related to the related logs.
        enrichDtosWithRelatedLogsInfo(Collections.singletonList(exchangeLogType));
    } catch (Exception e) {
        LOG.error("[ Error when getting exchange log by GUID. {}] {}", guid, e.getMessage());
        exchangeLogType = null;
    }
    return exchangeLogType;
}
Also used : ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Aggregations

ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)39 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)23 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)21 Date (java.util.Date)21 Test (org.junit.Test)21 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)12 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)11 LogRefType (eu.europa.ec.fisheries.schema.exchange.v1.LogRefType)10 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)7 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)7 ArrayList (java.util.ArrayList)5 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)4 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)3 ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)3 ParseException (java.text.ParseException)3 NoResultException (javax.persistence.NoResultException)3 PersistenceException (javax.persistence.PersistenceException)3 SendEmailType (eu.europa.ec.fisheries.schema.exchange.v1.SendEmailType)2 SendMovementType (eu.europa.ec.fisheries.schema.exchange.v1.SendMovementType)2 SendPollType (eu.europa.ec.fisheries.schema.exchange.v1.SendPollType)2