use of eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogModelBean method createExchangeLog.
@Override
public ExchangeLogType createExchangeLog(ExchangeLogType log, String username) throws ExchangeModelException {
if (log == null) {
throw new InputArgumentException("No log to create");
}
if (log.getType() == null) {
throw new InputArgumentException("No type in log to create");
}
try {
ExchangeLog exchangeLog = LogMapper.toNewEntity(log, username);
ExchangeLog persistedLog = logDao.createLog(exchangeLog);
return LogMapper.toModel(persistedLog);
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when creating Exchange log {} {}] {}", log, username, ex.getMessage());
throw new ExchangeModelException("Error when creating Exchange log ");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException 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());
}
}
use of eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException in project UVMS-ExchangeModule-APP by UnionVMS.
the class ExchangeLogModelBean method setPollStatus.
@Override
public ExchangeLogType setPollStatus(PollStatus pollStatus, String username) throws ExchangeModelException {
ExchangeLogType log = null;
if (pollStatus == null || pollStatus.getPollGuid() == null) {
throw new InputArgumentException("No poll id to update status");
}
try {
List<ExchangeLog> exchangeLogByTypesRefAndGuid = logDao.getExchangeLogByTypesRefAndGuid(pollStatus.getPollGuid(), Collections.singletonList(TypeRefType.POLL));
if (CollectionUtils.isNotEmpty(exchangeLogByTypesRefAndGuid)) {
List<ExchangeLogStatus> statusList = exchangeLogByTypesRefAndGuid.get(0).getStatusHistory();
statusList.add(LogMapper.toNewStatusEntity(exchangeLogByTypesRefAndGuid.get(0), pollStatus.getStatus(), username));
exchangeLogByTypesRefAndGuid.get(0).setStatus(pollStatus.getStatus());
ExchangeLog retEntity = logDao.updateLog(exchangeLogByTypesRefAndGuid.get(0));
log = LogMapper.toModel(retEntity);
}
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when set poll status {} {}] {}", pollStatus, username, ex.getMessage());
throw new ExchangeModelException("Error when update status of Exchange log ");
}
return log;
}
use of eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException in project UVMS-ExchangeModule-APP by UnionVMS.
the class UnsentModelBean method resend.
@Override
public List<UnsentMessageType> resend(List<String> unsentMessageId) throws ExchangeModelException {
if (unsentMessageId == null) {
throw new InputArgumentException("No messageList to resend");
}
try {
List<UnsentMessageType> unsentMessageList = new ArrayList<>();
for (String messageId : unsentMessageId) {
try {
UnsentMessage message = dao.getByGuid(messageId);
UnsentMessage removedMessage = dao.remove(message);
unsentMessageList.add(UnsentMessageMapper.toModel(removedMessage));
} catch (NoEntityFoundException e) {
LOG.error("Couldn't find message to resend with guid: " + messageId);
}
}
return unsentMessageList;
} catch (ExchangeDaoException ex) {
LOG.error("[ Error when resending message message list ] {}", ex.getMessage());
throw new ExchangeModelException("Error when resending unsent message list");
}
}
use of eu.europa.ec.fisheries.uvms.exchange.model.exception.InputArgumentException 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);
}
}
Aggregations