Search in sources :

Example 1 with VarsqlAppException

use of com.varsql.web.exception.VarsqlAppException in project varsql by varsqlinfo.

the class UserPreferencesServiceImpl method updateUserInfo.

/**
 * @Method Name  : updateUserInfo
 * @Method 설명 : 사용자 정보 업데이트
 * @작성자   : ytkim
 * @작성일   : 2017. 11. 29.
 * @변경이력  :
 * @param userForm
 * @param req
 * @param res
 * @return
 */
public boolean updateUserInfo(UserModReqeustDTO userForm, HttpServletRequest req, HttpServletResponse res) {
    logger.debug("updateUserInfo : {}", userForm);
    UserEntity userInfo = userMgmtRepository.findByViewid(SecurityUtil.userViewId());
    if (userInfo == null)
        throw new VarsqlAppException("user infomation not found : " + SecurityUtil.userViewId());
    userInfo.setLang(userForm.getLang());
    userInfo.setUname(userForm.getUname());
    userInfo.setOrgNm(userForm.getOrgNm());
    userInfo.setDeptNm(userForm.getDeptNm());
    userInfo.setDescription(userForm.getDescription());
    userMgmtRepository.save(userInfo);
    // 언어 변경시 처리.
    Locale userLocale = LocaleConstants.parseLocaleString(userForm.getLang());
    if (userLocale != null && !userLocale.equals(SecurityUtil.loginInfo().getUserLocale())) {
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(req);
        if (localeResolver == null) {
            throw new IllegalStateException("No LocaleResolver found.");
        }
        if (localeResolver.resolveLocale(req) != userLocale) {
            localeResolver.setLocale(req, res, userLocale);
        }
        SecurityUtil.loginInfo().setUserLocale(userLocale);
    }
    return true;
}
Also used : Locale(java.util.Locale) LocaleResolver(org.springframework.web.servlet.LocaleResolver) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) UserEntity(com.varsql.web.model.entity.user.UserEntity)

Example 2 with VarsqlAppException

use of com.varsql.web.exception.VarsqlAppException in project varsql by varsqlinfo.

the class AuthDAO method getUserDataBaseInfo.

/**
 * @Method Name  : getUserDataBaseInfo
 * @Method 설명 :
 * @작성일   : 2015. 6. 22.
 * @작성자   : ytkim
 * @변경이력  :
 * @return
 * @throws SQLException
 */
