use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class AdvancedExportController method metaFieldDomain.
public void metaFieldDomain(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
AdvancedExportLine adv = request.getContext().asType(AdvancedExportLine.class);
MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(adv.getCurrentDomain());
List<MetaField> metaFields = metaModel.getMetaFields();
List<Long> metaFieldList = new ArrayList<>();
if (metaFields != null) {
Class<?> klass = Class.forName(metaModel.getFullName());
Mapper mapper = Mapper.of(klass);
for (MetaField field : metaFields) {
if (!mapper.getProperty(field.getName()).isTransient()) {
metaFieldList.add(field.getId());
}
}
}
metaFieldList.add(0L);
response.setAttr("metaField", "domain", "self.id in (" + Joiner.on(",").join(metaFieldList) + ")");
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class BatchTimesheetReminder method process.
@Override
protected void process() {
Template template = batch.getHrBatch().getTemplate();
MetaModel metaModel = template.getMetaModel();
try {
if (metaModel != null) {
if (metaModel.getName().equals(Employee.class.getSimpleName())) {
sendReminderUsingEmployees(template);
} else if (metaModel.getName().equals(Timesheet.class.getSimpleName())) {
sendReminderUsingTimesheets(template);
}
}
} catch (Exception e) {
TraceBackService.trace(e, metaModel.getName(), batch.getId());
incrementAnomaly();
}
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class PrintTemplateLineController method checkTemplateLineExpression.
public void checkTemplateLineExpression(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
PrintTemplateLineTest printTemplateLineTest = context.asType(PrintTemplateLineTest.class);
printTemplateLineTest = Beans.get(PrintTemplateLineTestRepository.class).find(printTemplateLineTest.getId());
MetaModel metaModel = Beans.get(MetaModelRepository.class).all().filter("self.fullName = ?", printTemplateLineTest.getReference()).fetchOne();
try {
Beans.get(PrintTemplateLineService.class).checkExpression(Long.valueOf(printTemplateLineTest.getReferenceId().toString()), metaModel, printTemplateLineTest.getPrintTemplateLine());
} catch (NumberFormatException | ClassNotFoundException | AxelorException | IOException e) {
TraceBackService.trace(response, e);
}
response.setReload(true);
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class PrintTemplateLineController method addItemToReferenceSelection.
@SuppressWarnings("unchecked")
public void addItemToReferenceSelection(ActionRequest request, ActionResponse response) {
LinkedHashMap<String, Object> metaModelMap = (LinkedHashMap<String, Object>) request.getContext().get("metaModel");
if (metaModelMap == null) {
return;
}
Long metaModelId = Long.parseLong(metaModelMap.get("id").toString());
MetaModel metaModel = Beans.get(MetaModelRepository.class).find(metaModelId);
Beans.get(PrintTemplateLineService.class).addItemToReferenceSelection(metaModel);
response.setNotify(I18n.get(IExceptionMessage.PRINT_TEMPLATE_LINE_TEST_REFRESH));
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class FilterGroovyService method getMetaFieldType.
private String getMetaFieldType(MetaField field, String targetField, boolean isJson) throws AxelorException {
if (targetField == null || !targetField.contains(".")) {
return field.getTypeName();
}
targetField = targetField.substring(targetField.indexOf(".") + 1);
String targetName = targetField.contains(".") ? targetField.substring(0, targetField.indexOf(".")) : targetField;
MetaModel model = metaModelRepo.findByName(field.getTypeName());
if (model == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No model found: %s ", field.getName());
}
MetaField subMeta = filterSqlService.findMetaField(targetName, model.getFullName());
if (subMeta != null) {
return getMetaFieldType(subMeta, targetField, isJson);
} else if (isJson) {
MetaJsonField subJson = filterSqlService.findJsonField(targetName, model.getName());
if (subJson != null) {
return getJsonFieldType(subJson, targetField);
}
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found field: %s model: %s ", targetName, model.getFullName());
}
Aggregations