Search in sources :

Example 1 with ActionResponse

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);
    }
}
Also used : List(java.util.List) ActionHandler(com.axelor.meta.ActionHandler) HashMap(java.util.HashMap) Map(java.util.Map) ActionResponse(com.axelor.rpc.ActionResponse)

Example 2 with ActionResponse

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);
    }
}
Also used : SortedSet(java.util.SortedSet) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) HashMap(java.util.HashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Partner(com.axelor.apps.base.db.Partner) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) RoundingMode(java.math.RoundingMode) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ActionResponse

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;
}
Also used : Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) ActionResponse(com.axelor.rpc.ActionResponse) Template(com.axelor.apps.message.db.Template) CallMethod(com.axelor.meta.CallMethod)

Example 4 with ActionResponse

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);
}
Also used : Context(com.axelor.rpc.Context) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) ActionResponse(com.axelor.rpc.ActionResponse) MultiMap(org.apache.commons.collections.MultiMap) Model(com.axelor.db.Model)

Example 5 with ActionResponse

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Aggregations

ActionResponse (com.axelor.rpc.ActionResponse)19 Context (com.axelor.rpc.Context)17 List (java.util.List)17 Beans (com.axelor.inject.Beans)16 ActionRequest (com.axelor.rpc.ActionRequest)16 TraceBackService (com.axelor.exception.service.TraceBackService)15 Singleton (com.google.inject.Singleton)15 I18n (com.axelor.i18n.I18n)14 ArrayList (java.util.ArrayList)14 AxelorException (com.axelor.exception.AxelorException)13 ActionView (com.axelor.meta.schema.actions.ActionView)13 BigDecimal (java.math.BigDecimal)13 Map (java.util.Map)13 Product (com.axelor.apps.base.db.Product)12 Collectors (java.util.stream.Collectors)12 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)11 StringTool (com.axelor.apps.tool.StringTool)10 ObjectUtils (com.axelor.common.ObjectUtils)10 MethodHandles (java.lang.invoke.MethodHandles)10 Logger (org.slf4j.Logger)10