Search in sources :

Example 1 with MetaAttrs

use of com.axelor.meta.db.MetaAttrs in project axelor-open-suite by axelor.

the class BpmDeploymentServiceImpl method deploy.

@Override
@Transactional
public void deploy(WkfModel wkfModel, Map<String, Map<String, String>> migrationMap) {
    if (wkfModel.getDiagramXml() == null) {
        return;
    }
    this.wkfModel = wkfModel;
    this.migrationMap = migrationMap;
    ProcessEngine engine = Beans.get(ProcessEngineService.class).getEngine();
    String key = wkfModel.getId() + ".bpmn";
    BpmnModelInstance bpmInstance = Bpmn.readModelFromStream(new ByteArrayInputStream(wkfModel.getDiagramXml().getBytes()));
    DeploymentBuilder deploymentBuilder = engine.getRepositoryService().createDeployment().addModelInstance(key, bpmInstance).source(key);
    Set<MetaFile> dmnFiles = wkfModel.getDmnFileSet();
    if (dmnFiles != null) {
        addDmn(deploymentBuilder, dmnFiles);
    }
    Map<String, String> processMap = deployProcess(engine, deploymentBuilder, bpmInstance);
    List<MetaAttrs> metaAttrsList = Beans.get(WkfNodeService.class).extractNodes(wkfModel, bpmInstance, processMap);
    Beans.get(WkfModelRepository.class).save(wkfModel);
    metaAttrsService.saveMetaAttrs(metaAttrsList, wkfModel.getId());
}
Also used : ProcessEngineService(com.axelor.apps.bpm.service.init.ProcessEngineService) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MetaAttrs(com.axelor.meta.db.MetaAttrs) ByteArrayInputStream(java.io.ByteArrayInputStream) WkfModelRepository(com.axelor.apps.bpm.db.repo.WkfModelRepository) MetaFile(com.axelor.meta.db.MetaFile) DeploymentBuilder(org.camunda.bpm.engine.repository.DeploymentBuilder) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) Transactional(com.google.inject.persist.Transactional)

Example 2 with MetaAttrs

use of com.axelor.meta.db.MetaAttrs in project axelor-open-suite by axelor.

the class MetaAttrsServiceImpl method saveMetaAttrs.

@Override
@Transactional
public void saveMetaAttrs(List<MetaAttrs> metaAttrsList, Long wkfModelId) {
    List<Long> metaAttrsIds = new ArrayList<Long>();
    metaAttrsIds.add(0L);
    for (MetaAttrs metaAttrs : metaAttrsList) {
        MetaAttrs saved = findMetaAttrs(metaAttrs, wkfModelId);
        log.debug("Creating meta attrs: {}", saved);
        saved.setValue(metaAttrs.getValue());
        saved.setRoles(metaAttrs.getRoles());
        metaAttrsRepository.save(saved);
        metaAttrsIds.add(saved.getId());
    }
    long attrsRemoved = Query.of(MetaAttrs.class).filter("self.id not in ?1 and self.wkfModelId = ?2", metaAttrsIds, wkfModelId.toString()).remove();
    log.debug("Total meta attrs removed: {}", attrsRemoved);
}
Also used : MetaAttrs(com.axelor.meta.db.MetaAttrs) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 3 with MetaAttrs

use of com.axelor.meta.db.MetaAttrs in project axelor-open-suite by axelor.

the class WkfNodeService method extractNodes.