public void getUserDataBaseInfo() {
    Connection conn = ConnectionFactory.getInstance().getConnection();
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        User user = SecurityUtil.loginInfo();
        StringBuffer query = new StringBuffer();
        String dbColumnQuery = "select VCONNID, VNAME, VDBSCHEMA, VDBVERSION, BASETABLE_YN, LAZYLOAD_YN,SCHEMA_VIEW_YN, MAX_SELECT_COUNT, USE_COLUMN_LABEL, b.DB_TYPE from VTCONNECTION a left outer join VTDBTYPE_DRIVER_PROVIDER b  on a.VDRIVER = b.DRIVER_PROVIDER_ID where USE_YN ='Y' and DEL_YN = 'N' AND ";
        query.append(dbColumnQuery);
        AuthorityType tmpAuthority = user.getTopAuthority();
        if (tmpAuthority.equals(AuthorityType.ADMIN)) {
            query.append(" 1 = 1 ");
        } else if (tmpAuthority.equals(AuthorityType.GUEST)) {
            query.append(" 1 != 1 ");
        } else {
            query.append(" A.VCONNID IN ( ");
            query.append(" select d.VCONNID ");
            query.append(" from VTDATABASE_GROUP a inner join VTDATABASE_GROUP_DB b on a.GROUP_ID = b.GROUP_ID ");
            query.append(" inner join VTDATABASE_GROUP_USER c on b.GROUP_ID = c.GROUP_ID ");
            query.append(" inner join VTCONNECTION d on b.VCONNID = d.VCONNID ");
            query.append(" left outer join VTDATABASE_BLOCK_USER e on d.VCONNID = e.VCONNID and c.VIEWID =e.VIEWID ");
            query.append(" where c.VIEWID = '" + user.getViewid() + "'  ");
            query.append(" and e.viewid is null ");
            query.append(" and d.USE_YN = 'Y' ");
            query.append(" group by d.VCONNID ");
            query.append(" ) ");
            if (tmpAuthority.equals(AuthorityType.MANAGER)) {
                query.append(" union ");
                query.append(dbColumnQuery + "  A.VCONNID in ( select VCONNID from VTDATABASE_MANAGER where VIEWID = '" + user.getViewid() + "' ) ");
            }
        }
        Map<String, DatabaseInfo> userDatabaseInfo = new LinkedHashMap<String, DatabaseInfo>();
        if (!tmpAuthority.equals(AuthorityType.GUEST)) {
            pstmt = conn.prepareStatement(query.toString());
            rs = pstmt.executeQuery();
            String vconnid;
            String uuid = "";
            String viewid = user.getViewid();
            Map<String, String> vconnidNconuid = new HashMap<>();
            List<String> newVconnidList = new ArrayList<String>();
            while (rs.next()) {
                vconnid = rs.getString(VarsqlKeyConstants.CONN_ID);
                newVconnidList.add(vconnid);
                uuid = UUIDUtil.vconnidUUID(viewid, vconnid);
                try {
                    userDatabaseInfo.put(uuid, new DatabaseInfo(vconnid, uuid, rs.getString("DB_TYPE"), rs.getString(VarsqlKeyConstants.CONN_NAME), rs.getString(VarsqlKeyConstants.CONN_DBSCHEMA), rs.getString(VarsqlKeyConstants.CONN_BASETABLE_YN), rs.getString(VarsqlKeyConstants.CONN_LAZYLOAD_YN), rs.getLong(VarsqlKeyConstants.CONN_VDBVERSION), rs.getString(VarsqlKeyConstants.CONN_SCHEMA_VIEW_YN), rs.getInt(VarsqlKeyConstants.CONN_MAX_SELECT_COUNT), rs.getString(VarsqlKeyConstants.CONN_USE_COLUMN_LABEL)));
                    vconnidNconuid.put(vconnid, uuid);
                } catch (Exception e) {
                    logger.error("DatabaseInfo not valid : " + vconnid);
                }
            }
            user.setDatabaseInfo(userDatabaseInfo);
            user.setVconnidNconuid(vconnidNconuid);
        }
    } catch (SQLException e) {
        throw new VarsqlAppException("database load exception : " + e.getMessage(), e);
    } finally {
        JdbcUtils.close(conn, pstmt, rs);
    }
}
Also used : User(com.varsql.core.auth.User) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) PreparedStatement(java.sql.PreparedStatement) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) SQLException(java.sql.SQLException) LinkedHashMap(java.util.LinkedHashMap) AuthorityType(com.varsql.core.auth.AuthorityType) ResultSet(java.sql.ResultSet)

Example 3 with VarsqlAppException

use of com.varsql.web.exception.VarsqlAppException in project varsql by varsqlinfo.

the class FileServiceUtils method getSaveRelativePath.

/**
 * @method  : getSaveRelativePath
 * @desc : save
 * @author   : ytkim
 * @date   : 2021. 1. 3.
 * @param div
 * @return
 * @throws IOException
 */
public static String getSaveRelativePath(String div) {
    String relativePath = FileUtils.getSaveDayPath(div);
    Path fileExportPath = getUploadRootPath().resolve(relativePath);
    if (Files.notExists(fileExportPath)) {
        try {
            Files.createDirectories(fileExportPath);
        } catch (IOException e) {
            throw new VarsqlAppException(e.getMessage(), e);
        }
    }
    return relativePath;
}
Also used : Path(java.nio.file.Path) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) IOException(java.io.IOException)

Example 4 with VarsqlAppException

use of com.varsql.web.exception.VarsqlAppException in project varsql by varsqlinfo.

