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();
}
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));
}
}
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;
}
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;
}
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;
}
Aggregations