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 ");
}
}
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;
}
Aggregations