private static void addToRegistry(String rootPath, File file, int tenantId) {
    try {
      Registry registry = getRegistry(tenantId);

      // This path is used to store the file resource under registry
      String fileRegistryPath =
          REGISTRY_GADGET_STORAGE_PATH
              + file.getAbsolutePath().substring(rootPath.length()).replaceAll("[/\\\\]+", "/");

      // Adding the file to the Registry
      Resource fileResource = registry.newResource();
      fileResource.setMediaType("application/vnd.wso2-gadget+xml");
      fileResource.setContentStream(new FileInputStream(file));
      registry.put(fileRegistryPath, fileResource);

    } catch (RegistryException e) {
      log.error(e.getMessage(), e);
    } catch (FileNotFoundException e) {
      log.error(e.getMessage(), e);
    }
  }
  /**
   * This method is used to load custom security scenarios used inside Identity STS componsnts.
   *
   * @throws Exception
   */
  private void loadSecurityScenarios() throws Exception {

    Registry registry = registryService.getConfigSystemRegistry();

    try {
      // Scenarios are listed in resources/scenario-config.xml
      URL resource = bundleContext.getBundle().getResource("scenario-config.xml");
      XmlConfiguration xmlConfiguration =
          new XmlConfiguration(resource.openStream(), SecurityConstants.SECURITY_NAMESPACE);

      OMElement[] elements = xmlConfiguration.getElements("//ns:Scenario");

      boolean transactionStarted = Transaction.isStarted();
      if (!transactionStarted) {
        registry.beginTransaction();
      }

      for (OMElement scenarioEle : elements) {
        SecurityScenario scenario = new SecurityScenario();
        String scenarioId = scenarioEle.getAttribute(SecurityConstants.ID_QN).getAttributeValue();

        scenario.setScenarioId(scenarioId);
        scenario.setSummary(
            scenarioEle.getFirstChildWithName(SecurityConstants.SUMMARY_QN).getText());
        scenario.setDescription(
            scenarioEle.getFirstChildWithName(SecurityConstants.DESCRIPTION_QN).getText());
        scenario.setCategory(
            scenarioEle.getFirstChildWithName(SecurityConstants.CATEGORY_QN).getText());
        scenario.setWsuId(scenarioEle.getFirstChildWithName(SecurityConstants.WSUID_QN).getText());
        scenario.setType(scenarioEle.getFirstChildWithName(SecurityConstants.TYPE_QN).getText());

        OMElement genPolicyElem =
            scenarioEle.getFirstChildWithName(SecurityConstants.IS_GEN_POLICY_QN);
        if (genPolicyElem != null && genPolicyElem.getText().equals("false")) {
          scenario.setGeneralPolicy(false);
        }

        String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;

        for (Iterator modules =
                scenarioEle.getFirstChildWithName(SecurityConstants.MODULES_QN).getChildElements();
            modules.hasNext(); ) {
          String module = ((OMElement) modules.next()).getText();
          scenario.addModule(module);
        }

        // Save it in the DB
        SecurityScenarioDatabase.put(scenarioId, scenario);

        // Store the scenario in the Registry
        if (!scenarioId.equals(SecurityConstants.SCENARIO_DISABLE_SECURITY)
            && !scenarioId.equals(SecurityConstants.POLICY_FROM_REG_SCENARIO)) {
          Resource scenarioResource = new ResourceImpl();
          scenarioResource.setContentStream(
              bundleContext.getBundle().getResource(scenarioId + "-policy.xml").openStream());
          if (!registry.resourceExists(resourceUri)) {
            registry.put(resourceUri, scenarioResource);
          }
        }
      }
      if (!transactionStarted) {
        registry.commitTransaction();
      }
    } catch (Exception e) {
      registry.rollbackTransaction();
      throw e;
    }
  }