Search in sources :

Example 1 with FullContext

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

the class WkfCommonServiceImpl method findRelatedRecord.

@Override
public Object findRelatedRecord(Model model, String path) throws AxelorException {
    Object object = null;
    FullContext wkfModel = new FullContext(model);
    if (path.startsWith("_find(")) {
        List<String> params = Arrays.asList(path.replace("_find(", "").replace(")", "").split(","));
        if (params.size() >= 2) {
            List<Object> queryParams = params.stream().map(it -> evalExpression(wkfModel, it)).collect(Collectors.toList());
            String queryModel = (String) queryParams.get(0);
            queryParams.remove(0);
            String query = (String) queryParams.get(0);
            queryParams.remove(0);
            log.debug("Find model: {}, query: {}, params: {}", queryModel, query, queryParams);
            object = WkfContextHelper.filterOne(queryModel, query, queryParams.toArray());
        }
    } else {
        object = evalExpression(new FullContext(model), path);
    }
    return object;
}
Also used : MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) Arrays(java.util.Arrays) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Variables(org.camunda.bpm.engine.variable.Variables) EntityHelper(com.axelor.db.EntityHelper) JpaRepository(com.axelor.db.JpaRepository) WkfModelRepository(com.axelor.apps.bpm.db.repo.WkfModelRepository) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Property(com.axelor.db.mapper.Property) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) FullContext(com.axelor.apps.tool.context.FullContext) Strings(com.google.common.base.Strings) AxelorException(com.axelor.exception.AxelorException) Map(java.util.Map) WkfContextHelper(com.axelor.apps.bpm.context.WkfContextHelper) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) JPAVariableSerializer(org.camunda.bpm.engine.impl.variable.serializer.jpa.JPAVariableSerializer) BpmnParser(org.camunda.bpm.engine.impl.bpmn.parser.BpmnParser) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) Collectors(java.util.stream.Collectors) SimpleBindings(javax.script.SimpleBindings) List(java.util.List) WkfProcessConfigRepository(com.axelor.apps.bpm.db.repo.WkfProcessConfigRepository) Context(com.axelor.rpc.Context) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord) SerializationDataFormats(org.camunda.bpm.engine.variable.Variables.SerializationDataFormats) FullContext(com.axelor.apps.tool.context.FullContext)

Example 2 with FullContext

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

the class WkfCommonServiceImpl method createVariables.

@Override
public Map<String, Object> createVariables(Map<String, Object> modelMap) {
    Map<String, Object> varMap = new HashMap<String, Object>();
    for (String name : modelMap.keySet()) {
        Object model = modelMap.get(name);
        if (model == null) {
            varMap.put(name, Variables.objectValue(null, true).create());
            continue;
        }
        ObjectValue var = null;
        Long id = null;
        if (model instanceof Model) {
            var = Variables.objectValue(model, true).serializationDataFormat(JPAVariableSerializer.NAME).create();
            id = ((Model) model).getId();
        } else {
            var = Variables.objectValue(model, true).serializationDataFormat(SerializationDataFormats.JSON).create();
            if (model instanceof FullContext) {
                id = (Long) ((FullContext) model).get("id");
            }
        }
        varMap.put(name, var);
        if (id != null) {
            varMap.put(name + "Id", Variables.longValue(id));
        }
    }
    log.debug("Process variables: {}", varMap);
    return varMap;
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) HashMap(java.util.HashMap) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model)

Example 3 with FullContext

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

the class WkfInstanceServiceImpl method createVariables.

private Map<String, Object> createVariables(String processInstanceId) {
    Map<String, Object> varMap = new HashMap<String, Object>();
    WkfInstance wkfInstance = Beans.get(WkfInstanceRepository.class).findByInstnaceId(processInstanceId);
    if (wkfInstance == null) {
        return varMap;
    }
    for (WkfProcessConfig wkfProcessConfig : wkfInstance.getWkfProcess().getWkfProcessConfigList()) {
        Model model = FullContextHelper.getRepository(wkfProcessConfig.getModel()).all().filter("self.processInstanceId = ?1", processInstanceId).fetchOne();
        if (model == null) {
            continue;
        }
        Object var = Variables.objectValue(new FullContext(model), true).serializationDataFormat(SerializationDataFormats.JSON).create();
        Long id = ((Model) model).getId();
        String varName = wkfService.getVarName(model);
        varMap.put(varName, var);
        varMap.put(varName + "Id", id);
    }
    return varMap;
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) WkfInstance(com.axelor.apps.bpm.db.WkfInstance) FullContext(com.axelor.apps.tool.context.FullContext) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) Model(com.axelor.db.Model)

Example 4 with FullContext

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

the class WkfInstanceServiceImpl method checkSubProcess.

protected void checkSubProcess(Model model) {
    String chldModel = model instanceof MetaJsonRecord ? ((MetaJsonRecord) model).getJsonModel() : model.getClass().getSimpleName();
    List<WkfTaskConfig> taskConfigs = wkfTaskConfigRepository.all().filter("self.callModel = ?1 AND self.callLink IS NOT NULL", chldModel).fetch();
    if (taskConfigs.isEmpty()) {
        return;
    }
    FullContext modelCtx = WkfContextHelper.create(model);
    Map<String, Object> ctxMap = ImmutableMap.of(wkfService.getVarName(model), modelCtx);
    for (WkfTaskConfig taskConfig : taskConfigs) {
        if (!evalCondition(ctxMap, taskConfig.getCallLinkCondition())) {
            continue;
        }
        Object parentModel = modelCtx.get(taskConfig.getCallLink());
        if (parentModel != null && parentModel instanceof FullContext) {
            Model parent = (Model) ((FullContext) parentModel).getTarget();
            if (parent.getProcessInstanceId() != null) {
                addChildProcessInstanceId(parent.getProcessInstanceId(), modelCtx, ctxMap);
                break;
            }
        }
    }
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) WkfTaskConfig(com.axelor.apps.bpm.db.WkfTaskConfig) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 5 with FullContext

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

the class WkfTaskServiceImpl method getContext.

protected Map<String, Object> getContext(WkfInstance instance) throws ClassNotFoundException {
    WkfProcess wkfProcess = instance.getWkfProcess();
    Map<String, Object> modelMap = new HashMap<>();
    for (WkfProcessConfig processConfig : wkfProcess.getWkfProcessConfigList()) {
        Model model = null;
        String klassName;
        if (processConfig.getMetaJsonModel() != null) {
            klassName = MetaJsonRecord.class.getName();
        } else {
            klassName = processConfig.getMetaModel().getFullName();
        }
        @SuppressWarnings("unchecked") final Class<? extends Model> klass = (Class<? extends Model>) Class.forName(klassName);
        String query = "self.processInstanceId = ?";
        if (processConfig.getMetaJsonModel() != null) {
            query += " AND self.jsonModel = '" + processConfig.getMetaJsonModel().getName() + "'";
        }
        if (model == null)
            model = JpaRepository.of(klass).all().filter(query, instance.getInstanceId()).order("-id").fetchOne();
        if (model != null) {
            model = EntityHelper.getEntity(model);
            String name = wkfService.getVarName(model);
            modelMap.put(name, new FullContext(model));
        } else {
            log.debug("Model not found with processInstanceId: {}", instance.getInstanceId());
        }
    }
    log.debug("Variable map used: {}", modelMap);
    return modelMap;
}
Also used : WkfProcess(com.axelor.apps.bpm.db.WkfProcess) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) 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