Search in sources :

Example 16 with ExchangeLogType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType in project UVMS-ExchangeModule-APP by UnionVMS.

the class LogMapperTest method toModelWhenEntityIsPollLog.

@Test
public void toModelWhenEntityIsPollLog() {
    Date dateReceived = new Date();
    String guid = "Paradise";
    String senderReceiver = "Chris Martin";
    boolean incoming = true;
    ExchangeLogStatusTypeType status = ExchangeLogStatusTypeType.PROBABLY_TRANSMITTED;
    Date fwdDate = new Date();
    String recipient = "Viva la vida";
    ExchangeLog entity = new ExchangeLog();
    entity.setDateReceived(dateReceived);
    entity.setGuid(guid);
    entity.setSenderReceiver(senderReceiver);
    entity.setTransferIncoming(incoming);
    entity.setStatus(status);
    entity.setFwdDate(fwdDate);
    entity.setRecipient(recipient);
    entity.setType(LogType.SEND_POLL);
    ExchangeLogType model = LogMapper.toModel(entity);
    assertEquals(LogType.SEND_POLL, model.getType());
    assertEquals(dateReceived, model.getDateRecieved());
    assertEquals(guid, model.getGuid());
    assertEquals(senderReceiver, model.getSenderReceiver());
    assertEquals(incoming, model.isIncoming());
    assertEquals(status, model.getStatus());
    assertEquals(fwdDate, ((SendPollType) model).getFwdDate());
    assertEquals(recipient, ((SendPollType) model).getRecipient());
}
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)

Example 17 with ExchangeLogType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelTest method testDataEnrichment.

@Test
@SneakyThrows
public void testDataEnrichment() {
    Mockito.when(logDao.getExchangeLogListSearchCount(Mockito.anyString(), Mockito.anyList())).thenReturn(100L);
    Mockito.when(logDao.getExchangeLogListPaginated(Mockito.any(Integer.class), Mockito.any(Integer.class), Mockito.anyString(), Mockito.anyList())).thenReturn(logs);
    Mockito.when(logDao.getExchangeLogByRangeOfRefGuids(Mockito.anyList())).thenReturn(refLogs);
    ExchangeListQuery query = new ExchangeListQuery();
    ExchangeListPagination pagin = new ExchangeListPagination();
    ExchangeListCriteria exchCrit = new ExchangeListCriteria();
    query.setPagination(pagin);
    pagin.setListSize(10);
    query.setExchangeSearchCriteria(exchCrit);
    ListResponseDto exchangeLogListByQuery = exchangeLogModel.getExchangeLogListByQuery(query);
    List<ExchangeLogType> exchangeLogList = exchangeLogListByQuery.getExchangeLogList();
    ExchangeLogType exchangeLogType1 = exchangeLogList.get(0);
    ExchangeLogType exchangeLogType2 = exchangeLogList.get(1);
    assertTrue(exchangeLogType1.getRelatedLogData().isEmpty());
    assertTrue(!exchangeLogType2.getRelatedLogData().isEmpty());
    System.out.println("Done");
}
Also used : ExchangeListCriteria(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListCriteria) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeListQuery(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListQuery) ExchangeListPagination(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeListPagination) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 18 with ExchangeLogType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method enrichDtosWithRelatedLogsInfo.

private void enrichDtosWithRelatedLogsInfo(List<ExchangeLogType> exchangeLogList) {
    List<String> guids = new ArrayList<>();
    for (ExchangeLogType log : exchangeLogList) {
        guids.add(log.getGuid());
    }
    List<ExchangeLog> relatedLogs = logDao.getExchangeLogByRangeOfRefGuids(guids);
    if (CollectionUtils.isNotEmpty(relatedLogs)) {
        for (ExchangeLog logEntity : relatedLogs) {
            RelatedLogInfo refLogInfo = new RelatedLogInfo();
            refLogInfo.setGuid(logEntity.getGuid());
            refLogInfo.setType(logEntity.getTypeRefType().toString());
            for (ExchangeLogType logType : exchangeLogList) {
                if (StringUtils.equals(logEntity.getTypeRefGuid(), logType.getGuid())) {
                    logType.getRelatedLogData().add(refLogInfo);
                }
            }
        }
    }
}
Also used : RelatedLogInfo(eu.europa.ec.fisheries.schema.exchange.v1.RelatedLogInfo) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 19 with ExchangeLogType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogByGuidAndType.

