public void init(ConfigurationContext configurationContext) {

    tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    String artifactPath = CarbonUtils.getCarbonRepository() + "gadgets";
    File artifactsDir = new File(artifactPath);

    // checking whether its the gadget server is so, setting the gadget path
    String serverName = ServerConfiguration.getInstance().getFirstProperty("Name").trim();

    if (serverName.contains(DashboardConstants.PRODUCT_SERVER_NAME)
        || serverName.contains(DashboardConstants.SERVICE_SERVER_NAME)) {
      REGISTRY_GADGET_STORAGE_PATH =
          DashboardConstants.GS_REGISTRY_ROOT + DashboardConstants.GADGET_PATH;
    }

    if (!artifactsDir.exists()) {
      // If the directory is not there create it
      boolean created = artifactsDir.mkdir();
      if (!created) {
        log.debug("Directory could not be created at : " + artifactPath);
      }
    }

    if (log.isDebugEnabled()) {
      log.debug("Initializing Gadget Deployer..");
    }
  }
  /**
   * Deploys a .gar archive to the Registry path in REGISTRY_GADGET_STORAGE_PATH
   *
   * @param deploymentFileData - info about the deployed file
   * @throws DeploymentException - error while deploying .gar archive
   */
  public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    try {

      //            int tenantId;
      //            try {
      //                tenantId =
      // MultitenantUtils.getTenantId(DashboardContext.getConfigContext());
      //            } catch (Exception e) {
      //                throw new DeploymentException(e);
      //            }

      UserRegistry registry = getRegistry(tenantID);

      // Extracting archive
      String extractedArchiveDir = extractGarArchive(deploymentFileData.getAbsolutePath());

      // Set permission for anonymous read. We do it here because it should happen always in order
      // to support mounting a remote registry.

      if (registry != null) {
        AuthorizationManager accessControlAdmin = registry.getUserRealm().getAuthorizationManager();

        if (!accessControlAdmin.isRoleAuthorized(
            CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME,
            RegistryConstants.CONFIG_REGISTRY_BASE_PATH + REGISTRY_GADGET_STORAGE_PATH,
            ActionConstants.GET)) {
          accessControlAdmin.authorizeRole(
              CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME,
              RegistryConstants.CONFIG_REGISTRY_BASE_PATH + REGISTRY_GADGET_STORAGE_PATH,
              ActionConstants.GET);
        }

        File gadgetsDir = new File(extractedArchiveDir);
        if (gadgetsDir.exists()) {
          beginFileTansfer(gadgetsDir, tenantID);

          log.info(
              "Successfully populated gadgets from archive ."
                  + deploymentFileData.getAbsolutePath()
                  + " to the registry.");
        } else {
          log.info("Couldn't find contents at '" + extractedArchiveDir + "'. Giving up.");
        }
      }

    } catch (RegistryException e) {
      throw new DeploymentException("An error occured while deploying gadget archive", e);
    } catch (CarbonException e) {
      throw new DeploymentException("An error occured while deploying gadget archive", e);
    } catch (UserStoreException e) {
      throw new DeploymentException("An error occured while deploying gadget archive", e);
    }
  }
 /**
  * This method try to delete the temporary file, If it fails it will just log a warning msg.
  *
  * @param file
  * @throws IOException
  */
 private void delete(File file) throws IOException {
   if (file != null && file.exists() && !file.delete()) {
     log.warn("Failed to delete file/directory at path: " + file.getAbsolutePath());
   }
 }