The SUSI SKill CMS has various filters to explore the skills of interest. For example skill category and skill language. The skills are stored in the susi_skill_data Github repo in the following structure:
susi_skill_data/models/<model_name>/<group_name>/<language_name>/<skill_name>.txt
NOTE: group and category are same terms and can be used interchangeably
So when a category filter is applied the skills from the corresponding directory are returned.
susi_skill_data/models/<model_name>/<group_name>/<language_name>/<skill_name>.txt
But there’s no directory called “All”, so how to get skills of all groups? For this, we need to loop through all the directories present in the model.
Server side implementation
Create a helper function that returns a list of all the folders present in a directory. The function accepts the parent directory name and an empty list. First, fetch all the items (files and folders) present in that directory and store them in an array. Then apply a filter over the array to check if the element is a directory and doesn’t start with a dot(.) i.e., it’s not hidden. Add the filtered array to the list.
private void listFoldersForFolder(final File folder, ArrayList<String> fileList) { File[] filesInFolder = folder.listFiles(); if (filesInFolder != null) { Arrays.stream(filesInFolder) .filter(fileEntry -> fileEntry.isDirectory() && !fileEntry.getName().startsWith(".")) .forEach(fileEntry -> fileList.add(fileEntry.getName() + "")); } }
Fetch the group name form the request and add a check if the CMS is asking for all skill. Otherwise, return the skills of a particular group only.
String group_name = call.get("group", "Knowledge"); if (group_name.equals("All")) { // Return the list of all skills } else { // Return the list of a skills in a particular group only }
To fetch the list of all skills, call the listFoldersForFolders() function with the model name and an empty list as arguments. The function adds all the directories, present in that model directory, to folderList.
File allGroup = new File(String.valueOf(model)); ArrayList<String> folderList = new ArrayList<String>(); listFoldersForFolder(allGroup, folderList);
Then loop over all the groups present in the list to get all the skills present in that group. This process is the same as the existing process of getting skills of a particular category. Just keep adding the skill list to a global array.
CMS side implementation
The list of categories is first fetched from the API and then added to the dropdown menu. Since the API doesn’t return “All” in it, so we need to push it to the list manually.
groups.push(<MenuItem value="All" key="All" primaryText="All" />);