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