Search in sources :

Example 6 with WkfProcessConfig

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

the class WkfModelController method newInstance.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void newInstance(ActionRequest request, ActionResponse response) {
    try {
        LinkedHashMap<String, Object> _map = (LinkedHashMap<String, Object>) request.getData().get("context");
        WkfProcessConfig config = Beans.get(WkfProcessConfigRepository.class).find(Long.valueOf(((Map) _map.get("processConfig")).get("id").toString()));
        boolean isMetaModel = config.getMetaModel() != null;
        String modelName = isMetaModel ? config.getMetaModel().getName() : config.getMetaJsonModel().getName();
        ActionViewBuilder actionViewBuilder = this.viewNewRecord(modelName, isMetaModel);
        response.setView(actionViewBuilder.map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) WkfProcessConfigRepository(com.axelor.apps.bpm.db.repo.WkfProcessConfigRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with WkfProcessConfig

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

Example 8 with WkfProcessConfig

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

the class WkfCache method initWkfModelCache.

public static void initWkfModelCache() {
    List<WkfProcessConfig> wkfProcessConfigs = JPA.all(WkfProcessConfig.class).fetch();
    Map<Long, String> modelMap = new HashMap<Long, String>();
    modelMap.put(0L, "");
    for (WkfProcessConfig config : wkfProcessConfigs) {
        modelMap.put(config.getId(), config.getModel());
    }
    WKF_MODEL_CACHE.put(BpmTools.getCurentTenant(), modelMap);
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 9 with WkfProcessConfig

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

the class BpmDeploymentServiceImpl method addProcessConfig.

private void addProcessConfig(BpmnModelInstance bpmInstance, WkfProcess process) {
    BaseElement processElement = bpmInstance.getModelElementById(process.getName());
    ExtensionElements extensionElements = processElement.getExtensionElements();
    if (extensionElements == null) {
        return;
    }
    ModelBuilderImpl builderImpl = new ModelBuilderImpl(null);
    ModelElementType processConfigType = builderImpl.defineGenericType("processConfiguration", BpmnParser.CAMUNDA_BPMN_EXTENSIONS_NS);
    List<ModelElementInstance> processConfigElements = extensionElements.getElementsQuery().filterByType(processConfigType).list();
    if (processConfigElements == null || processConfigElements.size() == 0) {
        return;
    }
    ModelElementInstance processConfigElement = processConfigElements.get(0);
    Map<String, WkfProcessConfig> configMap = createConfigMap(process);
    ModelElementType processConfigParamType = builderImpl.defineGenericType("processConfigurationParameter", BpmnParser.CAMUNDA_BPMN_EXTENSIONS_NS);
    Collection<ModelElementInstance> configParams = processConfigElement.getChildElementsByType(processConfigParamType);
    for (ModelElementInstance configParam : configParams) {
        WkfProcessConfig config = getProcessCofig(configMap, configParam);
        config = (WkfProcessConfig) wkfService.addProperties(WkfPropertyMapper.PROCESS_CONFIG_PROPERTIES, config, configParam);
        process.addWkfProcessConfigListItem(config);
    }
}
Also used : ModelBuilderImpl(org.camunda.bpm.model.xml.impl.ModelBuilderImpl) ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) BaseElement(org.camunda.bpm.model.bpmn.instance.BaseElement) ExtensionElements(org.camunda.bpm.model.bpmn.instance.ExtensionElements) WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 10 with WkfProcessConfig

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

the class WkfCommonServiceImpl method findProcessConfig.

protected WkfProcessConfig findProcessConfig(Model model, boolean isActive, int status) {
    List<WkfProcessConfig> configs = wkfProcessConfigRepository.all().filter("(self.metaModel.fullName = ?1 OR self.metaJsonModel.name = ?1) " + "AND self.wkfProcess.wkfModel.statusSelect = ?2 " + "AND self.wkfProcess.wkfModel.isActive is ?3 " + "AND (self.isStartModel is true OR self.processPath is not null)", getModelName(model), status, isActive).order("pathCondition").fetch();
    Map<String, Object> ctxMap = new HashMap<String, Object>();
    ctxMap.put(getVarName(model), new FullContext(model));
    for (WkfProcessConfig config : configs) {
        boolean condition = true;
        if (config.getPathCondition() != null) {
            condition = (boolean) evalExpression(ctxMap, config.getPathCondition());
        }
        if (condition) {
            return config;
        }
    }
    return null;
}
Also used : WkfProcessConfig(com.axelor.apps.bpm.db.WkfProcessConfig) HashMap(java.util.HashMap) FullContext(com.axelor.apps.tool.context.FullContext)

Aggregations

WkfProcessConfig (com.axelor.apps.bpm.db.WkfProcessConfig)13 HashMap (java.util.HashMap)8 WkfProcess (com.axelor.apps.bpm.db.WkfProcess)6 FullContext (com.axelor.apps.tool.context.FullContext)5 ArrayList (java.util.ArrayList)4 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)3 List (java.util.List)3 Map (java.util.Map)3 WkfModel (com.axelor.apps.bpm.db.WkfModel)2 User (com.axelor.auth.db.User)2 Model (com.axelor.db.Model)2 AxelorException (com.axelor.exception.AxelorException)2 RuntimeService (org.camunda.bpm.engine.RuntimeService)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 NodeList (org.w3c.dom.NodeList)2 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)1 WkfProcessConfigRepository (com.axelor.apps.bpm.db.repo.WkfProcessConfigRepository)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1