Search in sources :

Example 1 with ResponseResult

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ResponseResult(com.vartech.common.app.beans.ResponseResult) FileInfoEntity(com.varsql.web.model.entity.app.FileInfoEntity) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream)

Example 2 with ResponseResult

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;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) MetaControlBean(com.varsql.core.db.MetaControlBean)

Example 3 with ResponseResult

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;
}
Also used : SQLException(java.sql.SQLException) ResponseResult(com.vartech.common.app.beans.ResponseResult) ArrayList(java.util.ArrayList) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileInfoEntity(com.varsql.web.model.entity.app.FileInfoEntity) FileImportResult(com.varsql.web.dto.file.FileImportResult) IOException(java.io.IOException)

Example 4 with ResponseResult

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;
}
Also used : SqlFileEntity(com.varsql.web.model.entity.sql.SqlFileEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) SqlFileTabEntity(com.varsql.web.model.entity.sql.SqlFileTabEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ResponseResult

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;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) DBType(com.varsql.core.db.DBType)

Aggregations

ResponseResult (com.vartech.common.app.beans.ResponseResult)75 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)15 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 Transactional (org.springframework.transaction.annotation.Transactional)12 MetaControlBean (com.varsql.core.db.MetaControlBean)10 DBTypeDriverProviderEntity (com.varsql.web.model.entity.db.DBTypeDriverProviderEntity)8 HashMap (java.util.HashMap)8 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)6 EncryptDecryptException (com.vartech.common.crypto.EncryptDecryptException)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ObjectError (org.springframework.validation.ObjectError)6 FileInfoEntity (com.varsql.web.model.entity.app.FileInfoEntity)5 SQLException (java.sql.SQLException)5 FileInfo (com.varsql.core.common.beans.FileInfo)4 JDBCDriverInfo (com.varsql.core.connection.beans.JDBCDriverInfo)4 DBMetadataException (com.varsql.core.exception.DBMetadataException)4 DBTypeDriverEntity (com.varsql.web.model.entity.db.DBTypeDriverEntity)4