Search in sources :

Example 6 with ExchangeLogStatus

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus 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 ExchangeLogStatus

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

the class LogMapper method toNewEntity.

public static ExchangeLog toNewEntity(ExchangeLogType log, String username) {
    ExchangeLog entity = new ExchangeLog();
    switch(log.getType()) {
        case RECEIVE_MOVEMENT:
            entity = toReceiveMovementEntity(log);
            break;
        case SEND_MOVEMENT:
            entity = toSendMovementEntity(log);
            break;
        case SEND_POLL:
            entity = toSendPollEntity(log);
            break;
        case SEND_EMAIL:
            entity = toSendEmailEntity(log);
            break;
        case RECEIVE_FLUX_RESPONSE_MSG:
        case RCV_FLUX_FA_REPORT_MSG:
        case RECEIVE_FA_QUERY_MSG:
        case SEND_FA_QUERY_MSG:
        case SEND_FLUX_FA_REPORT_MSG:
        case SEND_FLUX_RESPONSE_MSG:
            entity.setSource(FLUX);
            break;
    }
    if (username == null) {
        username = "SYSTEM";
    }
    if (log.getTypeRef() != null) {
        entity.setTypeRefGuid(log.getTypeRef().getRefGuid());
        entity.setTypeRefType(log.getTypeRef().getType());
        entity.setTypeRefMessage(log.getTypeRef().getMessage());
    }
    entity.setDateReceived(log.getDateRecieved());
    entity.setSenderReceiver(log.getSenderReceiver());
    ExchangeLogStatusTypeType status = ExchangeLogStatusTypeType.ISSUED;
    if (log.getStatus() != null) {
        status = log.getStatus();
    }
    List<ExchangeLogStatus> statusHistory = new ArrayList<>();
    ExchangeLogStatus statusLog = new ExchangeLogStatus();
    statusLog.setLog(entity);
    statusLog.setStatus(status);
    statusLog.setStatusTimestamp(DateUtils.nowUTC().toDate());
    statusLog.setUpdatedBy(username);
    statusLog.setUpdateTime(DateUtils.nowUTC().toDate());
    statusHistory.add(statusLog);
    entity.setStatus(status);
    if (entity.getTransferIncoming() == null) {
        entity.setTransferIncoming(log.isIncoming());
    }
    entity.setStatusHistory(statusHistory);
    entity.setUpdatedBy(username);
    entity.setUpdateTime(DateUtils.nowUTC().toDate());
    entity.setType(log.getType());
    entity.setDestination(log.getDestination());
    return entity;
}
Also used : ExchangeLogStatusTypeType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Aggregations

ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)7 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)4 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)4 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)3 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)3 ArrayList (java.util.ArrayList)3 ExchangeLogStatusHistoryType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType)2 ExchangeLogStatusType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType)2 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)2 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)1 LogRefType (eu.europa.ec.fisheries.schema.exchange.v1.LogRefType)1 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)1 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NoResultException (javax.persistence.NoResultException)1 PersistenceException (javax.persistence.PersistenceException)1