The admin panel of SUSI.AI has an admin panel to manage its users and skills and it also provides the admins to delete skills and restore the deleted ones. In this post we will discuss about how this works on the server and client side.
On the server side there are three APIs associated with this feature. One is to delete a skill, one to restore the skills and another to display the list of deleted skills. The following servlets are responsible for the above APIs and we will discuss about them in detail.
To delete a skill we need the pass five parameters, access_token(to verify user role), and four properties associated with each skill namely modal, group, language and skill name. If we pass just the skill name then susi server will look for the skill in general modal and Knowledge group by default and will fail to delete skills from other groups giving the error as skill not found. therefore it’s always better to pass all four parameters along with the access token. The endpoint associated with delete skill feature is:
Whenever we call this endpoint specifying the above parameters, the ‘skill_name.txt’ file which is found at the path
is moved from this path to the deleted_skills_dir along with the subdirectory which are again created using the specified parameters. This txt file contains all codes, instructions and data about the particular skill. While deleting the skill the last modified time of the file is set to the current system time of the server and then moved to the deleted-skills_dir file on the server. After the above process is completed the response is send to the client about deletion status of the skill.
On the client side at the skills tab whenever an admin click on delete button corresponding to a skill then they receive a confirmation message whether they really want to delete the skill or not. Once they confirm deletion the deleteSkill function is called which sets the loading status on the page to true and sends an ajax request to the server to the above discussed API and if the server responds with success message then a dialog appears on the screen telling us that the following skill is deleted successfully on the server and if the server responds an error then it we see the failed message. Once pressing ok, the page refreshes with the updated list of active and deleted skills and we can see the skill which we deleted in the deleted tab.
To undo a deleted skill we need the pass the same five parameters we passed while deleting the skill. The endpoint associated with delete skill feature is:
Whenever we call this endpoint most of the steps remains the same but the only difference being that this time the skill.txt file is moved from deleted skills directory to the skills data directory at the older path which the skill used to have earlier.
After the above process is completed the response is send to the client about whether the skill was restored successfully or not.
On the client side at the skills tab whenever an admin click on restore button corresponding to a skill then they receive a confirmation message whether they really want to restore the skill or not the same way while deleting the skill. Once pressing ok, the page refreshes with the updated list of active and deleted skills and we can see the skill which we deleted in the deleted tab.
Like we have an api to list all active skills, we also have an API to fetch the list of skills which are deleted by the admins. Admins can restore a deleted skill within 30 days from the time it was deleted. Once a skill has been deleted for more than 30 days then it is permanently deleted. This is taken care by the CareTaker.java servlet. All deleted skills are stored in deleted_skills_dir and listed using the FileUtils.listFiles method which is imported from ‘org.apache.commons.io’ module. A collection ‘files’ is made which is then converted to a JSONArray and is send as the response to the clients.
The response is similar to the sample below and as you can see the array returns the paths of the files which follows the syntax as discussed above.
On the client side this data is displayed in a table which takes data input in the form of an array of json objects therefore the strings from the server are processed into json objects and then passed to the deleted skills table.