use of com.varsql.web.model.entity.app.FileInfoEntity in project varsql by varsqlinfo.
the class ExportServiceImpl method downloadTableData.
/**
* @method : downloadTableData
* @desc : download table data
* @author : ytkim
* @date : 2022. 1. 28.
* @param preferencesInfo
* @param req
* @param res
* @throws Exception
*/
public void downloadTableData(PreferencesRequestDTO preferencesInfo, HttpServletRequest req, HttpServletResponse res) throws Exception {
ResponseResult result = downloadTableData2(preferencesInfo, req, res);
FileInfoEntity fie = result.getItem();
VarsqlUtils.setResponseDownAttr(res, req, fie.getFileName());
res.setHeader("Content-Length", "" + fie.getFileSize());
File file = FileServiceUtils.getFileInfoToFile(fie);
byte[] b = new byte[2048];
try (BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream outs = new BufferedOutputStream(res.getOutputStream())) {
int read = 0;
while ((read = fin.read(b)) != -1) {
outs.write(b, 0, read);
}
outs.flush();
IOUtils.close(fin);
IOUtils.close(outs);
}
}
use of com.varsql.web.model.entity.app.FileInfoEntity in project varsql by varsqlinfo.
the class FileImportExportServiceImpl method importFile.
/**
* @Method Name : importFile
* @Method 설명 : import file
* @작성자 : ytkim
* @작성일 : 2020. 11. 22.
* @변경이력 :
*/
public ResponseResult importFile(FileImportInfo fii) {
String conuid = fii.getConuid();
String importType = fii.getImportType();
List<FileInfoEntity> importFileList = fileInfoEntityRepository.findAllById(Arrays.asList(CommUtils.getFileIds(fii.getFileIds())));
ResponseResult result = new ResponseResult();
List<FileImportResult> resultInfo = new ArrayList<>();
importFileList.forEach(fileInfo -> {
FileImportResult fileImportResult = new FileImportResult();
try {
fileImportResult.setFileName(fileInfo.getFileName());
SQLExecuteResult ser = null;
if ("sql".equals(importType)) {
ser = sqlImport(fileInfo, conuid);
} else if ("xml".equals(importType)) {
ser = xmlImport(fileInfo, conuid);
} else if ("json".equals(importType)) {
ser = jsonImport(fileInfo, conuid);
} else if ("csv".equals(importType)) {
ser = csvImport(fileInfo, conuid);
}
if (ser.getResultCode() != null) {
fileImportResult.setResultCode(ser.getResultCode());
}
fileImportResult.setResultCount(ser.getExecuteCount());
fileImportResult.setMessage(ser.getMessage());
} catch (IOException | SQLException e) {
fileImportResult.setResultCode(VarsqlAppCode.ERROR);
fileImportResult.setMessage(e.getMessage());
logger.error("file import error importType : {} , conuid : {} , fileInfo :{} ", importType, fileInfo);
logger.error("error message : {}", e.getMessage(), e);
}
resultInfo.add(fileImportResult);
});
result.setItemList(resultInfo);
return result;
}
use of com.varsql.web.model.entity.app.FileInfoEntity in project varsql by varsqlinfo.
the class UserPreferencesServiceFileImpl method importFileList.
public ResponseResult importFileList(UploadFileType fileType, SearchParameter searchParameter) {
Page<FileInfoEntity> result = fileInfoEntityRepository.findAll(FileInfoSpec.fileTypeSearch(fileType, SecurityUtil.userViewId(), searchParameter), VarsqlUtils.convertSearchInfoToPage(searchParameter));
List<Map> fileList = new ArrayList<>();
result.getContent().forEach(entity -> {
Map item = new HashMap();
item.put("fileId", entity.getFileId());
item.put("fileName", entity.getFileName());
item.put("ext", entity.getFileExt());
item.put("regDt", entity.getRegDt());
item.put("fileSize", entity.getFileSize());
fileList.add(item);
});
return VarsqlUtils.getResponseResult(fileList, result.getTotalElements(), searchParameter);
}
use of com.varsql.web.model.entity.app.FileInfoEntity in project varsql by varsqlinfo.
the class UserPreferencesServiceFileImpl method zipFileDetail.
public ResponseResult zipFileDetail(String fileId, String fileName) {
FileInfoEntity entity = fileInfoEntityRepository.findByFileId(fileId);
if (entity == null) {
new FileNotFoundException("fileId not found : " + fileId);
}
StringBuffer sb = new StringBuffer();
try (ZipFile zipFile = new ZipFile(FileServiceUtils.getFileInfoToFile(entity))) {
ZipEntry entry = zipFile.getEntry(fileName);
if (entry.getName().equals(fileName)) {
try (InputStreamReader isr = new InputStreamReader(zipFile.getInputStream(entry));
BufferedReader br = new BufferedReader(isr)) {
String read_data = "";
int lineCount = 0;
while ((read_data = br.readLine()) != null) {
if (lineCount >= MAX_LINE) {
break;
}
lineCount++;
sb.append(read_data).append(BlankConstants.NEW_LINE);
}
IOUtils.close(br);
IOUtils.close(isr);
}
}
IOUtils.close(zipFile);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemOne(sb.toString());
}
use of com.varsql.web.model.entity.app.FileInfoEntity in project varsql by varsqlinfo.
the class UserPreferencesServiceFileImpl method detail.
public ResponseResult detail(String fileId) {
FileInfoEntity entity = fileInfoEntityRepository.findByFileId(fileId);
if (entity == null) {
new FileNotFoundException("fileId not found : " + fileId);
}
if (UploadFileType.EXPORT.equals(UploadFileType.getDivType(entity.getFileDiv()))) {
Map item;
List<Map> fileList = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(FileServiceUtils.getFileInfoToFile(entity))) {
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
item = new HashMap();
item.put("fileName", entry.getName());
item.put("fileSize", entry.getSize());
item.put("compressFileSize", entry.getCompressedSize());
item.put("updDt", DateUtils.dateformat(VarsqlConstants.DATE_TIME_FORMAT, entry.getLastModifiedTime().toMillis()));
fileList.add(item);
}
IOUtils.close(zipFile);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemList(fileList);
} else if (UploadFileType.IMPORT.equals(UploadFileType.getDivType(entity.getFileDiv()))) {
StringBuffer sb = new StringBuffer();
Map item = new HashMap();
try (InputStreamReader isr = new InputStreamReader(new FileInputStream(FileServiceUtils.getFileInfoToFile(entity)));
BufferedReader br = new BufferedReader(isr)) {
String read_data = "";
int lineCount = 0;
while ((read_data = br.readLine()) != null) {
if (lineCount >= MAX_LINE) {
break;
}
lineCount++;
sb.append(read_data).append(BlankConstants.NEW_LINE);
}
item.put("lineCount", lineCount);
item.put("content", sb.toString());
IOUtils.close(br);
IOUtils.close(isr);
} catch (Exception e) {
logger.error("detail fileId : {}", fileId, e);
}
return VarsqlUtils.getResponseResultItemOne(item);
}
return VarsqlUtils.getResponseResultItemOne(null);
}
Aggregations