use of org.wso2.carbon.identity.template.mgt.TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method addTemplate.
/**
* Add a {@link Template}.
*
* @param template {@link Template} to insert.
* @return Inserted {@link TemplateInfo}.
* @throws TemplateManagementException If error occurs while adding the {@link Template}.
*/
public Template addTemplate(Template template) throws TemplateManagementException {
Template templateResult;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(TemplateMgtConstants.SqlQueries.INSERT_TEMPLATE, preparedStatement -> {
preparedStatement.setInt(1, template.getTenantId());
preparedStatement.setString(2, template.getTemplateName());
preparedStatement.setString(3, template.getDescription());
InputStream inputStream = IOUtils.toInputStream(template.getTemplateScript());
try {
preparedStatement.setBinaryStream(4, inputStream, inputStream.available());
} catch (IOException e) {
// SQLException is thrown since the QueryFilter throws an SQLException
throw TemplateMgtUtils.handleSQLException(ERROR_CODE_INSERT_TEMPLATE, template.getTemplateName(), e);
}
});
} catch (DataAccessException e) {
throw TemplateMgtUtils.handleServerException(ERROR_CODE_INSERT_TEMPLATE, template.getTemplateName(), e);
}
templateResult = new Template(template.getTenantId(), template.getTemplateName(), template.getDescription(), template.getTemplateScript());
return templateResult;
}
Aggregations