Search in sources :

Example 31 with ExchangeLogStatusTypeType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType 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;
}
Also used : ExchangeLogStatusTypeType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Aggregations

ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)27 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)21 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)21 Test (org.junit.Test)21 Date (java.util.Date)20 LogRefType (eu.europa.ec.fisheries.schema.exchange.v1.LogRefType)11 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)10 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)7 ExchangeLogStatusType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType)4 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)3 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)3 NotificationMessage (eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage)3 ArrayList (java.util.ArrayList)3 ExchangeMessageException (eu.europa.ec.fisheries.uvms.exchange.message.exception.ExchangeMessageException)2 SendSalesReportRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendSalesReportRequest)1 SendSalesResponseRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.SendSalesResponseRequest)1 UpdateLogStatusRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.UpdateLogStatusRequest)1 ExchangeHistoryListQuery (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeHistoryListQuery)1 ExchangeLogStatusHistoryType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType)1 PollStatus (eu.europa.ec.fisheries.schema.exchange.v1.PollStatus)1