/** Copy the Artifact to the toolkit */
  private void resolveFileDependency(Artifact a, Map<String, Object> config) throws IOException {

    JSONArray includes = (JSONArray) topology.builder().getConfig().get("includes");
    if (includes == null)
      topology.builder().getConfig().put("includes", includes = new JSONArray());

    final File dstDir =
        new File((String) (config.get(ContextProperties.TOOLKIT_DIR)), a.dstDirName);
    File absFile = a.absPath.toFile();
    try {
      JSONObject include = new JSONObject();
      include.put("source", a.absPath.toString());
      include.put("target", a.dstDirName);
      if (false && absFile.isFile()) {
        Files.copy(
            a.absPath,
            new File(dstDir, absFile.getName()).toPath(),
            StandardCopyOption.REPLACE_EXISTING);
      } else if (false && absFile.isDirectory()) {
        copyDirectoryToDirectory(absFile, dstDir);
      }
      includes.add(include);
    } catch (IOException e) {
      throw new IOException("Error copying file dependency " + a.absPath + ": " + e, e);
    }
  }
  private void getAllDriverReports(HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    UserProfileDoa userProfileDoa = new UserProfileDoaImpl();

    String driverUserName = request.getParameter("driverUserName");

    UserProfile driverProfile = userProfileDoa.retriveUserProfile(driverUserName);

    ParentMonitoringDao parentMonitoringDao = new ParentMonitoringDaoImpl();

    List<DriverReport> driverReports = parentMonitoringDao.getAllDriverReports(driverProfile);

    JSONObject json = new JSONObject();
    json.put("message", "success");
    json.put("result_code", 0);

    JSONArray result_data = new JSONArray();

    for (DriverReport driverReport : driverReports) {

      JSONObject jsonReport = new JSONObject();
      jsonReport.put("report_date", driverReport.getDate());
      jsonReport.put("report_lat", driverReport.getLat());
      jsonReport.put("report_lon", driverReport.getLon());
      jsonReport.put("report_reason", driverReport.getReason());
      jsonReport.put("report_time", driverReport.getTime());

      result_data.add(jsonReport);
    }

    json.put("result_data", result_data);

    response.getWriter().print(json);
  }
  /**
   * Resolve the dependencies. Copies jars to the impl/lib part of the bundle and file/directory
   * dependencies to the bundle.
   *
   * @param config context configuration
   * @throws IOException
   * @throws URISyntaxException
   */
  public void resolveDependencies(Map<String, Object> config)
      throws IOException, URISyntaxException {
    for (BOperatorInvocation op : operatorToJarDependencies.keySet()) {
      ArrayList<String> jars = new ArrayList<String>();

      for (Path pa : operatorToJarDependencies.get(op)) {
        String jarName = resolveDependency(pa, config);
        jars.add("impl/lib/" + jarName);
      }

      String[] jarPaths = jars.toArray(new String[jars.size()]);
      op.setParameter("jar", jarPaths);
    }

    ArrayList<String> jars = new ArrayList<String>();
    for (Path dep : globalDependencies) {
      if (previouslyCopiedDependencies.containsKey(dep)) {
        continue;
      }
      String jarName = resolveDependency(dep, config);
      jars.add("impl/lib/" + jarName);
    }

    List<BOperator> ops = topology.builder().getOps();
    if (jars.size() != 0) {
      for (BOperator op : ops) {
        if (op instanceof BOperatorInvocation) {
          BOperatorInvocation bop = (BOperatorInvocation) op;
          if (Functional.class.isAssignableFrom(bop.op().getOperatorClass())) {
            JSONObject params = (JSONObject) bop.json().get("parameters");
            JSONObject op_jars = (JSONObject) params.get("jar");
            if (null == op_jars) {
              JSONObject val = new OrderedJSONObject();
              val.put("value", new JSONArray());
              params.put("jar", val);
              op_jars = val;
            }
            JSONArray value = (JSONArray) op_jars.get("value");
            for (String jar : jars) {
              value.add(jar);
            }
          }
        }
      }
    }

    for (Artifact dep : globalFileDependencies) resolveFileDependency(dep, config);
  }
  private JSONArray getComments(String itemNumber) {
    JSONArray returnArray = new JSONArray();
    CouchDbConnector dbc = _db.createConnector(dbname, true);

    Map<String, String> doc = new HashMap<String, String>();

    ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
    List<Map> result = dbc.queryView(query, Map.class);
    JSONArray jsonresult = new JSONArray();
    for (Map element : result) {
      JSONObject obj = new JSONObject();
      obj.putAll(element);
      if (itemNumber == null || obj.get("itemNumber").equals(itemNumber)) jsonresult.add(obj);
    }

    System.out.println(jsonresult.toString());

    return jsonresult;
  }
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String action = request.getParameter("action");
    JSONArray result = new JSONArray();

    switch (action) {
      case "getComments":
        result = getComments(request.getParameter("itemNumber"));
        break;
      case "addComment":
        addComment(request.getParameter("itemNumber"), request.getParameter("comment"));
        break;
    }
    response.setContentType("text/html; charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.getOutputStream().print(result.serialize());
    return;
  }
Ejemplo n.º 6
0
  /**
   * If exists, process the VCAP_SERVICES environment variable in order to get the username,
   * password and baseURL
   */
  private void processVCAP_Services() {
    logger.info("Processing VCAP_SERVICES");
    JSONObject sysEnv = getVcapServices();
    if (sysEnv == null) return;
    logger.info("Looking for: " + serviceName);

    for (Object key : sysEnv.keySet()) {
      String keyString = (String) key;
      logger.info("found key: " + key);
      if (keyString.startsWith(serviceName)) {
        JSONArray services = (JSONArray) sysEnv.get(key);
        JSONObject service = (JSONObject) services.get(0);
        JSONObject credentials = (JSONObject) service.get("credentials");
        baseURL = (String) credentials.get("url");
        username = (String) credentials.get("username");
        password = (String) credentials.get("password");
        logger.info("baseURL  = " + baseURL);
        logger.info("username = "******"password = "******"Doesn't match /^" + serviceName + "/");
      }
    }
  }