Search in sources :

Example 1 with DmnField

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

the class DmnDeploymentServiceImpl method setDmnField.

private void setDmnField(DecisionTable decisionTable, DmnTable dmnTable) {
    Map<String, DmnField> outputFieldMap = new HashMap<String, DmnField>();
    if (dmnTable.getOutputDmnFieldList() != null) {
        outputFieldMap = dmnTable.getOutputDmnFieldList().stream().collect(Collectors.toMap(DmnField::getName, dmnField -> dmnField));
    }
    dmnTable.clearOutputDmnFieldList();
    for (Output output : decisionTable.getOutputs()) {
        DmnField field = outputFieldMap.get(output.getName());
        log.debug("Find output for name: {}, found: {}", output.getName(), field);
        if (field == null) {
            field = new DmnField(output.getName());
            field.setOutputDmnTable(dmnTable);
        } else {
            field.setName(output.getName());
        }
        field.setFieldType(output.getTypeRef());
        dmnTable.addOutputDmnFieldListItem(field);
    }
}
Also used : DmnField(com.axelor.apps.bpm.db.DmnField) HashMap(java.util.HashMap) Output(org.camunda.bpm.model.dmn.instance.Output)

Example 2 with DmnField

use of com.axelor.apps.bpm.db.DmnField 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)

Aggregations

DmnField (com.axelor.apps.bpm.db.DmnField)2 HashMap (java.util.HashMap)2 DmnTable (com.axelor.apps.bpm.db.DmnTable)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 Output (org.camunda.bpm.model.dmn.instance.Output)1