Search in sources :

Example 1 with DmnTable

use of com.axelor.apps.bpm.db.DmnTable in project axelor-open-suite by axelor.

the class DmnServiceImpl method executeDmn.

@Override
@Transactional
public void executeDmn(String decisionDefinitionId, Model model) throws AxelorException {
    ProcessEngine processEngine = Beans.get(ProcessEngineService.class).getEngine();
    FullContext context = new FullContext(model);
    String varName = Beans.get(WkfCommonService.class).getVarName(EntityHelper.getEntity(model));
    Map<String, Object> modelMap = new HashMap<String, Object>();
    modelMap.put(varName, context);
    DmnDecisionTableResult dmnDecisionTableResult = processEngine.getDecisionService().evaluateDecisionTableByKey(decisionDefinitionId, modelMap);
    List<Map<String, Object>> result = dmnDecisionTableResult.getResultList();
    DmnTable dmnTable = Beans.get(DmnTableRepository.class).all().filter("self.decisionId = ?1", decisionDefinitionId).fetchOne();
    if (dmnTable != null) {
        Map<String, Object> res = result.get(0);
        for (DmnField dmnField : dmnTable.getOutputDmnFieldList()) {
            if (dmnField.getField() != null) {
                addValue(context, dmnField.getField(), res.get(dmnField.getName()), model);
            }
        }
    }
    JpaRepository.of(EntityHelper.getEntityClass(model)).save(model);
}
Also used : DmnDecisionTableResult(org.camunda.bpm.dmn.engine.DmnDecisionTableResult) DmnField(com.axelor.apps.bpm.db.DmnField) ProcessEngineService(com.axelor.apps.bpm.service.init.ProcessEngineService) HashMap(java.util.HashMap) DmnTableRepository(com.axelor.apps.bpm.db.repo.DmnTableRepository) FullContext(com.axelor.apps.tool.context.FullContext) DmnTable(com.axelor.apps.bpm.db.DmnTable) HashMap(java.util.HashMap) Map(java.util.Map) WkfCommonService(com.axelor.apps.bpm.service.WkfCommonService) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) Transactional(com.google.inject.persist.Transactional)

Example 2 with DmnTable

use of com.axelor.apps.bpm.db.DmnTable in project axelor-open-suite by axelor.

the class DmnDeploymentServiceImpl method setDecisionTables.

private void setDecisionTables(WkfDmnModel wkfDmnModel, DmnModelInstance dmnModelInstance) {
    Map<String, DmnTable> dmnTableMap = new HashMap<String, DmnTable>();
    if (wkfDmnModel.getDmnTableList() != null) {
        dmnTableMap = wkfDmnModel.getDmnTableList().stream().collect(Collectors.toMap(DmnTable::getDecisionId, dmnTable -> dmnTable));
    }
    wkfDmnModel.clearDmnTableList();
    Collection<DecisionTable> tables = dmnModelInstance.getModelElementsByType(DecisionTable.class);
    for (DecisionTable table : tables) {
        String decisionId = table.getParentElement().getAttributeValue("id");
        String decisionName = table.getParentElement().getAttributeValue("name");
        DmnTable dmnTable = dmnTableMap.get(decisionId);
        log.debug("Find decision table for id: {}, found: {}", decisionId, dmnTable);
        if (dmnTable == null) {
            dmnTable = new DmnTable();
            dmnTable.setWkfDmnModel(wkfDmnModel);
        }
        dmnTable.setName(decisionName);
        dmnTable.setDecisionId(decisionId);
        setDmnField(table, dmnTable);
        wkfDmnModel.addDmnTableListItem(dmnTable);
    }
}
Also used : DmnTable(com.axelor.apps.bpm.db.DmnTable) DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) HashMap(java.util.HashMap)

Aggregations

DmnTable (com.axelor.apps.bpm.db.DmnTable)2 HashMap (java.util.HashMap)2 DmnField (com.axelor.apps.bpm.db.DmnField)1 DmnTableRepository (com.axelor.apps.bpm.db.repo.DmnTableRepository)1 WkfCommonService (com.axelor.apps.bpm.service.WkfCommonService)1 ProcessEngineService (com.axelor.apps.bpm.service.init.ProcessEngineService)1 FullContext (com.axelor.apps.tool.context.FullContext)1 Transactional (com.google.inject.persist.Transactional)1 Map (java.util.Map)1 DmnDecisionTableResult (org.camunda.bpm.dmn.engine.DmnDecisionTableResult)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)1