use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class FilterSqlService method addJoin.
private void addJoin(MetaJsonField field, List<String> joins, StringBuilder parent) {
String targetModel = null;
if (field.getTargetModel() != null) {
targetModel = field.getTargetModel();
} else if (field.getTargetJsonModel() != null) {
targetModel = MetaJsonRecord.class.getName();
}
MetaModel metaModel = metaModelRepo.all().filter("self.fullName = ?1", targetModel).fetchOne();
joins.add("left join " + metaModel.getTableName() + " " + "obj" + joins.size() + " on (obj" + joins.size() + ".id = " + "cast(" + parent + "." + getColumn(field.getModel(), field.getModelField()) + "->'" + field.getName() + "'->>'id' as integer))");
parent.replace(0, parent.length(), "obj" + (joins.size() - 1));
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class ExportObserver method onExport.
void onExport(@Observes @Named(RequestEvent.EXPORT) PostRequest event) throws IOException {
List<GlobalTrackingConfigurationLine> gtcLines = Beans.get(AppBaseService.class).getAppBase().getGlobalTrackingConfigurationLines();
if (CollectionUtils.isEmpty(gtcLines)) {
return;
}
MetaModel model = Beans.get(MetaModelRepository.class).all().filter("self.fullName = ?", event.getRequest().getBeanClass().getName()).fetchOne();
if (gtcLines.stream().anyMatch(l -> l.getMetaModel().equals(model) && l.getTrackExport())) {
@SuppressWarnings("unchecked") final Map<String, Object> data = (Map<String, Object>) event.getResponse().getData();
if (data == null || data.get("fileName") == null) {
return;
}
final String fileName = (String) data.get("fileName");
final Path filePath = MetaFiles.findTempFile(fileName);
MetaFile mf = new MetaFile();
mf.setFileName(fileName);
Beans.get(MetaFiles.class).upload(new FileInputStream(filePath.toFile()), mf);
Beans.get(GlobalTrackingLogService.class).createExportLog(model, mf);
}
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class AdvancedExportController method callAdvancedExportWizard.
@SuppressWarnings("unchecked")
public void callAdvancedExportWizard(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
LOG.debug("Call advanced export wizard for model : {} ", request.getModel());
MetaModel metaModel = Beans.get(MetaModelRepository.class).all().filter("self.fullName = ?", request.getModel()).fetchOne();
String criteria = "";
if (request.getContext().get("_ids") != null)
criteria = request.getContext().get("_ids").toString();
else {
Class<? extends Model> klass = (Class<? extends Model>) request.getBeanClass();
Filter filter = Beans.get(AdvancedExportService.class).getJpaSecurityFilter(metaModel);
int recordCount = (int) request.getCriteria().createQuery(klass, filter).count();
if (recordCount > 0)
criteria = String.valueOf(recordCount);
}
if (Strings.isNullOrEmpty(criteria))
response.setError(I18n.get(IExceptionMessage.ADVANCED_EXPORT_2));
else {
String metaModelName = request.getModel();
boolean isExist = Beans.get(AdvancedExportService.class).checkAdvancedExportExist(metaModelName);
if (!isExist) {
response.setView(ActionView.define(I18n.get("Advanced export")).model(AdvancedExport.class.getName()).add("form", "advanced-export-form").context("_metaModel", metaModel).map());
return;
}
response.setView(ActionView.define(I18n.get("Advanced export")).model(AdvancedExport.class.getName()).add("form", "advanced-export-wizard-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").context("_metaModel", metaModel).context("_criteria", criteria.startsWith("[") ? criteria : request).map());
}
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class DataBackupCreateService method checkErrors.
protected int checkErrors(DataBackup dataBackup, List<MetaModel> metaModelList, String tempDirectoryPath, Map<String, List<String>> subClassesMap) {
int errorsCount = 0;
for (MetaModel metaModel : metaModelList) {
try {
List<String> subClasses = subClassesMap.get(metaModel.getFullName());
long totalRecord = getMetaModelDataCount(metaModel, subClasses);
if (totalRecord > 0) {
LOG.debug("Checking Model : " + metaModel.getFullName());
CSVWriter csvWriter = new CSVWriter(new FileWriter(new File(tempDirectoryPath, metaModel.getName() + ".csv")), SEPARATOR, QUOTE_CHAR);
writeCSVData(metaModel, csvWriter, dataBackup, 1, subClasses, tempDirectoryPath);
csvWriter.close();
}
} catch (ClassNotFoundException e) {
} catch (IOException e) {
TraceBackService.trace(e, DataBackupService.class.getName());
} catch (Exception e) {
JPA.em().getTransaction().rollback();
sb.append("\nError occured while processing model : " + metaModel.getFullName() + "\n");
sb.append(e.getMessage() + "\n");
JPA.em().getTransaction().begin();
dataBackup = Beans.get(DataBackupRepository.class).find(dataBackup.getId());
dataBackup.setFetchLimit(1);
errorsCount++;
}
}
return errorsCount;
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class DataBackupCreateService method getSubClassesMap.
protected Map<String, List<String>> getSubClassesMap() {
List<MetaModel> metaModels = getMetaModels();
List<String> subClasses;
Map<String, List<String>> subClassMap = new HashMap<>();
for (MetaModel metaModel : metaModels) {
try {
subClasses = new ArrayList<>();
@SuppressWarnings("unchecked") Class<AuditableModel> superClass = (Class<AuditableModel>) Class.forName(metaModel.getFullName()).getSuperclass();
if (superClass != AuditableModel.class) {
if (!subClassMap.isEmpty() && subClassMap.containsKey(superClass.getName())) {
subClasses = subClassMap.get(superClass.getName());
}
subClasses.add(metaModel.getName());
subClassMap.put(superClass.getName(), subClasses);
}
} catch (ClassNotFoundException e) {
String strError = "Class not found issue: ";
sb.append(strError).append(e.getLocalizedMessage() + "-----------------------------------------\n");
e.printStackTrace();
}
}
return subClassMap;
}
Aggregations