public List<MetaAttrs> extractNodes(WkfModel wkfModel, BpmnModelInstance bpmInstance, Map<String, String> processMap) {
    Map<String, WkfTaskConfig> configMap = new HashMap<>();
    if (wkfModel.getWkfTaskConfigList() != null) {
        for (WkfTaskConfig config : wkfModel.getWkfTaskConfigList()) {
            configMap.put(config.getName(), config);
        }
    }
    List<MetaAttrs> metaAttrsList = new ArrayList<MetaAttrs>();
    Collection<FlowNode> activities = new ArrayList<FlowNode>();
    activities.addAll(bpmInstance.getModelElementsByType(Activity.class));
    activities.addAll(bpmInstance.getModelElementsByType(CatchEvent.class));
    activities.addAll(bpmInstance.getModelElementsByType(EndEvent.class));
    if (activities != null) {
        for (FlowNode activity : activities) {
            WkfTaskConfig config = updateTaskConfig(wkfModel, configMap, metaAttrsList, activity);
            Process process = findProcess(activity);
            if (process != null) {
                config.setProcessId(processMap.get(process.getId()));
            }
            updateMenus(config, false);
            wkfModel.addWkfTaskConfigListItem(config);
        }
    }
    for (String name : configMap.keySet()) {
        updateMenus(configMap.get(name), true);
        wkfModel.removeWkfTaskConfigListItem(configMap.get(name));
    }
    return metaAttrsList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Activity(org.camunda.bpm.model.bpmn.instance.Activity) Process(org.camunda.bpm.model.bpmn.instance.Process) CatchEvent(org.camunda.bpm.model.bpmn.instance.CatchEvent) WkfTaskConfig(com.axelor.apps.bpm.db.WkfTaskConfig) MetaAttrs(com.axelor.meta.db.MetaAttrs) EndEvent(org.camunda.bpm.model.bpmn.instance.EndEvent) FlowNode(org.camunda.bpm.model.bpmn.instance.FlowNode)

Example 4 with MetaAttrs

use of com.axelor.meta.db.MetaAttrs in project axelor-open-suite by axelor.

the class MetaAttrsServiceImpl method createMetaAttrs.

@Override
public List<MetaAttrs> createMetaAttrs(String taskName, ModelElementInstance modelElementInstance, WkfTaskConfig config, String wkfModelId) {
    List<MetaAttrs> metaAttrsList = new ArrayList<MetaAttrs>();
    Collection<CamundaProperty> properties = modelElementInstance.getChildElementsByType(CamundaProperty.class);
    log.debug("Extension elements: {}", properties.size());
    String model = null;
    String view = null;
    String item = null;
    String roles = null;
    String permanent = null;
    for (CamundaProperty property : properties) {
        String name = property.getCamundaName();
        String value = property.getCamundaValue();
        if (name == null) {
            continue;
        }
        log.debug("Processing property: {}, value: {}", name, value);
        switch(name) {
            case "model":
                model = getModel(value);
                view = null;
                item = null;
                roles = null;
                break;
            case "view":
                view = value;
                break;
            case "item":
                item = value;
                break;
            case "roles":
                roles = value;
                break;
            case "modelName":
                break;
            case "modelType":
                break;
            case "itemLabel":
                break;
            case "permanent":
                permanent = value;
                break;
            default:
                if (model != null && item != null) {
                    MetaAttrs metaAttrs = new MetaAttrs();
                    metaAttrs.setModel(model);
                    metaAttrs.setView(view);
                    metaAttrs.setField(item);
                    metaAttrs.setRoles(findRoles(roles));
                    if (permanent != null && permanent.equals("true")) {
                        metaAttrs.setCondition(String.format(META_ATTRS_CONDITION_PERMANENT, taskName));
                    } else {
                        metaAttrs.setCondition(String.format(META_ATTRS_CONDITION, taskName));
                    }
                    metaAttrs.setValue(value);
                    metaAttrs.setName(name);
                    metaAttrs.setWkfModelId(wkfModelId);
                    metaAttrsList.add(metaAttrs);
                }
                break;
        }
    }
    return metaAttrsList;
}
Also used : CamundaProperty(org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty) MetaAttrs(com.axelor.meta.db.MetaAttrs) ArrayList(java.util.ArrayList)

Aggregations

MetaAttrs (com.axelor.meta.db.MetaAttrs)4 ArrayList (java.util.ArrayList)3 Transactional (com.google.inject.persist.Transactional)2 WkfTaskConfig (com.axelor.apps.bpm.db.WkfTaskConfig)1 WkfModelRepository (com.axelor.apps.bpm.db.repo.WkfModelRepository)1 ProcessEngineService (com.axelor.apps.bpm.service.init.ProcessEngineService)1 MetaFile (com.axelor.meta.db.MetaFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 DeploymentBuilder (org.camunda.bpm.engine.repository.DeploymentBuilder)1 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)1 Activity (org.camunda.bpm.model.bpmn.instance.Activity)1 CatchEvent (org.camunda.bpm.model.bpmn.instance.CatchEvent)1 EndEvent (org.camunda.bpm.model.bpmn.instance.EndEvent)1 FlowNode (org.camunda.bpm.model.bpmn.instance.FlowNode)1 Process (org.camunda.bpm.model.bpmn.instance.Process)1 CamundaProperty (org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty)1