Search in sources :

Example 21 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogDaoBean method getExchangeLogByTypesRefAndGuid.

@Override
public List<ExchangeLog> getExchangeLogByTypesRefAndGuid(String typeRefGuid, List<TypeRefType> types) throws ExchangeDaoException {
    try {
        TypedQuery<ExchangeLog> namedQuery = em.createNamedQuery(ExchangeConstants.LOG_BY_TYPE_REF_AND_GUID, ExchangeLog.class);
        namedQuery.setParameter("typeRefGuid", typeRefGuid);
        namedQuery.setParameter("typeRefTypes", types);
        return namedQuery.getResultList();
    } catch (NoResultException e) {
        LOG.error("[ Error when getting entity by type ref ID. ] {}", e.getMessage());
        throw new NoEntityFoundException("[ Error when getting entity by type ref ID. ]");
    } catch (Exception e) {
        LOG.error("[ Error when getting entity by type ref ID. ] {}", e.getMessage());
        throw new ExchangeDaoException("[ Error when getting entity by type ref ID. ] ");
    }
}
Also used : ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) NoResultException(javax.persistence.NoResultException) NoResultException(javax.persistence.NoResultException) NoEntityFoundException(eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) PersistenceException(javax.persistence.PersistenceException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 22 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog 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);
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeLogStatusHistoryType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 23 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog 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 ");
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) TypeRefType(eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) HashSet(java.util.HashSet)

Example 24 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogRawXmlByGuid.

@Override
public LogWithRawMsgAndType getExchangeLogRawXmlByGuid(String guid) {
    LogWithRawMsgAndType logWrapper = new LogWithRawMsgAndType();
    try {
        ExchangeLog exchangeLog = logDao.getExchangeLogByGuid(guid);
        String rawMsg = exchangeLog.getTypeRefMessage();
        TypeRefType type = exchangeLog.getTypeRefType();
        logWrapper.setRawMsg(rawMsg);
        logWrapper.setType(type);
    } catch (ExchangeDaoException e) {
        LOG.error("[ERROR] Couldn't find Log with the following GUID : [[" + guid + "]]", e);
    }
    return logWrapper;
}
Also used : LogWithRawMsgAndType(eu.europa.ec.fisheries.schema.exchange.v1.LogWithRawMsgAndType) TypeRefType(eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 25 with ExchangeLog

use of eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog in project UVMS-ExchangeModule-APP by UnionVMS.

the class LogMapperTest method toNewEntityWhenLogTypeIsReceiveSalesReportAndUsernameIsNull.

@Test
public void toNewEntityWhenLogTypeIsReceiveSalesReportAndUsernameIsNull() throws Exception {
    // data set
    Date dateReceived = new Date();
    String senderOrReceiver = "BEL";
    ExchangeLogStatusTypeType status = ExchangeLogStatusTypeType.SUCCESSFUL;
    String destination = "destination";
    ExchangeLogType input = new ExchangeLogType();
    input.setType(LogType.RECEIVE_SALES_REPORT);
    input.setDateRecieved(dateReceived);
    input.setSenderReceiver(senderOrReceiver);
    input.setStatus(status);
    input.setIncoming(true);
    input.setDestination(destination);
    // execute
    ExchangeLog result = LogMapper.toNewEntity(input, null);
    // assert
    assertEquals(dateReceived, result.getDateReceived());
    assertEquals(senderOrReceiver, result.getSenderReceiver());
    assertEquals(status, result.getStatus());
    assertEquals(1, result.getStatusHistory().size());
    assertEquals(result, result.getStatusHistory().get(0).getLog());
    assertEquals(status, result.getStatusHistory().get(0).getStatus());
    assertNotNull(result.getStatusHistory().get(0).getStatusTimestamp());
    assertEquals("SYSTEM", result.getStatusHistory().get(0).getUpdatedBy());
    assertNotNull(result.getStatusHistory().get(0).getUpdateTime());
    assertEquals("SYSTEM", result.getUpdatedBy());
    assertNotNull(result.getUpdateTime());
    assertTrue(result.getTransferIncoming());
    assertEquals(LogType.RECEIVE_SALES_REPORT, result.getType());
    assertEquals(destination, result.getDestination());
}
Also used : ExchangeLogStatusTypeType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) Date(java.util.Date) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) Test(org.junit.Test)

Aggregations

ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)39 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)23 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)21 Date (java.util.Date)21 Test (org.junit.Test)21 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)12 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)11 LogRefType (eu.europa.ec.fisheries.schema.exchange.v1.LogRefType)10 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)7 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)7 ArrayList (java.util.ArrayList)5 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)4 NoEntityFoundException (eu.europa.ec.fisheries.uvms.exchange.exception.NoEntityFoundException)3 ExchangeSearchMapperException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException)3 ParseException (java.text.ParseException)3 NoResultException (javax.persistence.NoResultException)3 PersistenceException (javax.persistence.PersistenceException)3 SendEmailType (eu.europa.ec.fisheries.schema.exchange.v1.SendEmailType)2 SendMovementType (eu.europa.ec.fisheries.schema.exchange.v1.SendMovementType)2 SendPollType (eu.europa.ec.fisheries.schema.exchange.v1.SendPollType)2