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;
}
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());
}
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);
}
}
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);
}
}
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 ");
}
}
Aggregations