Search in sources :

Example 1 with ScriptLibraryResponse

use of org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryResponse 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

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ScriptLibraryResponse (org.wso2.carbon.identity.api.server.script.library.v1.model.ScriptLibraryResponse)1 FunctionLibraryManagementException (org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException)1