Search in sources :

Example 16 with FunctionLibraryManagementException

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());
}
Also used : FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 17 with FunctionLibraryManagementException

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);
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)

Example 18 with FunctionLibraryManagementException

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);
}
Also used : FunctionLibraryDAOImpl(org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl) FunctionLibraryDAO(org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)

Example 19 with FunctionLibraryManagementException

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) PreparedStatement(java.sql.PreparedStatement) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException)

Example 20 with FunctionLibraryManagementException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException)

Aggregations

FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)12 FunctionLibraryDAO (org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)11 Connection (java.sql.Connection)10 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)9 FunctionLibraryDAOImpl (org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl)7 SQLException (java.sql.SQLException)6 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)4 File (java.io.File)2 ResultSet (java.sql.ResultSet)2 ScriptLibraryResponse (org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryResponse)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1