Search in sources :

Example 21 with Model

use of com.axelor.db.Model 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 22 with Model

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

the class WkfRequestListener method processDeleted.

@Transactional
public void processDeleted(BeforeTransactionComplete event, String tenantId) {
    Set<? extends Model> deleted = new HashSet<Model>(event.getDeleted());
    WkfInstanceRepository wkfInstanceRepository = Beans.get(WkfInstanceRepository.class);
    for (Model model : deleted) {
        String modelName = EntityHelper.getEntityClass(model).getName();
        if (WkfCache.WKF_MODEL_CACHE.get(tenantId).containsValue(modelName)) {
            try {
                log.trace("Remove wkf instance of deleted model: {}, id: {}", modelName, model.getId());
                WkfInstance wkfInstance = wkfInstanceRepository.findByInstnaceId(model.getProcessInstanceId());
                if (wkfInstance != null && wkfInstance.getWkfProcess().getWkfProcessConfigList().size() == 1) {
                    wkfInstanceRepository.remove(wkfInstance);
                }
            } catch (Exception e) {
            }
        }
    }
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) Model(com.axelor.db.Model) AxelorException(com.axelor.exception.AxelorException) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 23 with Model

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

the class WkfRequestListener method processUpdated.

private void processUpdated(BeforeTransactionComplete event, String tenantId) throws AxelorException {
    Set<? extends Model> updated = new HashSet<Model>(event.getUpdated());
    for (Model model : updated) {
        String modelName = EntityHelper.getEntityClass(model).getName();
        if (WkfCache.WKF_MODEL_CACHE.get(tenantId).containsValue(modelName)) {
            try {
                log.trace("Eval workflow from updated model: {}, id: {}", modelName, model.getId());
                Beans.get(WkfInstanceService.class).evalInstance(model, null);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    if (!updated.containsAll(event.getUpdated())) {
        processUpdated(event, tenantId);
    }
}
Also used : WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) Model(com.axelor.db.Model) HashSet(java.util.HashSet)

Example 24 with Model

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

the class WkfRequestListener method onRequest.

public void onRequest(@Observes PostAction postAction) throws AxelorException {
    Context context = postAction.getContext();
    if (context == null || postAction.getName().equals("com.axelor.meta.web.MetaController:moreAttrs")) {
        return;
    }
    String signal = (String) context.get("_signal");
    if (signal == null) {
        return;
    }
    Boolean wkfEvaluated = (Boolean) context.get("_wkfEvaluated");
    if (wkfEvaluated != null && wkfEvaluated) {
        return;
    }
    String tenantId = BpmTools.getCurentTenant();
    if (!WkfCache.WKF_MODEL_CACHE.containsKey(tenantId)) {
        WkfCache.initWkfModelCache();
    }
    Map<Long, String> modelMap = WkfCache.WKF_MODEL_CACHE.get(tenantId);
    Class<? extends Model> model = (Class<? extends Model>) context.getContextClass();
    if (modelMap != null && modelMap.containsValue(model.getName())) {
        Long id = (Long) context.get("id");
        if (!WkfCache.WKF_BUTTON_CACHE.containsKey(tenantId)) {
            WkfCache.initWkfButttonCache();
        }
        MultiMap multiMap = WkfCache.WKF_BUTTON_CACHE.get(tenantId);
        if (multiMap != null && multiMap.containsValue(signal) && id != null) {
            try {
                log.trace("Wkf button cache: {}", WkfCache.WKF_BUTTON_CACHE);
                log.trace("Eval wkf from button model: {}, id: {}", model.getName(), id);
                String helpText = Beans.get(WkfInstanceService.class).evalInstance(JPA.find(model, id), signal);
                Object res = postAction.getResult();
                if (res instanceof ActionResponse && helpText != null) {
                    ((ActionResponse) res).setAlert(helpText);
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    context.put("_wkfEvaluated", true);
}
Also used : Context(com.axelor.rpc.Context) WkfInstanceService(com.axelor.apps.bpm.service.execution.WkfInstanceService) ActionResponse(com.axelor.rpc.ActionResponse) MultiMap(org.apache.commons.collections.MultiMap) Model(com.axelor.db.Model)

Example 25 with Model

use of com.axelor.db.Model 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)

Aggregations

Model (com.axelor.db.Model)77 MetaModel (com.axelor.meta.db.MetaModel)22 AxelorException (com.axelor.exception.AxelorException)19 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)16 Context (com.axelor.rpc.Context)15 Transactional (com.google.inject.persist.Transactional)15 List (java.util.List)14 Mapper (com.axelor.db.mapper.Mapper)13 IOException (java.io.IOException)13 File (java.io.File)12 Map (java.util.Map)12 Property (com.axelor.db.mapper.Property)11 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)9 JsonContext (com.axelor.rpc.JsonContext)8 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)7 Strings (com.google.common.base.Strings)7 HashSet (java.util.HashSet)7 FullContext (com.axelor.apps.tool.context.FullContext)6 Beans (com.axelor.inject.Beans)6