use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getResourcesByType.
@Override
public List<Resource> getResourcesByType(int tenantId, String resourceTypeId) throws ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String resourceTypeName = jdbcTemplate.fetchSingleRecord(SQLConstants.GET_RESOURCE_TYPE_BY_ID_SQL, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME), preparedStatement -> preparedStatement.setString(1, resourceTypeId));
return jdbcTemplate.executeQuery(GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL, (LambdaExceptionUtils.rethrowRowMapper((resultSet, rowNumber) -> {
String resourceId = resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID);
String resourceName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME);
String resourceLastModified = resultSet.getString(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED);
String resourceCreatedTime = resultSet.getString(DB_SCHEMA_COLUMN_NAME_CREATED_TIME);
String resourceHasFile = resultSet.getString(DB_SCHEMA_COLUMN_NAME_HAS_FILE);
if (StringUtils.equals(resourceHasFile, "1") && (isOracleDB() || isMSSqlDB() || isDB2DB())) {
resourceHasFile = "true";
}
String resourceHasAttribute = resultSet.getString(DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE);
Resource resource = new Resource();
resource.setCreatedTime(resourceCreatedTime);
resource.setHasAttribute(Boolean.valueOf(resourceHasAttribute));
resource.setResourceId(resourceId);
resource.setResourceName(resourceName);
resource.setLastModified(resourceLastModified);
resource.setHasFile(Boolean.valueOf(resourceHasFile));
resource.setTenantDomain(IdentityTenantUtil.getTenantDomain(tenantId));
resource.setFiles(getFiles(resourceId, resourceTypeName, resourceName));
resource.setAttributes(getAttributesByResourceId(resourceId));
return resource;
})), preparedStatement -> {
preparedStatement.setString(1, resourceTypeId);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_RESOURCES_DOES_NOT_EXISTS, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException in project identity-api-server by wso2.
the class NotificationSenderManagementService method handleConfigurationMgtException.
private APIError handleConfigurationMgtException(ConfigurationManagementException e, NotificationSenderManagementConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof ConfigurationManagementClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof ConfigurationManagementServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(CONFIG_MGT_ERROR_CODE_DELIMITER) ? errorCode : NOTIFICATION_SENDER_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method updateMetadataForH2.
private void updateMetadataForH2(Resource resource, String resourceTypeId, boolean isAttributeExists, Timestamp currentTime, boolean useCreatedTime) throws TransactionException, ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
if (isResourceExists(resource, resourceTypeId)) {
jdbcTemplate.withTransaction(template -> template.executeInsert(UPDATE_RESOURCE_H2, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setInt(initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
/*
Resource files are uploaded using a separate endpoint. Therefore resource creation
does not create files. It is allowed to create a resource without files or attributes
in order to allow file uploadafter resource creation.
*/
preparedStatement.setBoolean(++initialParameterIndex, false);
preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
preparedStatement.setString(++initialParameterIndex, resource.getResourceId());
}, resource, false));
} else {
try {
boolean isOracleOrMsssql = isOracleDB() || isMSSqlDB();
jdbcTemplate.withTransaction(template -> template.executeInsert(useCreatedTime ? INSERT_RESOURCE_SQL : INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resource.getResourceId());
preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
if (useCreatedTime) {
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
}
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
if (isOracleOrMsssql) {
preparedStatement.setInt(++initialParameterIndex, 0);
preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
} else {
preparedStatement.setBoolean(++initialParameterIndex, false);
preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
}
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
}, resource, false));
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getFilesByResourceType.
@Override
public List<ResourceFile> getFilesByResourceType(String resourceTypeId, int tenantId) throws ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
return jdbcTemplate.executeQuery(GET_FILES_BY_RESOURCE_TYPE_ID_SQL, ((resultSet, rowNumber) -> {
String resourceFileId = resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID);
String resourceFileName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_FILE_NAME);
String resourceName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME);
String resourceTypeName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME);
return new ResourceFile(resourceFileId, getFilePath(resourceFileId, resourceTypeName, resourceName), resourceFileName);
}), preparedStatement -> {
preparedStatement.setString(1, resourceTypeId);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_FILES_BY_TYPE, resourceTypeId, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method updateMetadataForMYSQL.
private void updateMetadataForMYSQL(Resource resource, String resourceTypeId, boolean isAttributeExists, Timestamp currentTime, boolean useCreatedTime) throws TransactionException, ConfigurationManagementServerException {
String query = INSERT_OR_UPDATE_RESOURCE_MYSQL;
try {
if (isPostgreSQLDB()) {
query = INSERT_OR_UPDATE_RESOURCE_POSTGRESQL;
} else if (isMSSqlDB() || isDB2DB()) {
query = INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2;
} else if (isOracleDB()) {
query = INSERT_OR_UPDATE_RESOURCE_ORACLE;
}
boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
final String finalQuery = query;
jdbcTemplate.withTransaction(template -> template.executeInsert(useCreatedTime ? finalQuery : INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resource.getResourceId());
preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
if (useCreatedTime) {
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
}
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
if (isOracleOrMssql) {
preparedStatement.setInt(++initialParameterIndex, 0);
preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
} else {
preparedStatement.setBoolean(++initialParameterIndex, false);
preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
}
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
}, resource, false));
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
}
Aggregations