use of org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary in project carbon-identity-framework by wso2.
the class JsGraphBuilder method loadLocalLibrary.
/**
* Loads the required function library from the database.
*
* @param functionLibraryName functionLibraryName
* @return functionLibraryScript
* @throws FunctionLibraryManagementException
*/
public String loadLocalLibrary(String functionLibraryName) throws FunctionLibraryManagementException {
FunctionLibraryManagementService functionLibMgtService = FrameworkServiceComponent.getFunctionLibraryManagementService();
FunctionLibrary functionLibrary;
String libraryScript = null;
functionLibrary = functionLibMgtService.getFunctionLibrary(functionLibraryName, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
if (functionLibrary != null) {
libraryScript = functionLibrary.getFunctionLibraryScript();
} else {
log.error("No function library available with " + functionLibraryName + "name.");
}
return libraryScript;
}
use of org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementAdminService method getFunctionLibrary.
/**
* Get a function library using function library name.
*
* @param functionLibraryName Name of the function library
* @return Function library
* @throws FunctionLibraryManagementException
*/
public FunctionLibrary getFunctionLibrary(String functionLibraryName) throws FunctionLibraryManagementException {
try {
functionLibMgtService = FunctionLibraryManagementServiceImpl.getInstance();
FunctionLibrary functionLibrary;
functionLibrary = functionLibMgtService.getFunctionLibrary(functionLibraryName, getTenantDomain());
return functionLibrary;
} catch (FunctionLibraryManagementException e) {
log.error("Error while retrieving script library " + functionLibraryName + " for tenant domain " + getTenantDomain() + ".", e);
throw e;
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceImpl method createFunctionLibrary.
@Override
public void createFunctionLibrary(FunctionLibrary functionLibrary, String tenantDomain) throws FunctionLibraryManagementException {
validateInputs(functionLibrary);
FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl();
if (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.createFunctionLibrary(functionLibrary, tenantDomain);
}
use of org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method getFunctionLibrary.
/**
* Retrieve a function library from the given name.
*
* @param functionLibraryName Function library name
* @param tenantDomain Tenant domain
* @return Function library
* @throws FunctionLibraryManagementException
*/
public FunctionLibrary getFunctionLibrary(String functionLibraryName, String tenantDomain) throws FunctionLibraryManagementException {
// get logged-in users tenant identifier.
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement getFunctionLibStmt = connection.prepareStatement(FunctionLibMgtDBQueries.LOAD_FUNCTIONLIB_FROM_TENANTID_AND_NAME)) {
getFunctionLibStmt.setInt(1, tenantID);
getFunctionLibStmt.setString(2, functionLibraryName);
try (ResultSet resultSet = getFunctionLibStmt.executeQuery()) {
if (resultSet.next()) {
FunctionLibrary functionlib = new FunctionLibrary();
functionlib.setFunctionLibraryName(resultSet.getString("NAME"));
functionlib.setDescription(resultSet.getString("DESCRIPTION"));
functionlib.setFunctionLibraryScript(IOUtils.toString(resultSet.getBinaryStream("DATA")));
return functionlib;
} else {
return null;
}
}
} catch (IOException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARY, functionLibraryName, e);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARY, functionLibraryName, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method updateFunctionLibrary.
/**
* Update an existing function library.
*
* @param oldFunctionLibName Previous name of the function library
* @param functionLibrary Function library
* @param tenantDomain Tenant domain
* @throws FunctionLibraryManagementException
*/
public void updateFunctionLibrary(String oldFunctionLibName, FunctionLibrary functionLibrary, String tenantDomain) throws FunctionLibraryManagementException {
// get logged-in users tenant identifier.
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
if (tenantID != MultitenantConstants.INVALID_TENANT_ID) {
try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
try (PreparedStatement updateFunctionLibStmt = connection.prepareStatement(FunctionLibMgtDBQueries.UPDATE_FUNCTIONLIB_INFO)) {
updateFunctionLibStmt.setString(1, functionLibrary.getFunctionLibraryName());
updateFunctionLibStmt.setString(2, functionLibrary.getDescription());
setBlobValue(functionLibrary.getFunctionLibraryScript(), updateFunctionLibStmt, 3);
updateFunctionLibStmt.setInt(4, tenantID);
updateFunctionLibStmt.setString(5, oldFunctionLibName);
updateFunctionLibStmt.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_UPDATE_SCRIPT_LIBRARY, oldFunctionLibName, e1);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_UPDATE_SCRIPT_LIBRARY, oldFunctionLibName, e);
} catch (IOException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_PROCESSING_CONTENT_STREAM_SCRIPT_LIBRARY, oldFunctionLibName, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
} else {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_INVALID_TENANT);
}
}
Aggregations