Search in sources :

Example 1 with TemplateManagementSQLException

use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementSQLException in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImpl method getTemplateByName.

/**
 * Retrieve {@link Template} by template name and tenant Id.
 *
 * @param templateName name of the {@link Template} to retrieve.
 * @param tenantId     tenant Id of the tenant which the {@link Template} resides.
 * @return {@link Template} for the given name and tenant Id.
 * @throws TemplateManagementException If error occurs while retrieving {@link Template}.
 */
public Template getTemplateByName(String templateName, Integer tenantId) throws TemplateManagementException {
    Template template;
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        template = jdbcTemplate.fetchSingleRecord(GET_TEMPLATE_BY_NAME, ((resultSet, rowNumber) -> {
            Template templateResult;
            try {
                templateResult = new Template(resultSet.getString(1), resultSet.getString(2), IOUtils.toString(resultSet.getBinaryStream(3)));
            } catch (IOException e) {
                // SQLException is thrown since the QueryFilter throws an SQLException
                throw new TemplateManagementSQLException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
            }
            return templateResult;
        }), preparedStatement -> {
            preparedStatement.setString(1, templateName);
            preparedStatement.setInt(2, tenantId);
        });
    } catch (DataAccessException e) {
        throw new TemplateManagementServerException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
    }
    return template;
}
Also used : LIST_PAGINATED_TEMPLATES_MYSQL(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.LIST_PAGINATED_TEMPLATES_MYSQL) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) ERROR_CODE_SELECT_TEMPLATE_BY_NAME(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_SELECT_TEMPLATE_BY_NAME) LIST_PAGINATED_TEMPLATES_MSSQL(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.LIST_PAGINATED_TEMPLATES_MSSQL) TemplateManagementSQLException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementSQLException) DELETE_TEMPLATE(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.DELETE_TEMPLATE) TemplateInfo(org.wso2.carbon.identity.template.mgt.model.TemplateInfo) ERROR_CODE_UPDATE_TEMPLATE(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_UPDATE_TEMPLATE) ERROR_CODE_INSERT_TEMPLATE(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE) JdbcUtils(org.wso2.carbon.identity.core.util.JdbcUtils) LIST_PAGINATED_TEMPLATES_DB2(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.LIST_PAGINATED_TEMPLATES_DB2) ERROR_CODE_PAGINATED_LIST_TEMPLATES(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_PAGINATED_LIST_TEMPLATES) ERROR_CODE_DELETE_TEMPLATE(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_DELETE_TEMPLATE) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) IOException(java.io.IOException) TemplateManagementServerException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException) JdbcUtils.isMSSqlDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMSSqlDB) GET_TEMPLATE_BY_NAME(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.GET_TEMPLATE_BY_NAME) JdbcUtils.isMySQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMySQLDB) LIST_PAGINATED_TEMPLATES_ORACLE(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.LIST_PAGINATED_TEMPLATES_ORACLE) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) JdbcUtils.isH2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB) TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) JdbcUtils.isPostgreSQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isPostgreSQLDB) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) TemplateMgtConstants(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants) TemplateMgtUtils(org.wso2.carbon.identity.template.mgt.util.TemplateMgtUtils) JdbcUtils.isDB2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB) Template(org.wso2.carbon.identity.template.mgt.model.Template) InputStream(java.io.InputStream) TemplateManagementServerException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException) IOException(java.io.IOException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template) TemplateManagementSQLException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementSQLException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 IOUtils (org.apache.commons.io.IOUtils)1 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)1 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)1 JdbcUtils (org.wso2.carbon.identity.core.util.JdbcUtils)1 JdbcUtils.isDB2DB (org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB)1 JdbcUtils.isH2DB (org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB)1 JdbcUtils.isMSSqlDB (org.wso2.carbon.identity.core.util.JdbcUtils.isMSSqlDB)1 JdbcUtils.isMySQLDB (org.wso2.carbon.identity.core.util.JdbcUtils.isMySQLDB)1 JdbcUtils.isPostgreSQLDB (org.wso2.carbon.identity.core.util.JdbcUtils.isPostgreSQLDB)1 TemplateMgtConstants (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants)1 ERROR_CODE_DELETE_TEMPLATE (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_DELETE_TEMPLATE)1 ERROR_CODE_INSERT_TEMPLATE (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE)1 ERROR_CODE_PAGINATED_LIST_TEMPLATES (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_PAGINATED_LIST_TEMPLATES)1 ERROR_CODE_SELECT_TEMPLATE_BY_NAME (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_SELECT_TEMPLATE_BY_NAME)1 ERROR_CODE_UPDATE_TEMPLATE (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_UPDATE_TEMPLATE)1 DELETE_TEMPLATE (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.DELETE_TEMPLATE)1 GET_TEMPLATE_BY_NAME (org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.GET_TEMPLATE_BY_NAME)1