Search in sources :

Example 26 with Context

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

the class WkfModelController method showRecord.

@SuppressWarnings("unchecked")
public void showRecord(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        String status = context.get("status").toString();
        String tableName = null;
        String jsonModel = null;
        ActionViewBuilder actionViewBuilder = null;
        if (context.get("metaModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaModel")).get("id").toString());
            MetaModel metaModel = Beans.get(MetaModelRepository.class).find(id);
            tableName = metaModel.getTableName();
            actionViewBuilder = createActionBuilder(status, metaModel);
        } else if (context.get("metaJsonModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaJsonModel")).get("id").toString());
            MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).find(id);
            jsonModel = metaJsonModel.getName();
            tableName = MetaJsonRecord.class.getAnnotation(Table.class).name();
            actionViewBuilder = createActionBuilder(status, metaJsonModel);
        }
        List<Long> idList = getRecordIds(context, tableName, jsonModel);
        response.setView(actionViewBuilder.context("ids", !idList.isEmpty() ? idList : 0).map());
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) Table(javax.persistence.Table) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 27 with Context

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

the class WkfModelController method cancelNode.

public void cancelNode(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String processInstanceId = (String) context.get("processInstanceId");
    String activityId = (String) context.get("activityId");
    if (processInstanceId != null && activityId != null) {
        Beans.get(WkfInstanceService.class).cancelNode(processInstanceId, activityId);
    }
    response.setFlash(I18n.get("Node cancelled"));
}
Also used : Context(com.axelor.rpc.Context) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService)

Example 28 with Context

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

the class WkfModelController method restart.

public void restart(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String processInstanceId = (String) context.get("processInstanceId");
    String activityId = (String) context.get("activityId");
    if (processInstanceId != null && activityId != null) {
        Beans.get(WkfInstanceService.class).restart(processInstanceId, activityId);
    }
    response.setFlash(I18n.get("Instance Restarted"));
}
Also used : Context(com.axelor.rpc.Context) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService)

Example 29 with Context

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

the class WkfModelController method deploy.

@SuppressWarnings("unchecked")
public void deploy(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    WkfModel wkfModel = context.asType(WkfModel.class);
    Map<String, Map<String, String>> migrationMap = (Map<String, Map<String, String>>) context.get("wkfMigrationMap");
    Boolean isMigrateOld = (Boolean) context.get("isMigrateOld");
    if (isMigrateOld != null && !isMigrateOld) {
        migrationMap = null;
    }
    wkfModel = wkfModelRepository.find(wkfModel.getId());
    Beans.get(BpmDeploymentService.class).deploy(wkfModel, migrationMap);
    response.setReload(true);
}
Also used : Context(com.axelor.rpc.Context) WkfModel(com.axelor.apps.bpm.db.WkfModel) BpmDeploymentService(com.axelor.apps.bpm.service.deployment.BpmDeploymentService) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with Context

use of com.axelor.rpc.Context 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)

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