use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType 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