Search in sources :

Example 16 with FullContext

use of com.axelor.apps.tool.context.FullContext 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 17 with FullContext

use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.

the class AppLoaderExportServiceImpl method addJsonModelData.

protected void addJsonModelData(AppDataLoader dataLoader, File parentDir) {
    try {
        if (!allowRead(MetaJsonRecord.class)) {
            return;
        }
        String modelName = dataLoader.getJsonModel().getName();
        String dasherizeModel = Inflector.getInstance().dasherize(modelName);
        File dataFile = new File(parentDir, modelName + ".xml");
        FileWriter fileWriter = createHeader(dasherizeModel, dataFile);
        List<FullContext> records = FullContextHelper.filter(modelName, dataLoader.getFilterQuery());
        Map<String, Object> jsonFieldMap = MetaStore.findJsonFields(modelName);
        fixTargetName(jsonFieldMap);
        for (FullContext record : records) {
            if (!allowRead(MetaJsonRecord.class, (Long) record.get("id"))) {
                continue;
            }
            fileWriter.write("<" + dasherizeModel + ">\n");
            for (MetaJsonField jsonField : dataLoader.getJsonFieldSet()) {
                String field = jsonField.getName();
                Map<String, Object> fieldAttrs = (Map<String, Object>) jsonFieldMap.get(field);
                fileWriter.write("\t<" + field + ">" + extractJsonFieldValue(record, fieldAttrs) + "</" + field + ">\n");
            }
            fileWriter.write("</" + dasherizeModel + ">\n\n");
        }
        fileWriter.write("</" + dasherizeModel + "s>\n");
        fileWriter.close();
    } catch (IOException e) {
        TraceBackService.trace(e);
    }
}
Also used : FileWriter(java.io.FileWriter) FullContext(com.axelor.apps.tool.context.FullContext) MetaJsonField(com.axelor.meta.db.MetaJsonField) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 18 with FullContext

use of com.axelor.apps.tool.context.FullContext in project axelor-open-suite by axelor.

the class ValueMapperController method execute.

public void execute(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Map<String, Object> valueMapperMap = (Map<String, Object>) context.get("valueMapper");
    ValueMapper mapper = Beans.get(ValueMapperRepository.class).find(Long.parseLong(valueMapperMap.get("id").toString()));
    if (mapper == null || mapper.getScript() == null) {
        return;
    }
    String modelName = (String) context.get("modelName");
    Model model = null;
    if (context.get("recordId") != null && modelName != null) {
        Long recordId = Long.parseLong(context.get("recordId").toString());
        model = FullContextHelper.getRepository(modelName).find(recordId);
    }
    Object result = Beans.get(ValueMapperService.class).execute(mapper, model);
    if (result != null && result instanceof FullContext && mapper.getScript().startsWith("def rec = $ctx.create(")) {
        FullContext fullContext = (FullContext) result;
        Object object = fullContext.getTarget();
        String title = object.getClass().getSimpleName();
        if (object instanceof MetaJsonRecord) {
            title = ((MetaJsonRecord) object).getJsonModel();
        }
        response.setView(ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form").add("grid").context("_showRecord", fullContext.get("id")).map());
    }
    response.setCanClose(true);
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Context(com.axelor.rpc.Context) ValueMapper(com.axelor.studio.db.ValueMapper) ValueMapperRepository(com.axelor.studio.db.repo.ValueMapperRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) ValueMapperService(com.axelor.studio.service.mapper.ValueMapperService) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Aggregations

FullContext (com.axelor.apps.tool.context.FullContext)18 HashMap (java.util.HashMap)8 Model (com.axelor.db.Model)7 WkfProcessConfig (com.axelor.apps.bpm.db.WkfProcessConfig)6 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)6 Map (java.util.Map)4 GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)3 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)2 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)2 Mapper (com.axelor.db.mapper.Mapper)2 Context (com.axelor.rpc.Context)2 Transactional (com.google.inject.persist.Transactional)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Bindings (javax.script.Bindings)2 SimpleBindings (javax.script.SimpleBindings)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)2 WkfContextHelper (com.axelor.apps.bpm.context.WkfContextHelper)1