The Dashboard on the SUSI Skill CMS is the page where all user specific Skill information is being displayed. It also has a section called “My Skills” which displays the Skills created by the user himself. The data for the “My Skills” section has to be fetched from the Skill metadata of each Skill. Hence, this blog post explains how the Skills created by an author are fetched using an API which takes author’s email as the only parameter.
Why is such an API required?
The task of displaying the “My Skills” section cannot be done entirely on the Client side with the use of existing APIs, as that would result in a lot of AJAX calls to the Server, because for each Skill, there would have to be an AJAX call for each user. Hence, we had to create an endpoint which could directly return the list of Skills created by a user using his ID. This would prevent multiple AJAX calls to the Server.
The endpoint used is:
Here, author_email is the email of the author who published the particular Skill, which is fetched from the Skill metadata object which looks like this:
Working of the API
The code to fetch the Skills created by an author is described in the GetSkillsByAuthor.java file. This API accepts either the author’s name, or the author’s email as the parameter. In our
We get all folders within a folder using the following method:
We use this method to get list of folders of all the group names for all the different Skills, and store them in a variable ‘folderList’ as per the following code:
For every folder corresponding to a group name, we traverse inside it and then further traverse inside the language folders to reach the place where all the Skill files are stored.
This is the code for the method to get all files within a folder:
We need to get all Skill files inside the ‘languages’ folder, which itself is in ‘group’ folder. This is the code required to implement the same:
This is how the Skill metadata is fetched from the getSkillMetadata() method of SusiSkill class:
getSkillMetadata() method takes model of the Skill, group of the Skill, language of the Skill, Skill name and also duration (for usage statistical purposes) as the method parameters, and returns the metadata for the Skill in the format as shown below:
This is how the Skills created by an author are fetched using this API. The JSON response of this endpoint shows the metadata of all Skills which have ‘author_email’ value the same as that given in the endpoint’s query parameter.
- List files and folders in a directory in JAVA – http://www.codejava.net/java-se/file-io/how-to-list-files-and-directories-in-a-directory
- For-each loop in JAVA – https://www.geeksforgeeks.org/for-each-loop-in-java/
- ArrayList in JAVA – https://www.geeksforgeeks.org/arraylist-in-java/