Example #1
0
  // Information needed to get a single file:
  // BASE_PATH, FILE_ID, TIMESTAMP_START, TIMESTAMP_STOP, SOURCE, FILESYSTEM
  private static Vector<Path> getFile(
      FileSystem fs, Hashtable<String, String> config, dbutil db_util) throws Exception {
    Long latestVersion = latestVersion(config, db_util);

    try {
      config.put("timestamp_start", config.get("timestamp_start"));
      config.put("timestamp_real", latestVersion.toString());
      config.put("timestamp_stop", latestVersion.toString());
    } catch (Exception E) {
      logger.error("Tryign to get file that is impossible to generate: " + getFullPath(config));
      return null;
    }
    if (Integer.parseInt(config.get("timestamp_start"))
        > Integer.parseInt(config.get("timestamp_stop"))) {
      return null;
    }
    logger.debug(
        "Getting DB for timestamp "
            + config.get("timestamp_start")
            + " to "
            + config.get("timestamp_stop"));

    String final_result = getFullPath(config);

    String temp_path_base =
        config.get("local_temp_path")
            + "_"
            + config.get("task_id")
            + "_"
            + config.get("run_id")
            + "/";
    Path newPath = new Path(final_result + "*");
    Vector<Path> ret_path = new Vector<Path>();
    String lockName = lock(final_result.replaceAll("/", "_"));
    if (fs.globStatus(newPath).length != 0) {
      ret_path.add(newPath);
      unlock(lockName);
      config.put("full_file_name", final_result);
      return ret_path;
    } else {
      if (!config.get("source").equals("local")) {
        config.put("temp_path_base", temp_path_base);

        config.put("timestamp_start", config.get("timestamp_start"));
        config.put("timestamp_real", latestVersion.toString());
        config.put("timestamp_stop", latestVersion.toString());

        Class<?> sourceClass =
            Class.forName("org.gestore.plugin.source." + config.get("source") + "Source");
        Method process_data = sourceClass.getMethod("process", Hashtable.class, FileSystem.class);
        Object processor = sourceClass.newInstance();
        Object retVal;
        try {
          retVal = process_data.invoke(processor, config, fs);
        } catch (InvocationTargetException E) {
          Throwable exception = E.getTargetException();
          logger.error("Unable to call method in child class: " + exception.toString());
          exception.printStackTrace(System.out);
          unlock(lockName);
          return null;
        }
        FileStatus[] files = (FileStatus[]) retVal;
        if (files == null) {
          logger.error("Error getting files, no files returned");
          return null;
        }

        for (FileStatus file : files) {
          Path cur_file = file.getPath();
          Path cur_local_path = new Path(temp_path_base + config.get("file_id"));
          String suffix = getSuffix(config.get("file_id"), cur_file.getName());
          cur_local_path = cur_local_path.suffix(suffix);
          Path res_path = new Path(new String(final_result + suffix));
          logger.debug("Moving file" + cur_file.toString() + " to " + res_path.toString());
          if (config.get("copy").equals("true")) {
            fs.moveFromLocalFile(cur_file, res_path);
          } else {
            fs.rename(cur_file, res_path);
          }
        }

        config.put("full_file_name", final_result);
      }
    }
    unlock(lockName);
    return ret_path;
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {
    System.out.println("called eventGroupUpload");
    response.setContentType("application/json");
    response.setHeader("Access-Control-Allow-Origin", "*");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    ArrayList<String> data = new ArrayList<String>();
    String appId = request.getParameter("appId");
    String name = request.getParameter("name");
    String imgUrl = request.getParameter("imgUrl");
    String about = request.getParameter("about");
    String rules = request.getParameter("rules");
    String contact = request.getParameter("contact");
    String callback = request.getParameter("callback");
    String responseType = request.getParameter("responseType");

    accessToken token = new accessToken();
    String accessToken = request.getParameter("accessToken");
    if ((accessToken != null) && token.get(accessToken)) {
      if (appId == null) {
        data.add("appId");
      }
      if (name == null) {
        data.add("name");
      }
      if (imgUrl == null) {
        data.add("imgUrl");
      }
      if (about == null) {
        data.add("about");
      }
      if (rules == null) {
        data.add("rules");
      }
      if (contact == null) {
        data.add("contact");
      }
      if (data.size() != 0) {
        obj.put("response", "error");
        obj.put("responseString", "Insufficient Data");
        obj.put("data", data);
      } else {

        try {
          beanEventGroupUpload bean = new beanEventGroupUpload();
          bean.setAppId(appId);
          bean.setName(name);
          bean.setImgUrl(imgUrl);
          bean.setAbout(about);
          bean.setRules(rules);
          bean.setContact(contact);
          daoEventGroupUpload dao = new daoEventGroupUpload();
          bean = dao.create(bean);
          if (bean.getValid()) {
            obj.put("response", "success");
            obj.put("responseString", "event uploaded successfully");
          } else {
            System.out.println("I am here");
            obj.put("response", "error");
            obj.put("responseString", bean.getException());
          }
        } catch (Throwable theException) {
          System.out.println("I am here1");
          obj.put("response", "error");
          obj.put("responseString", theException.toString());
        }
      }
    } else {
      obj.put("response", "error");
      obj.put("responseString", "Session expired");
    }
    if (responseType.equals("jsonp")) out.print(callback + "(" + obj + ")");
    else out.print(obj);
  }