Search in sources :

Example 6 with ExchangeLogStatusType

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

the class LogMapper method toStatusModel.

public static ExchangeLogStatusType toStatusModel(ExchangeLog exchangeLog) {
    ExchangeLogStatusType model = new ExchangeLogStatusType();
    if (exchangeLog.getType().equals(LogType.SEND_POLL)) {
        model.setIdentifier(exchangeLog.getRecipient());
    }
    model.setGuid(exchangeLog.getGuid());
    if (exchangeLog.getTypeRefType() != null) {
        LogRefType logRefType = new LogRefType();
        logRefType.setRefGuid(exchangeLog.getTypeRefGuid());
        logRefType.setType(exchangeLog.getTypeRefType());
        logRefType.setMessage(exchangeLog.getTypeRefMessage());
        model.setTypeRef(logRefType);
    }
    if (exchangeLog.getStatusHistory() != null) {
        List<ExchangeLogStatusHistoryType> historyModelList = new ArrayList<>();
        for (ExchangeLogStatus history : exchangeLog.getStatusHistory()) {
            ExchangeLogStatusHistoryType historyModel = new ExchangeLogStatusHistoryType();
            historyModel.setStatus(history.getStatus());
            historyModel.setTimestamp(history.getStatusTimestamp());
            historyModelList.add(historyModel);
        }
        model.getHistory().addAll(historyModelList);
    }
    return model;
}
Also used : ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) ExchangeLogStatusHistoryType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType) ArrayList(java.util.ArrayList) LogRefType(eu.europa.ec.fisheries.schema.exchange.v1.LogRefType) ExchangeLogStatus(eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)

Example 7 with ExchangeLogStatusType

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

the class ExchangeLogServiceBeanTest method updateStatusByLogGuidWhenSuccess.

@Test
public void updateStatusByLogGuidWhenSuccess() throws Exception {
    // data set
    ArgumentCaptor<ExchangeLogStatusType> captorForExchangeLogStatusType = ArgumentCaptor.forClass(ExchangeLogStatusType.class);
    ExchangeLogType expectedUpdatedLog = new ExchangeLogType();
    String logGuid = "123456";
    ExchangeLogStatusTypeType status = ExchangeLogStatusTypeType.SUCCESSFUL;
    // mock
    doReturn(expectedUpdatedLog).when(exchangeLogModel).updateExchangeLogStatus(isA(ExchangeLogStatusType.class), eq("SYSTEM"));
    // execute
    ExchangeLogType actualUpdatedLog = exchangeLogService.updateStatus(logGuid, status);
    // verify and assert
    verify(exchangeLogModel).updateExchangeLogStatus(captorForExchangeLogStatusType.capture(), eq("SYSTEM"));
    assertSame(expectedUpdatedLog, actualUpdatedLog);
    ExchangeLogStatusType capturedExchangeLogStatusType = captorForExchangeLogStatusType.getValue();
    assertEquals(logGuid, capturedExchangeLogStatusType.getGuid());
    assertEquals(1, capturedExchangeLogStatusType.getHistory().size());
    assertEquals(status, capturedExchangeLogStatusType.getHistory().get(0).getStatus());
}
Also used : ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) ExchangeLogStatusTypeType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) Test(org.junit.Test)

Example 8 with ExchangeLogStatusType

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

the class ExchangeLogServiceBean method updateStatus.

@Override
public ExchangeLogType updateStatus(String pluginMessageId, ExchangeLogStatusTypeType logStatus, String username) throws ExchangeLogException {
    try {
        String logGuid = logCache.acknowledged(pluginMessageId);
        ExchangeLogStatusType exchangeLogStatusType = createExchangeLogStatusType(logStatus, logGuid);
        ExchangeLogType updatedLog = exchangeLogModel.updateExchangeLogStatus(exchangeLogStatusType, username);
        sendAuditLogMessageForUpdateExchangeLog(updatedLog.getGuid(), username);
        // For long polling
        exchangeLogEvent.fire(new NotificationMessage("guid", updatedLog.getGuid()));
        return updatedLog;
    } catch (ExchangeModelException e) {
        throw new ExchangeLogException("Couldn't update status of exchange log", e);
    }
}
Also used : ExchangeLogStatusType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType) NotificationMessage(eu.europa.ec.fisheries.uvms.longpolling.notifications.NotificationMessage) ExchangeLogType(eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType) ExchangeLogException(eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException) ExchangeModelException(eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)

Example 9 with ExchangeLogStatusType

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

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

Aggregations

ExchangeLogStatusType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusType)9 ExchangeModelException (eu.europa.ec.fisheries.uvms.exchange.model.exception.ExchangeModelException)5 ArrayList (java.util.ArrayList)4 ExchangeLogStatusHistoryType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusHistoryType)3 ExchangeLogType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogType)3 TypeRefType (eu.europa.ec.fisheries.schema.exchange.v1.TypeRefType)3 ExchangeLogStatus (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLogStatus)3 ExchangeLogStatusTypeType (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeLogStatusTypeType)2 ExchangeLog (eu.europa.ec.fisheries.uvms.exchange.entity.exchangelog.ExchangeLog)2 ExchangeDaoException (eu.europa.ec.fisheries.uvms.exchange.exception.ExchangeDaoException)2 InputArgumentException (eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException)2 ResponseDto (eu.europa.ec.fisheries.uvms.exchange.rest.dto.ResponseDto)2 ExchangeLogException (eu.europa.ec.fisheries.uvms.exchange.service.exception.ExchangeLogException)2 RequiresFeature (eu.europa.ec.fisheries.uvms.rest.security.RequiresFeature)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 LogRefIdByTypeExistsRequest (eu.europa.ec.fisheries.schema.exchange.module.v1.LogRefIdByTypeExistsRequest)1 LogRefIdByTypeExistsResponse (eu.europa.ec.fisheries.schema.exchange.module.v1.LogRefIdByTypeExistsResponse)1 ExchangeHistoryListQuery (eu.europa.ec.fisheries.schema.exchange.v1.ExchangeHistoryListQuery)1