use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.
the class AdvancedImportController method resetImport.
public void resetImport(ActionRequest request, ActionResponse response) {
try {
AdvancedImport advancedImport = request.getContext().asType(AdvancedImport.class);
if (advancedImport.getId() != null) {
advancedImport = Beans.get(AdvancedImportRepository.class).find(advancedImport.getId());
}
boolean isReset = Beans.get(AdvancedImportService.class).resetImport(advancedImport);
if (isReset) {
response.setFlash(I18n.get(IExceptionMessage.ADVANCED_IMPORT_RESET));
response.setSignal("refresh-app", true);
} else {
response.setFlash(I18n.get(IExceptionMessage.ADVANCED_IMPORT_NO_RESET));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.
the class AdvancedImportBaseRepository method copy.
@Override
public AdvancedImport copy(AdvancedImport entity, boolean deep) {
AdvancedImport copy = super.copy(entity, deep);
copy.setStatusSelect(0);
copy.setErrorLog(null);
copy.setImportFile(null);
return copy;
}
use of com.axelor.apps.base.db.AdvancedImport in project axelor-open-suite by axelor.
the class ValidatorService method validate.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public boolean validate(DataReaderService reader, AdvancedImport advancedImport) throws IOException, ClassNotFoundException, AxelorException {
boolean isLog = false;
String[] sheets = reader.getSheetNames();
this.validateTab(sheets, advancedImport);
boolean isConfig = advancedImport.getIsConfigInFile();
boolean isTabConfig = advancedImport.getIsFileTabConfigAdded();
sortFileTabList(advancedImport.getFileTabList());
for (FileTab fileTab : advancedImport.getFileTabList()) {
if (!Arrays.stream(sheets).anyMatch(sheet -> sheet.equals(fileTab.getName()))) {
continue;
}
fieldMap = new HashMap<>();
titleMap = new HashMap<>();
String sheet = fileTab.getName();
logService.initialize(sheet);
this.validateModel(fileTab);
int tabConfigRowCount = 0;
int totalLines = reader.getTotalLines(fileTab.getName());
if (isConfig) {
String[] objectRow = reader.read(sheet, 0, 0);
if (isTabConfig) {
tabConfigRowCount = advancedImportService.getTabConfigRowCount(sheet, reader, totalLines, objectRow);
}
this.validateObject(objectRow, fileTab, isTabConfig);
}
this.validateSearch(fileTab);
this.validateObjectRequiredFields(fileTab);
this.validateFieldAndData(reader, sheet, fileTab, isConfig, isTabConfig, tabConfigRowCount);
this.validateActions(fileTab);
if (fileTab.getValidationLog() != null) {
fileTab.setValidationLog(null);
}
if (logService.isLogGenerated()) {
logService.write();
logService.close();
File logFile = logService.getLogFile();
fileTab.setValidationLog(metaFiles.upload(new FileInputStream(logFile), sheet + "_err.xlsx"));
logFile.delete();
isLog = true;
} else {
createCustomObjectSet(fileTab.getClass().getName(), fileTab.getMetaModel().getFullName(), 0);
createCustomButton(fileTab.getClass().getName(), fileTab.getMetaModel().getFullName(), 1);
}
fileTabRepo.save(fileTab);
}
return isLog;
}
Aggregations