use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project carbon-identity-framework by wso2.
the class FunctionLibraryManagementServiceTest method testIsRegexValidatedDataProvider.
@DataProvider(name = "testIsRegexValidatedDataProvider")
public Object[][] testIsRegexValidatedDataProvider() {
FunctionLibrary functionLibrary15 = new FunctionLibrary();
functionLibrary15.setFunctionLibraryName("sample15$%");
functionLibrary15.setDescription("sample15");
functionLibrary15.setFunctionLibraryScript("function samplefunction15(){}");
FunctionLibrary functionLibrary16 = new FunctionLibrary();
functionLibrary16.setFunctionLibraryName("%%sample16");
functionLibrary16.setDescription("sample16");
functionLibrary16.setFunctionLibraryScript("function samplefunction16(){}");
FunctionLibrary functionLibrary17 = new FunctionLibrary();
functionLibrary17.setFunctionLibraryName("$%sample17");
functionLibrary17.setDescription("sample17");
functionLibrary17.setFunctionLibraryScript("function samplefunction17(){}");
return new Object[][] { { functionLibrary15, SAMPLE_TENANT_DOMAIN2 }, { functionLibrary16, SAMPLE_TENANT_DOMAIN2 }, { functionLibrary17, SAMPLE_TENANT_DOMAIN2 } };
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project product-is by wso2.
the class FunctionLibraryManagementTestCase method testDeleteFunctionLibrary.
@Test(alwaysRun = true, description = "Test deleting a Function Library")
public void testDeleteFunctionLibrary() {
String functionLibraryName = "TestFunctionLibrary";
try {
deleteFunctionLibrary(functionLibraryName);
FunctionLibrary[] functionLibraries = functionLibraryManagementServiceClient.listFunctionLibraries();
boolean functionLibraryExists = false;
if (functionLibraries != null) {
for (FunctionLibrary functionLibrary : functionLibraries) {
if (functionLibrary.getFunctionLibraryName().equals(functionLibraryName)) {
functionLibraryExists = true;
}
}
}
Assert.assertFalse(functionLibraryExists, functionLibraryName + " has not been deleted.");
} catch (AxisFault axisFault) {
Assert.fail("Error while trying to delete a function library", axisFault);
}
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.
the class ServerScriptLibrariesService method createScriptLibrariesList.
/**
* Create a script libraries list response.
*
* @param scriptLibraries list of script libraries.
* @param limit Item per page.
* @param offset offset
* @return scriptLibraryListResponse
*/
private ScriptLibraryListResponse createScriptLibrariesList(List<FunctionLibrary> scriptLibraries, Integer limit, Integer offset) {
ScriptLibraryListResponse scriptLibraryListResponse = new ScriptLibraryListResponse();
if (CollectionUtils.isNotEmpty(scriptLibraries)) {
List<ScriptLibrary> scriptLibraryItem = new ArrayList<>();
for (FunctionLibrary functionLibrary : scriptLibraries) {
ScriptLibrary scriptLibrary = new ScriptLibrary();
scriptLibrary.setName(functionLibrary.getFunctionLibraryName());
scriptLibrary.setDescription(functionLibrary.getDescription());
scriptLibrary.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + SCRIPT_LIBRARY_PATH_COMPONENT + "/%s", functionLibrary.getFunctionLibraryName())).toString());
scriptLibraryItem.add(scriptLibrary);
}
scriptLibraryListResponse.setScriptLibraries(scriptLibraryItem.subList(Math.min(scriptLibraryItem.size(), offset), Math.min(scriptLibraryItem.size(), offset + limit)));
scriptLibraryListResponse.setCount(scriptLibraryListResponse.getScriptLibraries().size());
scriptLibraryListResponse.setTotalResults(scriptLibraries.size());
scriptLibraryListResponse.setStartIndex(offset + 1);
} else {
scriptLibraryListResponse.setCount(0);
}
return scriptLibraryListResponse;
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.
the class ServerScriptLibrariesService method createScriptLibraryPut.
/**
* Create a function library object from ScriptLibraryPUTRequest.
*
* @param scriptLibraryName Script library name.
* @param scriptLibraryPUTRequest ScriptLibraryPUTRequest
* @return functionLibrary
*/
private FunctionLibrary createScriptLibraryPut(String scriptLibraryName, ScriptLibraryPUTRequest scriptLibraryPUTRequest) {
FunctionLibrary functionLibrary = new FunctionLibrary();
functionLibrary.setFunctionLibraryName(scriptLibraryName);
functionLibrary.setDescription(scriptLibraryPUTRequest.getDescription());
functionLibrary.setFunctionLibraryScript(String.valueOf(scriptLibraryPUTRequest.getContent()));
return functionLibrary;
}
use of org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary in project identity-api-server by wso2.
the class ServerScriptLibrariesService method addScriptLibrary.
/**
* Add a script library.
*
* @param name Name of the script library.
* @param contentInputStream Content of the script library code.
* @param description Description of the script library
*/
public void addScriptLibrary(String name, InputStream contentInputStream, String description) {
ScriptLibraryPOSTRequest scriptLibraryPOSTRequest = new ScriptLibraryPOSTRequest();
scriptLibraryPOSTRequest.setName(name);
scriptLibraryPOSTRequest.setDescription(description);
try {
scriptLibraryPOSTRequest.setContent(new File(IOUtils.toString(contentInputStream, StandardCharsets.UTF_8.name())));
} catch (IOException e) {
log.error("Error occurred while reading contentInputStream: " + e);
throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_SCRIPT_LIBRARY, Response.Status.INTERNAL_SERVER_ERROR);
}
if (isScriptLibraryAvailable(scriptLibraryPOSTRequest.getName())) {
throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_SCRIPT_LIBRARY_ALREADY_FOUND, Response.Status.CONFLICT, scriptLibraryPOSTRequest.getName(), ContextLoader.getTenantDomainFromContext());
} else {
FunctionLibrary functionLibrary = createScriptLibrary(scriptLibraryPOSTRequest);
try {
if (scriptLibraryPOSTRequest.getName().contains(Constants.SCRIPT_LIBRARY_EXTENSION)) {
ScriptLibraryServiceHolder.getScriptLibraryManagementService().createFunctionLibrary(functionLibrary, ContextLoader.getTenantDomainFromContext());
} else {
throw handleScriptLibraryClientError(Constants.ErrorMessage.ERROR_SCRIPT_LIBRARY_NAME_VALIDATION, Response.Status.BAD_REQUEST);
}
} catch (FunctionLibraryManagementException e) {
throw handleScriptLibraryError(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_SCRIPT_LIBRARY);
}
}
}
Aggregations