@Override
public ExchangeLogType getExchangeLogByGuidAndType(String guid, TypeRefType typeRefType) throws ExchangeModelException {
    ExchangeLogType exchangeLogType;
    try {
        ExchangeLog exchangeLogByGuid = logDao.getExchangeLogByGuid(guid, typeRefType);
        exchangeLogType = LogMapper.toModel(exchangeLogByGuid);
    } catch (Exception e) {
        LOG.error("[ Error when getting exchange log by GUID. {}] {}", guid, e.getMessage());
        exchangeLogType = null;
    }
    return exchangeLogType;
}
Also used : ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)

Example 20 with ExchangeLogType

use of eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType in project UVMS-ExchangeModule-APP by UnionVMS.

the class ExchangeLogModelBean method getExchangeLogListByQuery.

@Override
public ListResponseDto getExchangeLogListByQuery(ExchangeListQuery query) throws ExchangeModelException {
    if (query == null) {
        throw new InputArgumentException("Exchange list query is null");
    }
    if (query.getPagination() == null) {
        throw new InputArgumentException("Pagination in Exchange query is null");
    }
    if (query.getExchangeSearchCriteria() == null) {
        throw new InputArgumentException("No search criterias in Exchange query");
    }
    try {
        ListResponseDto response = new ListResponseDto();
        List<ExchangeLogType> exchLogTypes = new ArrayList<>();
        Integer page = query.getPagination().getPage();
        Integer listSize = query.getPagination().getListSize();
        List<SearchValue> searchKeyValues = SearchFieldMapper.mapSearchField(query.getExchangeSearchCriteria().getCriterias());
        String sql = SearchFieldMapper.createSelectSearchSql(searchKeyValues, true, query.getSorting());
        LOG.info("sql:" + sql);
        String countSql = SearchFieldMapper.createCountSearchSql(searchKeyValues, true);
        LOG.info("countSql:" + countSql);
        Long numberMatches = logDao.getExchangeLogListSearchCount(countSql, searchKeyValues);
        List<ExchangeLog> exchangeLogEntityList = logDao.getExchangeLogListPaginated(page, listSize, sql, searchKeyValues);
        for (ExchangeLog entity : exchangeLogEntityList) {
            exchLogTypes.add(LogMapper.toModel(entity));
        }
        // Enriches the "first level logs" with info related to the related logs.
        enrichDtosWithRelatedLogsInfo(exchLogTypes);
        int numberOfPages = (int) (numberMatches / listSize);
        if (numberMatches % listSize != 0) {
            numberOfPages += 1;
        }
        response.setTotalNumberOfPages(numberOfPages);
        response.setCurrentPage(query.getPagination().getPage());
        response.setExchangeLogList(exchLogTypes);
        return response;
    } catch (ExchangeSearchMapperException | ExchangeDaoException | ParseException ex) {
        LOG.error("[ Error when getting ExchangeLogs by query {}] {} ", query, ex.getMessage());
        throw new ExchangeModelException(ex.getMessage());
    }
}
Also used : InputArgumentException(eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeSearchMapperException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeSearchMapperException) ArrayList(java.util.ArrayList) ExchangeLog(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog) ExchangeDaoException(eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException) SearchValue(eu.europa.ec.fisheries.uvms.exchange.search.SearchValue) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException) ParseException(java.text.ParseException) ListResponseDto(eu.europa.ec.fisheries.uvms.exchange.model.dto.ListResponseDto)

Aggregations

ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)43 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)27 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)19 Test (org.junit.Test)19 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)18 Date (java.util.Date)17 LogRefType (eu.europa.ec.fisheries.schema.exchange.v1.LogRefType)13 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)9 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)8 ExchangeModelMarshallException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelMarshallException)8 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)5 NotificationMessage (eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage)5 JMSException (javax.jms.JMSException)5 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)4 ArrayList (java.util.ArrayList)4 PluginType (eu.europa.ec.fisheries.schema.exchange.plugin.types.v1.PluginType)3 SendEmailType (eu.europa.ec.fisheries.schema.exchange.v1.SendEmailType)3 SendMovementType (eu.europa.ec.fisheries.schema.exchange.v1.SendMovementType)3 SendPollType (eu.europa.ec.fisheries.schema.exchange.v1.SendPollType)3 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)3