use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImplTest method deleteFunctionLibraryException.
@Test(dataProvider = "deleteFunctionLibraryData", expectedExceptions = FunctionLibraryManagementException.class)
public void deleteFunctionLibraryException(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain);
functionLibraryDAO.deleteFunctionLibrary(((FunctionLibrary) functionLibrary).getFunctionLibraryName(), tenantDomain);
Assert.fail("Expected: " + FunctionLibraryManagementException.class.getName());
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceImpl method updateFunctionLibrary.
@Override
public void updateFunctionLibrary(String oldFunctionLibraryName, FunctionLibrary functionLibrary, String tenantDomain) throws FunctionLibraryManagementException {
validateInputs(functionLibrary);
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
if (!functionLibrary.getFunctionLibraryName().equals(oldFunctionLibraryName) && functionLibraryDAO.isFunctionLibraryExists(functionLibrary.getFunctionLibraryName(), tenantDomain)) {
throw FunctionLibraryExceptionManagementUtil.handleClientException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_ALREADY_EXIST_SCRIPT_LIBRARY, functionLibrary.getFunctionLibraryName());
}
String functionLibraryName = functionLibrary.getFunctionLibraryName();
if (!isRegexValidated(functionLibraryName)) {
throw FunctionLibraryExceptionManagementUtil.handleClientException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_INVALID_SCRIPT_LIBRARY_NAME, FunctionLibraryMgtUtil.FUNCTION_LIBRARY_NAME_VALIDATING_REGEX);
}
functionLibraryDAO.updateFunctionLibrary(oldFunctionLibraryName, functionLibrary, tenantDomain);
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceImpl method deleteFunctionLibrary.
@Override
public void deleteFunctionLibrary(String functionLibraryName, String tenantDomain) throws FunctionLibraryManagementException {
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
functionLibraryDAO.deleteFunctionLibrary(functionLibraryName, tenantDomain);
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method listFunctionLibraries.
/**
* Retrieve function library list in the tenant domain.
*
* @param tenantDomain Tenant domain
* @return A list of function libraries
* @throws FunctionLibraryManagementException
*/
public List<FunctionLibrary> listFunctionLibraries(String tenantDomain) throws FunctionLibraryManagementException {
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
List<FunctionLibrary> functionLibraries = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement getFunctionLibrariesStmt = connection.prepareStatement(FunctionLibMgtDBQueries.LOAD_FUNCTIONLIB_FROM_TENANTID)) {
getFunctionLibrariesStmt.setInt(1, tenantID);
try (ResultSet functionLibsResultSet = getFunctionLibrariesStmt.executeQuery()) {
while (functionLibsResultSet.next()) {
FunctionLibrary functionlib = new FunctionLibrary();
functionlib.setFunctionLibraryName(functionLibsResultSet.getString("NAME"));
functionlib.setDescription(functionLibsResultSet.getString("DESCRIPTION"));
functionLibraries.add(functionlib);
}
}
} catch (SQLException e1) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARIES, e1);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARIES, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
return functionLibraries;
}
use of org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method deleteFunctionLibrary.
/**
* Delete an existing function library.
*
* @param functionLibraryName Function library name
* @param tenantDomain Tenant domain
* @throws FunctionLibraryManagementException
*/
public void deleteFunctionLibrary(String functionLibraryName, String tenantDomain) throws FunctionLibraryManagementException {
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
try (PreparedStatement deleteFunctionLibStmt = connection.prepareStatement(FunctionLibMgtDBQueries.REMOVE_FUNCTIONLIB)) {
deleteFunctionLibStmt.setInt(1, tenantID);
deleteFunctionLibStmt.setString(2, functionLibraryName);
deleteFunctionLibStmt.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug("Removed the script library " + functionLibraryName + " successfully.");
}
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_PROCESSING_CONTENT_STREAM_SCRIPT_LIBRARY, functionLibraryName, e1);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_PROCESSING_CONTENT_STREAM_SCRIPT_LIBRARY, functionLibraryName, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
}
Aggregations