Example #1
0
  @Override
  public long getNumRepos(String username) {
    try {
      THttpClient transport = new THttpClient("http://datahub.csail.mit.edu/service");
      TBinaryProtocol protocol = new TBinaryProtocol(transport);
      DataHub.Client client = new DataHub.Client(protocol);

      ConnectionParams params = new ConnectionParams();
      params.setApp_id(DatahubDataModel.getKibitzAppName());
      params.setApp_token(DatahubDataModel.getKibitzAppId());
      params.setRepo_base(username);
      Connection connection = client.open_connection(params);

      ResultSet res =
          client.execute_sql(
              connection,
              "select count(distinct schemaname) from pg_tables where tableowner = '"
                  + username
                  + "';",
              null);
      HashMap<String, Integer> colToIndex = DatahubDataModel.getFieldNames(res);

      for (Tuple t : res.getTuples()) {
        List<ByteBuffer> cells = t.getCells();
        return Long.parseLong(new String(cells.get(colToIndex.get("count")).array()));
      }
    } catch (DBException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return 0;
  }
Example #2
0
  @Override
  public List<String> getColumns(String username, String repo, String table) {
    try {
      THttpClient transport = new THttpClient("http://datahub.csail.mit.edu/service");
      TBinaryProtocol protocol = new TBinaryProtocol(transport);
      DataHub.Client client = new DataHub.Client(protocol);

      ConnectionParams params = new ConnectionParams();
      params.setApp_id(DatahubDataModel.getKibitzAppName());
      params.setApp_token(DatahubDataModel.getKibitzAppId());
      params.setRepo_base(username);
      Connection connection = client.open_connection(params);

      List<String> columns = new ArrayList<String>();

      ResultSet res =
          client.execute_sql(
              connection,
              "select * from information_schema.columns where table_schema='"
                  + repo
                  + "' and table_name='"
                  + table
                  + "';",
              null);
      HashMap<String, Integer> colToIndex = DatahubDataModel.getFieldNames(res);

      for (Tuple t : res.getTuples()) {
        List<ByteBuffer> cells = t.getCells();
        columns.add(new String(cells.get(colToIndex.get("column_name")).array()));
      }
      return columns;
    } catch (DBException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  };
Example #3
0
  @Override
  public List<Recommender> getRecommenders(String username) {
    try {
      THttpClient transport = new THttpClient("http://datahub.csail.mit.edu/service");
      TBinaryProtocol protocol = new TBinaryProtocol(transport);
      DataHub.Client client = new DataHub.Client(protocol);

      ConnectionParams params = new ConnectionParams();
      params.setApp_id(DatahubDataModel.getKibitzAppName());
      params.setApp_token(DatahubDataModel.getKibitzAppId());
      params.setRepo_base(DatahubDataModel.getDefaultDatahubUsername());
      Connection connection = client.open_connection(params);

      List<Recommender> recommenders = new ArrayList<Recommender>();

      ResultSet res =
          client.execute_sql(
              connection,
              "SELECT database,username,ratings_table,overall_ratings,ratings_column FROM kibitz_users.recommenders WHERE username = '******';",
              null);
      HashMap<String, Integer> colToIndex = DatahubDataModel.getFieldNames(res);
      for (Tuple t : res.getTuples()) {
        List<ByteBuffer> cells = t.getCells();
        Recommender recommender = new Recommender();
        String database = new String(cells.get(colToIndex.get("database")).array());
        recommender.setUsername(new String(cells.get(colToIndex.get("username")).array()));
        recommender.setRepoName(database);
        recommender.setHomepage("default");
        recommender.setRecommenderName(
            new String(cells.get(colToIndex.get("ratings_table")).array()).split("\\.")[1]);
        if (Boolean.parseBoolean(new String(cells.get(colToIndex.get("overall_ratings")).array())))
          recommender.setRatingsColumn(
              new String(cells.get(colToIndex.get("ratings_column")).array()));
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");

        File file =
            new File(
                DatahubDataModel.WEBSERVER_DIR + username + "/" + database + "/js/initiate.js");
        Reader reader = new FileReader(file);
        jsEngine.eval(reader);

        recommender.setClientKey(jsEngine.get("client_key").toString());
        recommender.setTitle(jsEngine.get("title").toString());
        recommender.setDescription(jsEngine.get("description").toString());
        recommender.setVideo(jsEngine.get("video").toString());
        recommender.setImage(jsEngine.get("image").toString());
        recommender.setPrimaryKey(jsEngine.get("primary_key").toString());

        List<String> displayItems = new ArrayList<String>();

        int varsLength = Integer.parseInt(jsEngine.eval("display_items.length;").toString());
        for (int i = 0; i < varsLength; i++) {
          displayItems.add((String) jsEngine.eval("display_items[" + i + "];"));
        }

        recommender.setDisplayItems(displayItems);

        HashMap<String, String> itemMap =
            new HashMap<String, String>((Map<String, String>) jsEngine.get("item_types"));
        recommender.setItemTypes(itemMap);
        recommender.setNumRecs((int) Double.parseDouble(jsEngine.get("num_recs").toString()));
        recommender.setMaxRatingVal(
            (int) Double.parseDouble(jsEngine.get("maxRatingVal").toString()));

        recommenders.add(recommender);
      }

      return recommenders;
    } catch (ScriptException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DBException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }