Search in sources :

Example 16 with Model

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

the class WkfModelServiceImpl method getMetaModelRecords.

@SuppressWarnings("unchecked")
private List<Model> getMetaModelRecords(WkfTaskConfig config, List<String> processInstanceIds, String modelName, User user, String type) {
    LocalDate toDate = LocalDate.now();
    Object[] obj = this.getMetaModelRecordFilter(config, modelName, user);
    Class<Model> klass = (Class<Model>) obj[0];
    String filter = (String) obj[1];
    if (type != null) {
        String deadLinePath = config.getDeadlineFieldPath();
        if (Strings.isNullOrEmpty(deadLinePath)) {
            return new ArrayList<>();
        }
        Property property = Mapper.of(klass).getProperty(deadLinePath.split("\\.")[0]);
        if (property == null) {
            filter += " AND self.attrs." + deadLinePath;
            if (type.equals(TASK_NEXT)) {
                filter += " > '" + toDate + "' AND self.attrs." + deadLinePath + " < '" + toDate.plusDays(7) + "'";
            }
        } else {
            filter += " AND self." + deadLinePath;
            if (type.equals(TASK_NEXT)) {
                filter += " > '" + toDate + "' AND self." + deadLinePath + " < '" + toDate.plusDays(7) + "'";
            }
        }
        if (type.equals(TASK_TODAY)) {
            filter += " = '" + toDate + "'";
        } else if (type.equals(LATE_TASK)) {
            filter += " < '" + toDate + "'";
        }
    }
    return JPA.all(klass).filter(filter).bind("processInstanceIds", processInstanceIds).fetch();
}
Also used : WkfModel(com.axelor.apps.bpm.db.WkfModel) MetaModel(com.axelor.meta.db.MetaModel) Model(com.axelor.db.Model) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Property(com.axelor.db.mapper.Property)

Example 17 with Model

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

the class WkfBamlService method executeBaml.

private void executeBaml(DelegateExecution execution, BamlModel bamlModel) {
    Map<String, Object> context = createContext(execution);
    Model record = Beans.get(BamlService.class).execute(bamlModel, context);
    log.debug("Record created from BAML: {}", record);
    if (record != null) {
        String varName = Beans.get(WkfCommonService.class).getVarName(record);
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put(varName, record);
        execution.getProcessInstance().setVariables(Beans.get(WkfCommonService.class).createVariables(modelMap));
    }
}
Also used : HashMap(java.util.HashMap) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) BamlService(com.axelor.apps.baml.service.BamlService)

Example 18 with Model

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

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

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

the class WkfEmailServiceImpl method createUrl.

@Override
public String createUrl(FullContext wkfContext, String formName) {
    if (wkfContext == null) {
        return "";
    }
    String url = AppSettings.get().getBaseURL();
    Model model = (Model) EntityHelper.getEntity(wkfContext.getTarget());
    if (formName == null) {
        if (model instanceof MetaJsonRecord) {
            formName = "custom-model-" + ((MetaJsonRecord) model).getJsonModel() + "-form";
        } else {
            formName = inflector.dasherize(model.getClass().getSimpleName());
        }
    }
    String action = getAction(formName);
    if (action == null) {
        url += "/#ds/form::" + model.getClass().getName() + "/edit/" + wkfContext.get("id");
    } else {
        url += "/#ds/" + action + "/edit/" + wkfContext.get("id");
    }
    return url;
}
Also used : Model(com.axelor.db.Model) 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