Search in sources :

Example 91 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class MoveTemplateController method generateMove.

@SuppressWarnings("unchecked")
public void generateMove(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        HashMap<String, Object> moveTemplateTypeMap = (HashMap<String, Object>) context.get("moveTemplateType");
        MoveTemplateType moveTemplateType = Beans.get(MoveTemplateTypeRepository.class).find(Long.parseLong(moveTemplateTypeMap.get("id").toString()));
        HashMap<String, Object> moveTemplateMap = (HashMap<String, Object>) context.get("moveTemplate");
        MoveTemplate moveTemplate = null;
        if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_PERCENTAGE) {
            moveTemplate = Beans.get(MoveTemplateRepository.class).find(Long.parseLong(moveTemplateMap.get("id").toString()));
        }
        List<HashMap<String, Object>> dataList = (List<HashMap<String, Object>>) context.get("dataInputList");
        List<HashMap<String, Object>> moveTemplateList = (List<HashMap<String, Object>>) context.get("moveTemplateSet");
        LocalDate moveDate = null;
        if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_AMOUNT) {
            moveDate = LocalDate.parse((String) context.get("moveDate"), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        LOG.debug("MoveTemplate : {}", moveTemplate);
        LOG.debug("Data inputlist : {}", dataList);
        LOG.debug("Data inputlist : {}", moveTemplateList);
        if ((dataList != null && !dataList.isEmpty()) || (moveTemplateList != null && !moveTemplateList.isEmpty())) {
            List<Long> moveList = Beans.get(MoveTemplateService.class).generateMove(moveTemplateType, moveTemplate, dataList, moveDate, moveTemplateList);
            if (moveList != null && !moveList.isEmpty()) {
                response.setView(ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3)).model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").domain("self.id in (" + Joiner.on(",").join(moveList) + ")").map());
            }
        } else {
            response.setFlash(I18n.get(IExceptionMessage.MOVE_TEMPLATE_4));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) HashMap(java.util.HashMap) MoveTemplateType(com.axelor.apps.account.db.MoveTemplateType) MoveTemplate(com.axelor.apps.account.db.MoveTemplate) LocalDate(java.time.LocalDate) MoveTemplateService(com.axelor.apps.account.service.move.MoveTemplateService) Move(com.axelor.apps.account.db.Move) MoveTemplateTypeRepository(com.axelor.apps.account.db.repo.MoveTemplateTypeRepository) List(java.util.List)

Example 92 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class AppController method bulkInstall.

public void bulkInstall(ActionRequest request, ActionResponse response) throws AxelorException, IOException {
    Context context = request.getContext();
    Set<Map<String, Object>> apps = new HashSet<>();
    Collection<Map<String, Object>> appsSet = (Collection<Map<String, Object>>) context.get("appsSet");
    if (appsSet != null) {
        apps.addAll(appsSet);
    }
    Boolean importDemo = (Boolean) context.get("importDemoData");
    String language = (String) context.get("languageSelect");
    AppRepository appRepository = Beans.get(AppRepository.class);
    List<App> appList = new ArrayList<>();
    for (Map<String, Object> appData : apps) {
        App app = appRepository.find(Long.parseLong(appData.get("id").toString()));
        appList.add(app);
    }
    Beans.get(AppService.class).bulkInstall(appList, importDemo, language);
    response.setFlash(I18n.get(IExceptionMessages.BULK_INSTALL_SUCCESS));
    response.setSignal("refresh-app", true);
}
Also used : Context(com.axelor.rpc.Context) App(com.axelor.apps.base.db.App) AppService(com.axelor.apps.base.service.app.AppService) AppRepository(com.axelor.apps.base.db.repo.AppRepository) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map) HashSet(java.util.HashSet)

Example 93 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class ObjectDataExportController method anonymize.

public void anonymize(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    Long recordId = Long.parseLong(context.get("modelSelectId").toString());
    Long objectDataconfigId = Long.parseLong(context.get("objectDataConfigId").toString());
    ObjectDataConfig objectDataConfig = Beans.get(ObjectDataConfigRepository.class).find(objectDataconfigId);
    Beans.get(ObjectDataAnonymizeService.class).anonymize(objectDataConfig, recordId);
    response.setFlash("Data anonymized successfully");
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) ObjectDataAnonymizeService(com.axelor.apps.base.service.ObjectDataAnonymizeService) ObjectDataConfigRepository(com.axelor.apps.base.db.repo.ObjectDataConfigRepository) ObjectDataConfig(com.axelor.apps.base.db.ObjectDataConfig)

Example 94 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class ImportAdvancedImport method addJsonObjectRecord.

@SuppressWarnings("unchecked")
private void addJsonObjectRecord(Object bean, FileTab fileTab, String fieldName, Map<String, Object> values) {
    String field = Inflector.getInstance().camelize(fieldName, true) + "Set";
    List<Object> recordList;
    Map<String, Object> recordMap = new HashMap<String, Object>();
    recordMap.put("id", ((Model) bean).getId());
    Map<String, Object> jsonContextValues = (Map<String, Object>) values.get("jsonContextValues" + fileTab.getId());
    JsonContext jsonContext = (JsonContext) jsonContextValues.get("jsonContext");
    Context context = (Context) jsonContextValues.get("context");
    if (!jsonContext.containsKey(field)) {
        recordList = new ArrayList<Object>();
    } else {
        recordList = ((List<Object>) jsonContext.get(field)).stream().map(obj -> {
            if (Mapper.toMap(EntityHelper.getEntity(obj)).get("id") != null) {
                Map<String, Object> idMap = new HashMap<String, Object>();
                idMap.put("id", Mapper.toMap(EntityHelper.getEntity(obj)).get("id"));
                return idMap;
            }
            return obj;
        }).collect(Collectors.toList());
    }
    recordList.add(recordMap);
    jsonContext.put(field, recordList);
    fileTab.setAttrs(context.get("attrs").toString());
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 95 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class SaleOrderController method exportSaleOrder.

@SuppressWarnings("unchecked")
public void exportSaleOrder(ActionRequest request, ActionResponse response, boolean proforma, String format) {
    Context context = request.getContext();
    String fileLink;
    String title;
    SaleOrderPrintService saleOrderPrintService = Beans.get(SaleOrderPrintService.class);
    try {
        if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
            List<Long> ids = Lists.transform((List) request.getContext().get("_ids"), new Function<Object, Long>() {

                @Nullable
                @Override
                public Long apply(@Nullable Object input) {
                    return Long.parseLong(input.toString());
                }
            });
            fileLink = saleOrderPrintService.printSaleOrders(ids);
            title = I18n.get("Sale orders");
        } else if (context.get("id") != null) {
            SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
            title = Beans.get(SaleOrderService.class).getFileName(saleOrder);
            fileLink = saleOrderPrintService.printSaleOrder(saleOrder, proforma, format);
            response.setCanClose(true);
            logger.debug("Printing " + title);
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.SALE_ORDER_PRINT));
        }
        response.setView(ActionView.define(title).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderPrintService(com.axelor.apps.sale.service.saleorder.print.SaleOrderPrintService) AxelorException(com.axelor.exception.AxelorException) SaleOrderService(com.axelor.apps.sale.service.saleorder.SaleOrderService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10