use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class PrintTemplateController method openPrint.
public void openPrint(ActionRequest request, ActionResponse response) {
Model context = request.getContext().asType(Model.class);
String model = request.getModel();
LOG.debug("Print template wizard call for model : {}", model);
Query<PrintTemplate> printTemplateQuery = Beans.get(PrintTemplateRepository.class).all().filter("self.metaModel.fullName = ?", model);
try {
long templatesCount = printTemplateQuery.count();
LOG.debug("Print templates count : {} ", templatesCount);
if (templatesCount == 0) {
response.setError(I18n.get("Please define a print template for the model :" + model));
} else if (templatesCount == 1) {
Print print = Beans.get(PrintTemplateService.class).generatePrint(context.getId(), printTemplateQuery.fetchOne());
response.setView(getPrintView(print));
} else if (templatesCount >= 2) {
response.setView(ActionView.define(I18n.get("Select template")).model(Wizard.class.getName()).add("form", "select-print-template-wizard-form").param("show-confirm", "false").context("_objectId", context.getId().toString()).context("_templateContextModel", model).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class QuerieService method runJpqlRequest.
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Long> runJpqlRequest(String filter, Class<?> klass) {
List<Long> idLists = Lists.newArrayList();
List<Map> result = Query.of((Class<? extends Model>) klass).filter(filter).select("id").fetch(0, 0);
for (Map map : result) {
idLists.add(Long.valueOf(map.get("id").toString()));
}
return idLists;
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class DataBackupRestoreService method importObjectWithByteArray.
public Object importObjectWithByteArray(Object bean, Map<String, Object> values) throws IOException {
assert bean instanceof Model;
final Path path = (Path) values.get("__path__");
Mapper mapper = Mapper.of(bean.getClass());
for (String fieldName : values.keySet()) {
if (fieldName.startsWith("byte_")) {
String fileName = (String) values.get(fieldName);
if (Strings.isNullOrEmpty((fileName))) {
return bean;
}
try {
final File image = path.resolve(fileName).toFile();
byte[] bytes = new byte[(int) image.length()];
bytes = java.nio.file.Files.readAllBytes(image.toPath());
mapper.set(bean, fieldName.substring(5), bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return bean;
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class ObjectDataConfigExportManagementRepository method save.
@Override
public ObjectDataConfigExport save(ObjectDataConfigExport entity) {
try {
Class<? extends Model> klass = (Class<? extends Model>) Class.forName(entity.getModelSelect());
JpaRepository<? extends Model> repo = JpaRepository.of(klass);
Object obj = repo.all().filter("self.id = ?", entity.getModelSelectId()).fetchOne();
if (obj != null) {
Mapper mapper = Mapper.of(obj.getClass());
if (mapper.getNameField() != null && mapper.getNameField().get(obj) != null) {
entity.setRecordName(mapper.getNameField().get(obj).toString());
} else {
entity.setRecordName(mapper.get(obj, "id").toString());
}
}
} catch (ClassNotFoundException e) {
TraceBackService.trace(e);
}
return super.save(entity);
}
use of com.axelor.db.Model in project axelor-open-suite by axelor.
the class ObjectDataAnonymizeServiceImpl method deleteFields.
@Transactional
public void deleteFields(Set<MetaField> fields, Mapper mapper, List<? extends Model> data) {
if (fields.isEmpty()) {
return;
}
Map<String, Object> defaultValues = getDefaultValues(mapper, fields);
for (Model model : data) {
for (Entry<String, Object> fieldEntry : defaultValues.entrySet()) {
mapper.set(model, fieldEntry.getKey(), fieldEntry.getValue());
}
JPA.save(model);
mailMessageRepo.all().filter("self.relatedId = ?1 AND self.relatedModel = ?2", model.getId(), mapper.getBeanClass().getName()).delete();
}
}
Aggregations