use of com.axelor.apps.base.db.AdvancedExport in project axelor-open-suite by axelor.
the class AdvancedExportController method getModelAllFields.
public void getModelAllFields(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
AdvancedExport advancedExport = request.getContext().asType(AdvancedExport.class);
inflector = Inflector.getInstance();
if (advancedExport.getMetaModel() != null) {
List<Map<String, Object>> allFieldList = new ArrayList<>();
MetaModelRepository metaModelRepository = Beans.get(MetaModelRepository.class);
MetaFieldRepository metaFieldRepository = Beans.get(MetaFieldRepository.class);
for (MetaField field : advancedExport.getMetaModel().getMetaFields()) {
Map<String, Object> allFieldMap = new HashMap<>();
allFieldMap.put("currentDomain", advancedExport.getMetaModel().getName());
Class<?> modelClass = Class.forName(advancedExport.getMetaModel().getFullName());
Mapper modelMapper = Mapper.of(modelClass);
if (modelMapper.getProperty(field.getName()) == null || modelMapper.getProperty(field.getName()).isTransient()) {
continue;
}
if (!Strings.isNullOrEmpty(field.getRelationship())) {
MetaModel metaModel = metaModelRepository.all().filter("self.name = ?", field.getTypeName()).fetchOne();
Class<?> klass = Class.forName(metaModel.getFullName());
Mapper mapper = Mapper.of(klass);
String fieldName = mapper.getNameField() == null ? "id" : mapper.getNameField().getName();
MetaField metaField = metaFieldRepository.all().filter("self.name = ?1 AND self.metaModel = ?2", fieldName, metaModel).fetchOne();
allFieldMap.put("metaField", metaField);
allFieldMap.put("targetField", field.getName() + "." + metaField.getName());
} else {
allFieldMap.put("metaField", field);
allFieldMap.put("targetField", field.getName());
}
if (Strings.isNullOrEmpty(field.getLabel())) {
allFieldMap.put("title", this.getFieldTitle(inflector, field.getName()));
} else {
allFieldMap.put("title", field.getLabel());
}
allFieldList.add(allFieldMap);
}
response.setAttr("advancedExportLineList", "value", allFieldList);
}
}
use of com.axelor.apps.base.db.AdvancedExport in project axelor-open-suite by axelor.
the class AdvancedExportController method createCriteria.
@SuppressWarnings("unchecked")
private List<Long> createCriteria(ActionRequest request, AdvancedExport advancedExport) {
if (request.getContext().get("_criteria") != null) {
if (request.getContext().get("_criteria").toString().startsWith("[")) {
String ids = request.getContext().get("_criteria").toString();
return Splitter.on(", ").splitToList(ids.substring(1, ids.length() - 1)).stream().map(id -> Long.valueOf(id.toString())).collect(Collectors.toList());
} else {
ObjectMapper mapper = new ObjectMapper();
ActionRequest parentRequest = mapper.convertValue(request.getContext().get("_criteria"), ActionRequest.class);
Class<? extends Model> klass = (Class<? extends Model>) parentRequest.getBeanClass();
Filter filter = Beans.get(AdvancedExportService.class).getJpaSecurityFilter(advancedExport.getMetaModel());
Stream<? extends Model> listObj = parentRequest.getCriteria().createQuery(klass, filter).fetchSteam(advancedExport.getMaxExportLimit());
return listObj.map(it -> it.getId()).collect(Collectors.toList());
}
}
return null;
}
use of com.axelor.apps.base.db.AdvancedExport in project axelor-open-suite by axelor.
the class AdvancedExportController method advancedExport.
private void advancedExport(ActionRequest request, ActionResponse response, String fileType) throws AxelorException, IOException {
AdvancedExport advancedExport = request.getContext().asType(AdvancedExport.class);
advancedExport = Beans.get(AdvancedExportRepository.class).find(advancedExport.getId());
getAdvancedExportFile(request, response, advancedExport, fileType);
}
use of com.axelor.apps.base.db.AdvancedExport in project axelor-open-suite by axelor.
the class AdvancedExportController method generateExportFile.
@SuppressWarnings({ "rawtypes" })
public void generateExportFile(ActionRequest request, ActionResponse response) {
try {
if (request.getContext().get("_xAdvancedExport") == null || request.getContext().get("exportFormatSelect") == null) {
response.setError(I18n.get(IExceptionMessage.ADVANCED_EXPORT_4));
return;
}
AdvancedExport advancedExport = Beans.get(AdvancedExportRepository.class).find(Long.valueOf(((Map) request.getContext().get("_xAdvancedExport")).get("id").toString()));
String fileType = request.getContext().get("exportFormatSelect").toString();
getAdvancedExportFile(request, response, advancedExport, fileType);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.AdvancedExport in project axelor-open-suite by axelor.
the class AdvancedExportGenerator method generateFile.
/**
* This method is used to generate the export file.
*
* @param advancedExport
* @param query
* @return
* @throws AxelorException
* @throws IOException
* @throws DocumentException
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public File generateFile(Query query) throws AxelorException {
AdvancedExport advancedExport = getAdvancedExport();
log.debug("Export file : {}", getFileName());
generateHeader();
int startPosition = 0;
int reachLimit = 0;
int maxExportLimit = advancedExport.getMaxExportLimit();
int queryFetchLimit = advancedExport.getQueryFetchSize();
List<List> dataList = new ArrayList<>();
query.setMaxResults(queryFetchLimit);
while (startPosition < maxExportLimit) {
if ((maxExportLimit - startPosition) < queryFetchLimit) {
query.setMaxResults((maxExportLimit - startPosition));
}
query.setFirstResult(startPosition);
dataList = query.getResultList();
if (dataList.isEmpty())
break;
generateBody(dataList);
startPosition = startPosition + queryFetchLimit;
reachLimit += dataList.size();
}
if (maxExportLimit == reachLimit) {
isReachMaxExportLimit = true;
}
close();
return getExportFile();
}
Aggregations