use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog 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;
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.
the class LogMapper method toReceiveMovementEntity.
private static ExchangeLog toReceiveMovementEntity(ExchangeLogType type) {
ExchangeLog entity = new ExchangeLog();
entity.setSource(type.getSource());
entity.setTransferIncoming(true);
return entity;
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogDaoBean method getExchangeLogListPaginated.
@Override
public List<ExchangeLog> getExchangeLogListPaginated(Integer page, Integer listSize, String sql, List<SearchValue> searchKeyValues) throws ExchangeDaoException {
try {
LOG.debug("SQL QUERY IN LIST PAGINATED: " + sql);
TypedQuery<ExchangeLog> query = em.createQuery(sql, ExchangeLog.class);
HashMap<ExchangeSearchField, List<SearchValue>> orderedValues = SearchFieldMapper.combineSearchFields(searchKeyValues);
setQueryParameters(query, orderedValues);
query.setFirstResult(listSize * (page - 1));
query.setMaxResults(listSize);
return query.getResultList();
} catch (IllegalArgumentException e) {
LOG.error("[ Error getting exchangelog list paginated ] {}", e.getMessage());
throw new ExchangeDaoException("[ Error when getting list ] ");
} catch (Exception e) {
LOG.error("[ Error getting exchangelog list paginated ] {}", e.getMessage());
throw new ExchangeDaoException("[ Error when getting list ] ");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogDaoBean method getExchangeLogByGuid.
@Override
public ExchangeLog getExchangeLogByGuid(String logGuid, TypeRefType typeRefType) throws ExchangeDaoException {
try {
TypedQuery<ExchangeLog> query = em.createNamedQuery(ExchangeConstants.LOG_BY_GUID, ExchangeLog.class);
query.setParameter("typeRefType", typeRefType);
query.setParameter("guid", logGuid);
return query.getSingleResult();
} catch (NoResultException e) {
LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
throw new NoEntityFoundException("[ Error when getting entity by ID. ]");
} catch (Exception e) {
LOG.error("[ Error when getting entity by ID. ] {}", e.getMessage());
throw new ExchangeDaoException("[ Error when getting entity by ID. ] ");
}
}
Aggregations