use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method deleteTemplate.
/**
* Delete {@link Template} for a given template name and a tenant Id.
*
* @param templateName name of the {@link Template} to be deleted.the tenant
* @param tenantId tenant Id of the tenant which the {@link Template} resides.
* @return TemplateInfo of the deleted {@link Template}.
* @throws TemplateManagementException If error occurs while deleting the {@link Template}
*/
public TemplateInfo deleteTemplate(String templateName, Integer tenantId) throws TemplateManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(DELETE_TEMPLATE, preparedStatement -> {
preparedStatement.setString(1, templateName);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_DELETE_TEMPLATE.getMessage(), tenantId.toString(), templateName), ERROR_CODE_DELETE_TEMPLATE.getCode(), e);
}
return new TemplateInfo(tenantId, templateName);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method getAllTemplates.
/**
* List {@link TemplateInfo} items for a given search criteria.
*
* @param tenantId Tenant Id to be searched.
* @param limit Maximum number of results expected.
* @param offset Result offset.
* @return List of {@link TemplateInfo} entries.
* @throws TemplateManagementException If error occurs while searching the Templates.
*/
public List<TemplateInfo> getAllTemplates(Integer tenantId, Integer limit, Integer offset) throws TemplateManagementException {
List<TemplateInfo> templates;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String query;
if (isH2DB() || isMySQLDB() || isPostgreSQLDB()) {
query = LIST_PAGINATED_TEMPLATES_MYSQL;
} else if (isDB2DB()) {
query = LIST_PAGINATED_TEMPLATES_DB2;
int initialOffset = offset;
offset = offset + limit;
limit = initialOffset + 1;
} else if (isMSSqlDB()) {
int initialOffset = offset;
offset = limit + offset;
limit = initialOffset + 1;
query = LIST_PAGINATED_TEMPLATES_MSSQL;
} else {
// oracle
query = LIST_PAGINATED_TEMPLATES_ORACLE;
limit = offset + limit;
}
int finalLimit = limit;
int finalOffset = offset;
templates = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> new TemplateInfo(resultSet.getString(1), resultSet.getString(2)), preparedStatement -> {
preparedStatement.setInt(1, tenantId);
preparedStatement.setInt(2, finalLimit);
preparedStatement.setInt(3, finalOffset);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_PAGINATED_LIST_TEMPLATES.getMessage(), tenantId, limit, offset), ERROR_CODE_PAGINATED_LIST_TEMPLATES.getCode(), e);
}
return templates;
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException in project identity-api-server by wso2.
the class ServerIdpManagementService method handleTemplateMgtException.
/**
* Handle template management exceptions and return related API errors.
*
* @param e {@link TemplateManagementException}.
* @param errorEnum Error message with error code and description.
* @param data Additional information.
* @return API error.
*/
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof TemplateManagementClientException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TemplateManagementServerException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
if (e.getErrorCode() != null) {
errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementServerException 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