Search in sources :

Example 46 with FunctionLibrary

use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.

the class ServerScriptLibrariesService method createScriptLibraryResponse.

/**
 * Create the script library response.
 *
 * @param scriptLibrary script library object.
 * @return scriptLibraryResponse
 */
private ScriptLibraryResponse createScriptLibraryResponse(FunctionLibrary scriptLibrary) {
    ScriptLibraryResponse scriptLibraryResponse = new ScriptLibraryResponse();
    scriptLibraryResponse.setName(scriptLibrary.getFunctionLibraryName());
    scriptLibraryResponse.setDescription(scriptLibrary.getDescription());
    try {
        String displayName = URLEncoder.encode(scriptLibrary.getFunctionLibraryName(), StandardCharsets.UTF_8.name());
        scriptLibraryResponse.setContentRef(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + SCRIPT_LIBRARY_PATH_COMPONENT + "/%s" + SCRIPT_LIBRARY_CONTENT_PATH, displayName)).toString().replace("+", "%20"));
        return scriptLibraryResponse;
    } catch (UnsupportedEncodingException e) {
        FunctionLibraryManagementException error = new FunctionLibraryManagementException(Constants.ErrorMessage.ERROR_CODE_ERROR_ENCODING_URL.getMessage(), e);
        throw handleScriptLibraryError(error, Constants.ErrorMessage.ERROR_CODE_ERROR_ENCODING_URL);
    }
}
Also used : ScriptLibraryResponse(org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryResponse) FunctionLibraryManagementException(org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)31 Test (org.testng.annotations.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)15 DataProvider (org.testng.annotations.DataProvider)13 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)11 FunctionLibraryDAO (org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO)10 Connection (java.sql.Connection)9 FunctionLibraryDAOImpl (org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl)9 SQLException (java.sql.SQLException)5 AxisFault (org.apache.axis2.AxisFault)5 FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.xsd.FunctionLibrary)5 IOException (java.io.IOException)4 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)4 PreparedStatement (java.sql.PreparedStatement)3 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)3 File (java.io.File)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1