Search in sources :

Example 1 with ExchangeLogStatus

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

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

the class LogMapper method toStatusModel.

public static ExchangeLogStatusType toStatusModel(ExchangeLog exchangeLog) {
    ExchangeLogStatusType model = new ExchangeLogStatusType();
    if (exchangeLog.getType().equals(LogType.SEND_POLL)) {
        model.setIdentifier(exchangeLog.getRecipient());
    }
    model.setGuid(exchangeLog.getGuid());
    if (exchangeLog.getTypeRefType() != null) {
        LogRefType logRefType = new LogRefType();
        logRefType.setRefGuid(exchangeLog.getTypeRefGuid());
        logRefType.setType(exchangeLog.getTypeRefType());
        logRefType.setMessage(exchangeLog.getTypeRefMessage());
        model.setTypeRef(logRefType);
    }
    if (exchangeLog.getStatusHistory() != null) {
        List<ExchangeLogStatusHistoryType> historyModelList = new ArrayList<>();
        for (ExchangeLogStatus history : exchangeLog.getStatusHistory()) {
            ExchangeLogStatusHistoryType historyModel = new ExchangeLogStatusHistoryType();
            historyModel.setStatus(history.getStatus());
            historyModel.setTimestamp(history.getStatusTimestamp());
            historyModelList.add(historyModel);
        }
        model.getHistory().addAll(historyModelList);
    }
    return model;
}
Also used : ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) ExchangeLogStatusHistoryType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType) ArrayList(java.util.ArrayList) LogRefType(eu.europa.ec.fisheries.schema.exchange.v1.LogRefType) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 3 with ExchangeLogStatus

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

the class LogMapper method toNewStatusEntity.

public static ExchangeLogStatus toNewStatusEntity(ExchangeLog parent, ExchangeLogStatusTypeType status, String username) {
    ExchangeLogStatus entity = new ExchangeLogStatus();
    entity.setLog(parent);
    entity.setStatus(status);
    entity.setStatusTimestamp(DateUtils.nowUTC().toDate());
    entity.setUpdatedBy(username);
    entity.setUpdateTime(DateUtils.nowUTC().toDate());
    return entity;
}
Also used : ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 4 with ExchangeLogStatus

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

the class ExchangeLogDaoBean method getExchangeLogStatusHistory.

@Override
public List<ExchangeLogStatus> getExchangeLogStatusHistory(String sql, ExchangeHistoryListQuery searchQuery) throws ExchangeDaoException {
    try {
        LOG.debug("SQL query for status history " + sql);
        TypedQuery<ExchangeLogStatus> query = em.createQuery(sql, ExchangeLogStatus.class);
        if (searchQuery.getStatus() != null && !searchQuery.getStatus().isEmpty()) {
            query.setParameter("status", searchQuery.getStatus());
        }
        if (searchQuery.getType() != null && !searchQuery.getType().isEmpty()) {
            query.setParameter("type", searchQuery.getType());
        }
        if (searchQuery.getTypeRefDateFrom() != null) {
            Date from = searchQuery.getTypeRefDateFrom();
            query.setParameter("from", from);
        }
        if (searchQuery.getTypeRefDateTo() != null) {
            Date to = searchQuery.getTypeRefDateTo();
            query.setParameter("to", to);
        }
        return query.getResultList();
    } catch (IllegalArgumentException e) {
        LOG.error("[ Error getting exchangelog status list ] " + e.getMessage());
        throw new ExchangeDaoException("[ Error when getting search list ] ");
    } catch (Exception e) {
        LOG.error("[ Error getting exchangelog status list " + e.getMessage());
        throw new ExchangeDaoException("[ Error when getting search list ] ");
    }
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) Date(java.util.Date) NoResultException(javax.persistence.NoResultException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) PersistenceException(javax.persistence.PersistenceException) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 5 with ExchangeLogStatus

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

the class ExchangeLogModelBean method updateExchangeLogStatus.

@Override
public ExchangeLogType updateExchangeLogStatus(ExchangeLogStatusType status, String username) throws ExchangeModelException {
    if (status == null || status.getGuid() == null || status.getGuid().isEmpty()) {
        throw new InputArgumentException("No exchange log to update status");
    }
    if (status.getHistory() == null || status.getHistory().isEmpty() || status.getHistory().size() != 1) {
        throw new InputArgumentException("Non valid status to update to");
    }
    try {
        ExchangeLogStatusHistoryType updateStatus = status.getHistory().get(0);
        ExchangeLog exchangeLog = logDao.getExchangeLogByGuid(status.getGuid());
        List<ExchangeLogStatus> statusList = exchangeLog.getStatusHistory();
        statusList.add(LogMapper.toNewStatusEntity(exchangeLog, updateStatus.getStatus(), username));
        exchangeLog.setStatus(updateStatus.getStatus());
        ExchangeLog retEntity = logDao.updateLog(exchangeLog);
        ExchangeLogType retType = LogMapper.toModel(retEntity);
        return retType;
    } catch (ExchangeDaoException ex) {
        LOG.error("[ Error when update status of Exchange log {} {}] {}", status, username, ex.getMessage());
        throw new ExchangeModelException("Error when update status of Exchange log", ex);
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeLogStatusHistoryType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType) 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)

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