use of com.vartech.common.app.beans.ResponseResult 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.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.
the class ExportServiceImpl method selectExportTableInfo.
/**
* @Method Name : selectExportTableInfo
* @Method 설명 : table export list
* @작성자 : ytkim
* @작성일 : 2019. 4. 29.
* @변경이력 :
* @param preferencesInfo
* @return
* @throws Exception
*/
public ResponseResult selectExportTableInfo(PreferencesRequestDTO preferencesInfo) throws Exception {
MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(preferencesInfo.getDbType());
ResponseResult result = new ResponseResult();
result.setItemList(dbMetaEnum.getDBObjectList(ObjectType.TABLE.getObjectTypeId(), preferencesInfo));
return result;
}
use of com.vartech.common.app.beans.ResponseResult 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.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.
the class SQLFileServiceImpl method saveSql.
/**
* 쿼리 저장.
* @param sqlFileRequestDTO
*/
@Transactional(value = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public ResponseResult saveSql(SqlFileRequestDTO sqlFileRequestDTO) {
ResponseResult result = new ResponseResult();
String mode = String.valueOf(sqlFileRequestDTO.getCustom().get("mode"));
SqlFileEntity sqlFileInfo = sqlFileRequestDTO.toEntity();
if ("newfile".equals(mode)) {
sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
sqlFileInfo = sqlFileEntityRepository.save(sqlFileInfo);
} else if ("moveTab".equals(mode)) {
SqlFileTabEntity moveFileTabInfo = sqlFileTabEntityRepository.findByVconnidAndViewidAndSqlId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
// 이동전 앞에 sqlid 파일 업데이트.
sqlFileTabEntityRepository.updatePrevIdByPrevId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId(), moveFileTabInfo.getPrevSqlId());
if (StringUtils.isBlank(sqlFileRequestDTO.getPrevSqlId())) {
sqlFileTabEntityRepository.updatePrevIdBySqlId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getFirstSqlId(), sqlFileRequestDTO.getSqlId());
} else {
// 이동 할 위치 이전 sqlid 업데이트
sqlFileTabEntityRepository.updatePrevIdByPrevId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getPrevSqlId(), sqlFileRequestDTO.getSqlId());
}
moveFileTabInfo.setViewYn(true);
moveFileTabInfo.setPrevSqlId(sqlFileRequestDTO.getPrevSqlId());
sqlFileTabEntityRepository.save(moveFileTabInfo);
} else {
if ("addTab".equals(mode)) {
sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
SqlFileTabEntity sqlFileTabEntity = SqlFileTabEntity.builder().vconnid(sqlFileRequestDTO.getVconnid()).viewid(sqlFileRequestDTO.getViewid()).sqlId(sqlFileRequestDTO.getSqlId()).prevSqlId(sqlFileRequestDTO.getPrevSqlId()).viewYn(true).build();
sqlFileTabEntity = sqlFileTabEntityRepository.save(sqlFileTabEntity);
} else if (mode.startsWith("delTab")) {
deleteSqlFileTabInfo(sqlFileRequestDTO, mode);
} else if ("viewTab".equals(mode)) {
sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
sqlFileTabEntityRepository.updateSqlFileTabEnable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
} else {
sqlFileInfo = sqlFileEntityRepository.findOne(SqlFileSpec.detailSqlFile(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getSqlId())).orElse(null);
if (sqlFileInfo != null) {
if (sqlFileRequestDTO.getSqlCont() != null)
sqlFileInfo.setSqlCont(sqlFileRequestDTO.getSqlCont());
if (sqlFileRequestDTO.getSqlParam() != null)
sqlFileInfo.setSqlParam(sqlFileRequestDTO.getSqlParam());
if (sqlFileRequestDTO.getSqlTitle() != null)
sqlFileInfo.setSqlTitle(sqlFileRequestDTO.getSqlTitle());
if (sqlFileRequestDTO.getEditorCursor() != null)
sqlFileInfo.setEditorCursor(sqlFileRequestDTO.getEditorCursor());
sqlFileInfo = sqlFileEntityRepository.save(sqlFileInfo);
}
if ("query_del".equals(mode)) {
deleteSqlFileTabInfo(sqlFileRequestDTO);
}
}
}
if (sqlFileInfo != null)
sqlFileRequestDTO.setSqlId(sqlFileInfo.getSqlId());
result.setItemOne(sqlFileRequestDTO);
return result;
}
use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.
the class SQLServiceImpl method sqlFormat.
/**
* @Method Name : sqlFormat
* @Method 설명 : sql 포멧 맞추기
* @작성자 : ytkim
* @작성일 : 2015. 4. 6.
* @변경이력 :
* @param sqlExecuteInfo
* @return
* @throws Exception
*/
public ResponseResult sqlFormat(SqlExecuteDTO sqlExecuteInfo) throws Exception {
ResponseResult result = new ResponseResult();
DBType dbType = DBType.getDBType(sqlExecuteInfo.getDbType());
if ("varsql".equals(sqlExecuteInfo.getCustom().get("formatType"))) {
result.setItemOne(VarsqlFormatterUtil.format(sqlExecuteInfo.getSql(), dbType, VarsqlFormatterUtil.FORMAT_TYPE.VARSQL));
} else {
result.setItemOne(VarsqlFormatterUtil.format(sqlExecuteInfo.getSql(), dbType));
}
return result;
}
Aggregations