Search in sources :

Example 6 with FullContext

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

the class WkfUserActionServiceImpl method getModelCtx.

@Override
public FullContext getModelCtx(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException {
    String modelName = null;
    Class<? extends Model> modelClass = null;
    if (wkfTaskConfig.getModelName() != null) {
        modelName = wkfTaskConfig.getModelName();
        modelClass = (Class<? extends Model>) Class.forName(Beans.get(MetaModelRepository.class).findByName(modelName).getFullName());
    } else if (wkfTaskConfig.getJsonModelName() != null) {
        modelName = wkfTaskConfig.getJsonModelName();
        modelClass = MetaJsonRecord.class;
    } else {
        return null;
    }
    String varName = wkfService.getVarName(modelName);
    Object id = execution.getVariable(varName + "Id");
    FullContext wkfContext = null;
    if (id != null && id instanceof Long) {
        Model record = JPA.find(modelClass, Long.parseLong(id.toString()));
        wkfContext = new FullContext(record);
    }
    return wkfContext;
}
Also used : MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 7 with FullContext

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

the class DmnServiceImpl method findResult.

private Object findResult(Object value, String subField, String targetModel, boolean isCollection, boolean isSet) throws AxelorException {
    Object params = getParameter(value);
    String query = getQuery(subField, params instanceof Collection);
    log.debug("Find result for: {} , value: {}, targetModel: {}", subField, value, targetModel);
    if (isCollection) {
        Collection resultCollection = null;
        if (isSet) {
            resultCollection = new HashSet<>();
        } else {
            resultCollection = new ArrayList<>();
        }
        if (params == null) {
            return resultCollection;
        }
        for (FullContext res : FullContextHelper.filter(targetModel, query, params)) {
            resultCollection.add(res.getTarget());
        }
        return resultCollection;
    }
    if (params == null) {
        return null;
    }
    return WkfContextHelper.filterOne(targetModel, query, params).getTarget();
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Collection(java.util.Collection)

Example 8 with FullContext

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

the class AxelorScriptEngine method eval.

@Override
public Object eval(String script, ScriptContext ctx) {
    Bindings bindings = ctx.getBindings(ctx.getScopes().get(0));
    bindings.put("$json", Beans.get(MetaJsonRecordRepository.class));
    bindings.put("$ctx", WkfContextHelper.class);
    bindings.put("$beans", Beans.class);
    bindings.put("__user__", new FullContext(AuthUtils.getUser()));
    return new GroovyScriptHelper(bindings).eval(script);
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) MetaJsonRecordRepository(com.axelor.meta.db.repo.MetaJsonRecordRepository) Bindings(javax.script.Bindings) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

Example 9 with FullContext

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

the class AppLoaderExportServiceImpl method addMetaModelData.

protected void addMetaModelData(AppDataLoader dataLoader, File parentDir) {
    try {
        Class klass = Class.forName(dataLoader.getMetaModel().getFullName());
        if (!allowRead(klass)) {
            return;
        }
        Mapper modelMapper = Mapper.of(klass);
        String modelName = dataLoader.getMetaModel().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());
        for (FullContext record : records) {
            if (!allowRead(klass, (Long) record.get("id"))) {
                continue;
            }
            fileWriter.write("<" + dasherizeModel + ">\n");
            for (MetaField metaField : dataLoader.getMetaFieldSet()) {
                String field = metaField.getName();
                fileWriter.write("\t<" + field + ">" + extractMetaFieldValue(record, modelMapper.getProperty(field)) + "</" + field + ">\n");
            }
            fileWriter.write("</" + dasherizeModel + ">\n\n");
        }
        fileWriter.write("</" + dasherizeModel + "s>\n");
        fileWriter.close();
    } catch (IOException | ClassNotFoundException e) {
        TraceBackService.trace(e);
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaField(com.axelor.meta.db.MetaField) FileWriter(java.io.FileWriter) FullContext(com.axelor.apps.tool.context.FullContext) IOException(java.io.IOException) File(java.io.File)

Example 10 with FullContext

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

the class ValueMapperService method execute.

public Object execute(ValueMapper mapper, Model model) {
    if (model == null || mapper == null) {
        return null;
    }
    String modelName = getModelVariable(model);
    Bindings bindings = new SimpleBindings();
    bindings.put("$ctx", FullContextHelper.class);
    bindings.put(modelName, new FullContext(model));
    bindings.put(modelName + "Id", model.getId());
    Object result = new GroovyScriptHelper(bindings).eval(mapper.getScript());
    return result;
}
Also used : SimpleBindings(javax.script.SimpleBindings) FullContext(com.axelor.apps.tool.context.FullContext) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

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