Implementation of Delete Skill Feature for Admins in SUSI.AI

Implementation of Delete Skill Feature for Admins in SUSI.AI

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.

  • DeleteSkillService.java
  • UndoDeletedSkillService.java
  • SkillsToBeDeleted.java

DeleteSkillService

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:

/cms/deleteSkill.json

 

Whenever we call this endpoint specifying the above parameters, the ‘skill_name.txt’ file which is found at the path

/modal/group / language / skill_name.txt

 

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.

deleteSkill = () => {
  this.setState({
    loading: true
  });

  let url;

  url =

    `${urls.API_URL}/cms/deleteSkill.json?` +

    'model=' +

    this.state.skillModel +

    '&group=' +

    this.state.skillGroup +

    '&language=' +

    this.state.skillLanguage +

    '&skill=' +

    this.state.skillName +

    '&access_token=' +

    cookies.get('loggedIn');

  $.ajax({

    url: url,

    dataType: 'jsonp',

    jsonp: 'callback',

    crossDomain: true,

    success: function(data) {

      this.setState({
        loading: false
      });

      this.setState({
        deleteSuccessDialog: true
      });

    }.bind(this),

    error: function(err) {

      console.log(err);

      this.setState({
        loading: false
      });

      this.setState({
        deleteFailureDialog: true
      });

    }.bind(this),

  });

};

 

UndeDeleteSkillService

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:

/cms/undoDeleteSkill.json

 

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.

/modal/group/language/skill_name.txt

 

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.

restoreSkill = () => {
  this.setState({
    loading: true
  });

  let url;

  url =

    `${urls.API_URL}/cms/undoDeleteSkill.json?` +

    'model=' +

    this.state.skillModel +

    '&group=' +

    this.state.skillGroup +

    '&language=' +

    this.state.skillLanguage +

    '&skill=' +

    this.state.skillName +

    '&access_token=' +

    cookies.get('loggedIn');

  $.ajax({

    url: url,

    dataType: 'jsonp',

    jsonp: 'callback',

    crossDomain: true,

    success: function(data) {

      this.setState({
        loading: false
      });

      this.setState({
        restoreSuccessDialog: true
      });

    }.bind(this),

    error: function(err) {

      console.log(err);

      this.setState({
        loading: false
      });

      this.setState({
        restoreFailureDialog: true
      });

    }.bind(this),

  });

};

 

SkillsToBeDeleted

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.

String model_name = call.get("model", "general");

File model = new File(DAO.deleted_skill_dir, model_name);

JSONObject json = new JSONObject();

Collection files = FileUtils.listFiles(

  new File(DAO.deleted_skill_dir.getPath()),

  TrueFileFilter.INSTANCE,

  TrueFileFilter.TRUE

);

JSONArray jsArray = new JSONArray(files);

json.put("skills", jsArray);

json.put("accepted", true);

json.put("message", "Success: Fetched skill list");

return new ServiceResponse(json);

 

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.

"skills": [
  "data/deleted_skill_dir/models/general/Utilities/en/domain_check.txt",
  "data/deleted_skill_dir/models/general/Knowledge/en/quotes.txt"
],

 

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.

for (let i of response.skills) {
  const current = i.slice(i.indexOf('/models/') + 8, i.length - 4);

  const splitString = current.split('/');

  let deletedSkill = {

    model: splitString[0],

    group: splitString[1],

    language: splitString[2],

    skillName: splitString[3],

  };

  deletedSkills.push(deletedSkill);

}

 

Resources

Close Menu