use of org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.SqlQueries.GET_TEMPLATE_BY_NAME 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;
}
Aggregations