use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class MapService method getJSON.
private JSONObject getJSON(Response response) throws AxelorException, JSONException {
LOG.debug("Gmap connection status code: {}, message: {}", response.getStatusCode(), response.getStatusMessage());
AppBase appBase = appBaseService.getAppBase();
if (response.getStatusCode() != HttpStatus.SC_OK) {
String msg = String.format("%d: %s", response.getStatusCode(), response.getStatusMessage());
throw new AxelorException(appBase, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, msg);
}
JSONObject json = new JSONObject(response.getContentAsString());
String status = json.getString("status");
if (!"OK".equalsIgnoreCase(status)) {
String msg = json.has("error_message") ? String.format("%s: %s", status, json.getString("error_message")) : status;
throw new AxelorException(appBase, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, msg);
}
return json;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class PartnerPriceListServiceImpl method checkDates.
@Override
public void checkDates(PartnerPriceList partnerPriceList) throws AxelorException {
Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
if (priceListSet == null) {
return;
}
Set<PriceList> sortedPriceListSet = priceListSet.stream().sorted(Comparator.comparing(priceList -> priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN)).collect(Collectors.toSet());
LocalDate beginDate;
LocalDate previousEndDate = LocalDate.MIN;
String previousTitle = "";
for (PriceList priceList : sortedPriceListSet) {
beginDate = priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN;
if (beginDate.compareTo(previousEndDate) < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.PARTNER_PRICE_LIST_DATE_INCONSISTENT), previousTitle.replace("%", "%%"), priceList.getTitle().replace("%", "%%")), partnerPriceList);
}
previousEndDate = priceList.getApplicationEndDate() != null ? priceList.getApplicationEndDate() : LocalDate.MAX;
previousTitle = priceList.getTitle();
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ExpenseController method fillKilometricExpenseProduct.
public void fillKilometricExpenseProduct(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().getParent().asType(Expense.class);
Product expenseProduct = Beans.get(ExpenseService.class).getKilometricExpenseProduct(expense);
logger.debug("Get Kilometric expense product : {}", expenseProduct);
response.setValue("expenseProduct", expenseProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ExpenseController method cancel.
public void cancel(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
ExpenseService expenseService = Beans.get(ExpenseService.class);
expenseService.cancel(expense);
Message message = expenseService.sendCancellationEmail(expense);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ExpenseController method validateAndCompute.
public void validateAndCompute(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
ExpenseService expenseService = Beans.get(ExpenseService.class);
List<Integer> expenseLineListId = new ArrayList<>();
int compt = 0;
for (ExpenseLine expenseLine : expenseService.getExpenseLineList(expense)) {
compt++;
if (expenseLine.getExpenseDate().isAfter(Beans.get(AppBaseService.class).getTodayDate(expense.getCompany()))) {
expenseLineListId.add(compt);
}
}
try {
if (!expenseLineListId.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get("Date can't be in the future for line(s) : %s"), expenseLineListId.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
}
} catch (AxelorException e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
response.setValue("personalExpenseAmount", expenseService.computePersonalExpenseAmount(expense));
response.setValue("advanceAmount", expenseService.computeAdvanceAmount(expense));
if (expense.getKilometricExpenseLineList() != null && !expense.getKilometricExpenseLineList().isEmpty()) {
response.setValue("kilometricExpenseLineList", expense.getKilometricExpenseLineList());
}
compute(request, response);
}
Aggregations