private void createDefaultScriptFile(PigScript object) {
    String userScriptsPath = context.getProperties().get("scripts.dir");
    if (userScriptsPath == null) {
      String msg = "scripts.dir is not configured!";
      LOG.error(msg);
      throw new MisconfigurationFormattedException("scripts.dir");
    }
    int checkId = 0;

    boolean fileCreated;
    String newFilePath;
    do {
      String normalizedName = object.getTitle().replaceAll("[^a-zA-Z0-9 ]+", "").replaceAll(" ", "_").toLowerCase();
      String timestamp = new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date());
      newFilePath = String.format(userScriptsPath +
              "/%s-%s%s.pig", normalizedName, timestamp, (checkId == 0)?"":"_"+checkId);
      LOG.debug("Trying to create new file " + newFilePath);

      try {
        FSDataOutputStream stream = UserLocalObjects.getHdfsApi(context).create(newFilePath, false);
        stream.close();
        fileCreated = true;
        LOG.debug("File created successfully!");
      } catch (FileAlreadyExistsException e) {
        fileCreated = false;
        LOG.debug("File already exists. Trying next id");
      } catch (IOException e) {
        try {
          delete(object.getId());
        } catch (ItemNotFound itemNotFound) {
          throw new ServiceFormattedException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
        }
        throw new ServiceFormattedException("Error in creation: " + e.toString(), e);
      } catch (InterruptedException e) {
        try {
          delete(object.getId());
        } catch (ItemNotFound itemNotFound) {
          throw new ServiceFormattedException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
        }
        throw new ServiceFormattedException("Error in creation: " + e.toString(), e);
      }
      checkId += 1;
    } while (!fileCreated);

    object.setPigScript(newFilePath);
    getPigStorage().store(object);
  }
Constructor
@param context View Context instance
contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java