the class SQLServiceImpl method dataExport.

/**
 * 데이터 내보내기.
 * @param paramMap
 * @param req
 */
@SuppressWarnings("rawtypes")
public void dataExport(ParamMap paramMap, SqlExecuteDTO sqlExecuteInfo, HttpServletRequest req, HttpServletResponse res) throws Exception {
    String objectName = sqlExecuteInfo.getObjectName();
    if (!sqlExecuteInfo.getBaseSchema().equals(sqlExecuteInfo.getSchema())) {
        objectName = sqlExecuteInfo.getSchema() + "." + objectName;
    }
    StringBuilder reqQuerySb = new StringBuilder().append("select * from ").append(objectName).append(" where 1=1 ");
    String conditionQuery = paramMap.getString("conditionQuery");
    if (!StringUtils.isBlank(conditionQuery)) {
        conditionQuery = StringUtils.lTrim(conditionQuery);
        if (conditionQuery.startsWith("where")) {
            conditionQuery = conditionQuery.replaceFirst("where", "");
        }
        if (conditionQuery.startsWith("and")) {
            conditionQuery = conditionQuery.replaceFirst("and", "");
        }
        conditionQuery = " and " + conditionQuery;
        reqQuerySb.append(conditionQuery);
    }
    sqlExecuteInfo.setSqlParam("{}");
    sqlExecuteInfo.setSql(reqQuerySb.toString());
    String exportCharset = paramMap.getString("charset", VarsqlConstants.CHAR_SET);
    OutputStream outstream = null;
    AbstractWriter writer = null;
    try {
        VarsqlFileType exportType = sqlExecuteInfo.getExportType();
        Path fileExportPath = FileServiceUtils.getSavePath(UploadFileType.EXPORT);
        String downloadFilePath = FileUtils.pathConcat(fileExportPath.toAbsolutePath().toString(), exportType.concatExtension(VartechUtils.generateUUID()));
        outstream = new FileOutputStream(downloadFilePath);
        if (VarsqlFileType.CSV.equals(exportType)) {
            writer = new CSVWriter(outstream, ',', exportCharset);
        } else if (VarsqlFileType.JSON.equals(exportType)) {
            writer = new JSONWriter(outstream, "row", exportCharset);
        } else if (VarsqlFileType.XML.equals(exportType)) {
            writer = new XMLWriter(outstream, "row", exportCharset);
        } else if (VarsqlFileType.EXCEL.equals(exportType)) {
            writer = new ExcelWriter(outstream);
        } else {
            writer = new SQLWriter(outstream, DBType.getDBType(sqlExecuteInfo.getDbType()), objectName, exportCharset);
        }
        logger.debug("data export downloadFilePath :{} , query : {}", downloadFilePath, sqlExecuteInfo.getSql());
        final String tableName = objectName;
        SQLExecuteResult ser = new SelectExecutor().execute(sqlExecuteInfo, new AbstractSQLExecutorHandler(writer) {

            private boolean firstFlag = true;

            @Override
            public boolean handle(SQLHandlerParameter handleParam) {
                if (firstFlag) {
                    WriteMetadataInfo whi = new WriteMetadataInfo("exportInfo");
                    List<ExportColumnInfo> columns = new LinkedList<ExportColumnInfo>();
                    handleParam.getColumnInfoList().forEach(item -> {
                        ExportColumnInfo gci = new ExportColumnInfo();
                        gci.setName(item.getLabel());
                        gci.setAlias(item.getKey());
                        gci.setType(item.getDbType());
                        gci.setNumber(item.isNumber());
                        gci.setLob(item.isLob());
                        columns.add(gci);
                    });
                    whi.addMetedata("tableName", tableName);
                    whi.addMetedata("columns", columns);
                    getWriter().setMetadata(whi);
                    if (VarsqlFileType.SQL.equals(exportType)) {
                        ((SQLWriter) getWriter()).setColumnInfos(handleParam.getColumnInfoList());
                    }
                    firstFlag = false;
                }
                try {
                    getWriter().addRow(handleParam.getRowObject());
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                    return false;
                }
                return true;
            }
        });
        writer.writeAndClose();
        if (ser.getResultCode() != null) {
            throw new DataDownloadException(ser.getResultCode(), ser.getMessage(), new VarsqlAppException(ser.getMessage()));
        }
        String exportFileName = ValidateUtils.getValidFileName(paramMap.getString("fileName", objectName));
        VarsqlUtils.setResponseDownAttr(res, req, exportType.concatExtension(exportFileName));
        try (FileInputStream fileInputStream = new FileInputStream(new File(downloadFilePath));
            OutputStream downloadStream = res.getOutputStream()) {
            byte[] buf = new byte[8192];
            int read = 0;
            while ((read = fileInputStream.read(buf)) != -1) {
                downloadStream.write(buf, 0, read);
            }
            downloadStream.flush();
            downloadStream.close();
            fileInputStream.close();
        }
    } catch (Exception e) {
        throw e;
    } finally {
        IOUtils.close(writer);
        IOUtils.close(outstream);
    }
}
Also used : JSONWriter(com.vartech.common.io.writer.JSONWriter) SelectExecutor(com.varsql.core.sql.executor.SelectExecutor) ExportColumnInfo(com.varsql.core.sql.beans.ExportColumnInfo) SqlGridDownloadInfo(com.varsql.web.dto.sql.SqlGridDownloadInfo) Connection(java.sql.Connection) SqlHistoryEntity(com.varsql.web.model.entity.sql.SqlHistoryEntity) WriteMetadataInfo(com.vartech.common.io.writer.WriteMetadataInfo) SqlExecuteManager(com.varsql.core.sql.SqlExecuteManager) SqlSource(com.varsql.core.sql.builder.SqlSource) LoggerFactory(org.slf4j.LoggerFactory) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) Autowired(org.springframework.beans.factory.annotation.Autowired) VarsqlUtils(com.varsql.web.util.VarsqlUtils) ParameterMode(com.varsql.core.sql.mapping.ParameterMode) ParamMap(com.vartech.common.app.beans.ParamMap) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) ResultSet(java.sql.ResultSet) Map(java.util.Map) ConnectionFactory(com.varsql.core.connection.ConnectionFactory) JSONWriter(com.vartech.common.io.writer.JSONWriter) XMLWriter(com.vartech.common.io.writer.XMLWriter) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) SQLResultSetUtils(com.varsql.core.sql.util.SQLResultSetUtils) VarsqlFileType(com.varsql.core.common.code.VarsqlFileType) PreparedStatement(java.sql.PreparedStatement) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException) CSVWriter(com.vartech.common.io.writer.CSVWriter) List(java.util.List) SqlSourceBuilder(com.varsql.core.sql.builder.SqlSourceBuilder) CallableStatement(java.sql.CallableStatement) SqlStatisticsEntity(com.varsql.web.model.entity.sql.SqlStatisticsEntity) VarsqlFormatterUtil(com.varsql.core.sql.format.VarsqlFormatterUtil) ConvertUtils(com.varsql.web.util.ConvertUtils) ExcelWriter(com.vartech.common.io.writer.ExcelWriter) IOUtils(com.vartech.common.utils.IOUtils) SQLWriter(com.varsql.core.data.writer.SQLWriter) ValidateUtils(com.varsql.web.util.ValidateUtils) ResultSetConvertException(com.varsql.core.exception.ResultSetConvertException) JdbcUtils(com.varsql.core.sql.util.JdbcUtils) CommonServiceImpl(com.varsql.web.common.service.CommonServiceImpl) HashMap(java.util.HashMap) ResponseResult(com.vartech.common.app.beans.ResponseResult) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileUtils(com.vartech.common.utils.FileUtils) ArrayList(java.util.ArrayList) SecurityUtil(com.varsql.core.common.util.SecurityUtil) LinkedHashMap(java.util.LinkedHashMap) SQLDataType(com.varsql.core.sql.type.SQLDataType) GridColumnInfo(com.varsql.core.sql.beans.GridColumnInfo) VartechUtils(com.vartech.common.utils.VartechUtils) SQLException(java.sql.SQLException) HttpServletRequest(javax.servlet.http.HttpServletRequest) UploadFileType(com.varsql.web.constants.UploadFileType) AbstractWriter(com.vartech.common.io.writer.AbstractWriter) Service(org.springframework.stereotype.Service) SqlSourceResultVO(com.varsql.core.sql.builder.SqlSourceResultVO) JsonToken(com.fasterxml.jackson.core.JsonToken) LinkedList(java.util.LinkedList) DateUtils(com.vartech.common.utils.DateUtils) OutputStream(java.io.OutputStream) SQLParamUtils(com.varsql.core.sql.util.SQLParamUtils) Logger(org.slf4j.Logger) DataDownloadException(com.varsql.web.exception.DataDownloadException) JsonParser(com.fasterxml.jackson.core.JsonParser) GridUtils(com.varsql.core.common.util.GridUtils) FileServiceUtils(com.varsql.web.util.FileServiceUtils) ParameterMapping(com.varsql.core.sql.mapping.ParameterMapping) StringUtils(com.vartech.common.utils.StringUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) VarsqlConstants(com.varsql.core.common.constants.VarsqlConstants) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SqlLogInfoDTO(com.varsql.web.dto.sql.SqlLogInfoDTO) File(java.io.File) SqlDataConstants(com.varsql.core.common.constants.SqlDataConstants) JsonFactory(com.fasterxml.jackson.core.JsonFactory) EscapeType(com.vartech.common.utils.StringUtils.EscapeType) VarsqlCommandType(com.varsql.core.sql.builder.VarsqlCommandType) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) Statement(java.sql.Statement) DBType(com.varsql.core.db.DBType) SqlExecuteDTO(com.varsql.web.dto.sql.SqlExecuteDTO) VarsqlAppCode(com.varsql.core.common.code.VarsqlAppCode) VarsqlStatementType(com.varsql.core.sql.builder.VarsqlStatementType) SelectExecutor(com.varsql.core.sql.executor.SelectExecutor) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) DataDownloadException(com.varsql.web.exception.DataDownloadException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ExcelWriter(com.vartech.common.io.writer.ExcelWriter) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) WriteMetadataInfo(com.vartech.common.io.writer.WriteMetadataInfo) CSVWriter(com.vartech.common.io.writer.CSVWriter) AbstractWriter(com.vartech.common.io.writer.AbstractWriter) XMLWriter(com.vartech.common.io.writer.XMLWriter) VarsqlFileType(com.varsql.core.common.code.VarsqlFileType) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) ExportColumnInfo(com.varsql.core.sql.beans.ExportColumnInfo) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException) ResultSetConvertException(com.varsql.core.exception.ResultSetConvertException) SQLException(java.sql.SQLException) DataDownloadException(com.varsql.web.exception.DataDownloadException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) SQLWriter(com.varsql.core.data.writer.SQLWriter) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) File(java.io.File)

Aggregations

VarsqlAppException (com.varsql.web.exception.VarsqlAppException)4 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 AuthorityType (com.varsql.core.auth.AuthorityType)1 User (com.varsql.core.auth.User)1 VarsqlAppCode (com.varsql.core.common.code.VarsqlAppCode)1 VarsqlFileType (com.varsql.core.common.code.VarsqlFileType)1 SqlDataConstants (com.varsql.core.common.constants.SqlDataConstants)1 VarsqlConstants (com.varsql.core.common.constants.VarsqlConstants)1 GridUtils (com.varsql.core.common.util.GridUtils)1 SecurityUtil (com.varsql.core.common.util.SecurityUtil)1 ConnectionFactory (com.varsql.core.connection.ConnectionFactory)1 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 DBType (com.varsql.core.db.DBType)1 ConnectionFactoryException (com.varsql.core.exception.ConnectionFactoryException)1