public Scanner(
      final ServiceRegistry serviceRegistry,
      final String userId,
      final int batchWeight,
      final WritableBulkImportStatus importStatus,
      final ThreadPauser pauser,
      final BulkImportSource source,
      final Map<String, List<String>> parameters,
      final NodeRef target,
      final BulkImportThreadPoolExecutor importThreadPool,
      final BatchImporter batchImporter,
      final List<BulkImportCompletionHandler> completionHandlers) {
    // PRECONDITIONS
    assert serviceRegistry != null : "serviceRegistry must not be null.";
    assert userId != null : "userId must not be null.";
    assert batchWeight > 0 : "batchWeight must be > 0.";
    assert importStatus != null : "importStatus must not be null.";
    assert pauser != null : "pauser must not be null.";
    assert source != null : "source must not be null.";
    assert parameters != null : "parameters must not be null.";
    assert target != null : "target must not be null.";
    assert importThreadPool != null : "importThreadPool must not be null.";
    assert batchImporter != null : "batchImporter must not be null.";

    // Body
    this.userId = userId;
    this.batchWeight = batchWeight;
    this.importStatus = importStatus;
    this.pauser = pauser;
    this.source = source;
    this.parameters = parameters;
    this.target = target;
    this.targetAsPath = convertNodeRefToPath(serviceRegistry, target);
    this.importThreadPool = importThreadPool;
    this.batchImporter = batchImporter;
    this.completionHandlers = completionHandlers;

    this.replaceExisting =
        parameters.get(PARAMETER_REPLACE_EXISTING) == null
            ? false
            : Boolean.parseBoolean(parameters.get(PARAMETER_REPLACE_EXISTING).get(0));
    this.dryRun =
        parameters.get(PARAMETER_DRY_RUN) == null
            ? false
            : Boolean.parseBoolean(parameters.get(PARAMETER_DRY_RUN).get(0));

    this.currentBatchNumber = 0;
    this.currentBatch = null;
    this.weightOfCurrentBatch = 0;
    this.filePhase = false;
    this.multiThreadedImport = false;
  }
Beispiel #2
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;
  }