use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ActionServiceImpl method apply.
@SuppressWarnings("unchecked")
protected void apply(String actions) {
ActionHandler handler = createHandler(actions);
Object value = handler.execute();
ActionResponse response = (ActionResponse) value;
List<Map<String, Object>> dataList = (List<Map<String, Object>>) response.getData();
for (Map<String, Object> map : dataList) {
updateContext(map);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class PartnerSaleController method displayValues.
public void displayValues(ActionRequest request, ActionResponse response) {
Partner customer = request.getContext().asType(Partner.class);
try {
customer = Beans.get(PartnerRepository.class).find(customer.getId());
SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
if (productList.isEmpty()) {
response.setAttr("$saleDetailsByProduct", "hidden", true);
return;
}
response.setAttr("$saleDetailsByProduct", "hidden", false);
HashMap<String, BigDecimal> qtyAndPrice;
for (Product product : productList) {
qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", product.getName());
map.put("$quantitySold", qtyAndPrice.get("qty"));
map.put("$totalPrice", qtyAndPrice.get("price"));
map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
saleDetailsByProduct.add(map);
}
response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ActionEmailBuilderService method sendEmail.
@CallMethod
public ActionResponse sendEmail(Long objectId, String model, String tag, Long templateId, int sendOption) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
Template template = templateRepo.find(templateId);
Message message = templateMessageService.generateMessage(objectId, model, tag, template);
ActionResponse response = new ActionResponse();
if (sendOption == 0) {
messageService.sendByEmail(message);
} else {
response.setView(ActionView.define(I18n.get(IExceptionMessage.MESSAGE_3)).model(Message.class.getName()).add("form", "message-form").param("forceEdit", "true").context("_showRecord", message.getId().toString()).map());
}
return response;
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class WkfRequestListener method onRequest.
public void onRequest(@Observes PostAction postAction) throws AxelorException {
Context context = postAction.getContext();
if (context == null || postAction.getName().equals("com.axelor.meta.web.MetaController:moreAttrs")) {
return;
}
String signal = (String) context.get("_signal");
if (signal == null) {
return;
}
Boolean wkfEvaluated = (Boolean) context.get("_wkfEvaluated");
if (wkfEvaluated != null && wkfEvaluated) {
return;
}
String tenantId = BpmTools.getCurentTenant();
if (!WkfCache.WKF_MODEL_CACHE.containsKey(tenantId)) {
WkfCache.initWkfModelCache();
}
Map<Long, String> modelMap = WkfCache.WKF_MODEL_CACHE.get(tenantId);
Class<? extends Model> model = (Class<? extends Model>) context.getContextClass();
if (modelMap != null && modelMap.containsValue(model.getName())) {
Long id = (Long) context.get("id");
if (!WkfCache.WKF_BUTTON_CACHE.containsKey(tenantId)) {
WkfCache.initWkfButttonCache();
}
MultiMap multiMap = WkfCache.WKF_BUTTON_CACHE.get(tenantId);
if (multiMap != null && multiMap.containsValue(signal) && id != null) {
try {
log.trace("Wkf button cache: {}", WkfCache.WKF_BUTTON_CACHE);
log.trace("Eval wkf from button model: {}, id: {}", model.getName(), id);
String helpText = Beans.get(WkfInstanceService.class).evalInstance(JPA.find(model, id), signal);
Object res = postAction.getResult();
if (res instanceof ActionResponse && helpText != null) {
((ActionResponse) res).setAlert(helpText);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
context.put("_wkfEvaluated", true);
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ManufOrderController method generateMultiLevelManufOrder.
/**
* Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
if (prodProductList.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
}
List<Product> selectedProductList = new ArrayList<>();
for (ProdProduct prod : prodProductList) {
if (selectedProductList.contains(prod.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
}
selectedProductList.add(prod.getProduct());
}
List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations