Package com.tubeonfire.entity

Examples of com.tubeonfire.entity.Tube


        query = Query.newBuilder().setOptions(options)
            .build(queryString.toString());
        docResult = INDEX.search(query);
        if (docResult.getNumberFound() > 0) {
          Tube obj = new Tube();
          for (ScoredDocument scoredDocument : docResult) {
            obj = TubeSearchEngine
                .documentToObjectByReflection(scoredDocument);
            listResult.add(obj);
          }
View Full Code Here


          query = Query.newBuilder().setOptions(options)
              .build(queryString.toString());
          docResult = INDEX.search(query);

          if (docResult.getNumberFound() > 0) {
            Tube tub = new Tube();
            for (ScoredDocument scoredDocument : docResult) {
              tub = TubeSearchEngine
                  .documentToObjectByReflection(scoredDocument);
              keyPool.add(tub.getId());
            }
          }
          cache.put(playlistKeyPoolPrefix, keyPool);
        }
        // get list id random from pool
        List<String> relateKey = new ArrayList<String>();
        if (keyPool.size() > 20) {
          System.out.println(">20");
          Random randomGenerator = new Random();
          int index = randomGenerator
              .nextInt((int) (keyPool.size() / 2));
          relateKey = keyPool.subList(index, (index + 10));
        } else if (keyPool.size() < 5) {
          System.out.println("<5");
          options = QueryOptions.newBuilder().setLimit(10).build();
          query = Query.newBuilder().setOptions(options).build("");
          docResult = INDEX.search(query);

          if (docResult.getNumberFound() > 0) {
            Tube tub = new Tube();
            for (ScoredDocument scoredDocument : docResult) {
              tub = TubeSearchEngine
                  .documentToObjectByReflection(scoredDocument);
              relateKey.add(tub.getId());
            }
          }
        } else {
          System.out.println(">5<20");
          relateKey = keyPool;
        }

        for (String string : relateKey) {
          Tube tub = getById(string);
          if (tub != null) {
            listResult.add(tub);
          }
        }
        if (listResult.size() > 0) {
View Full Code Here

        query = Query.newBuilder().setOptions(options)
            .build(queryString.toString());
        docResult = INDEX.search(query);
        totalReturn = (int) docResult.getNumberReturned();
        if (docResult.getNumberFound() > 0) {
          Tube obj = new Tube();
          for (ScoredDocument scoredDocument : docResult) {
            obj = TubeSearchEngine
                .documentToObjectByReflection(scoredDocument);
            listResult.add(obj);
          }
View Full Code Here

    }
    return docBuilder;
  }

  public static Tube documentToObjectByReflection(ScoredDocument doc) {
    Tube obj = new Tube();
    for (java.lang.reflect.Field f : obj.getClass().getDeclaredFields()) {
      f.setAccessible(true);
      if (f.getType().getSimpleName().equals("String")) {
        try {
          StringBuilder tmpString = new StringBuilder();
          tmpString.append(doc.getOnlyField(f.getName()).getText());
View Full Code Here

            VideoFeed.class);
        totalResult = videoFeed.getTotalResults();
        System.out.println("Found : " + totalResult);
        initCache();
        for (VideoEntry videoEntry : videoFeed.getEntries()) {
          Tube tube = new Tube();
          tube = videoEntryToTube(videoEntry);
          if (tube != null) {
            listResult.add(tube);
          }
        }
View Full Code Here

        VideoFeed videoFeed = service.query(query, VideoFeed.class);
        totalResult = videoFeed.getTotalResults();
        System.out.println("Found : " + totalResult);
        initCache();
        for (VideoEntry videoEntry : videoFeed.getEntries()) {
          Tube tube = videoEntryToTube(videoEntry);
          if (tube != null) {
            listResult.add(tube);
          }
        }
        System.out.println("Return : " + listResult.size());
View Full Code Here

      e.printStackTrace();
    }
  }

  public void searchById(String id) {
    Tube tub = new Tube();
    try {
      String prefix = "tubeModel_" + "id_" + id;
      listResult = new ArrayList<Tube>();
      if (cache != null && cache.containsKey(prefix)) {
        tub = (Tube) cache.get(prefix);
View Full Code Here

  }

  public static void updateDatabase(TreeMap<String, Long> mapIdView) {
    try {
      for (String id : mapIdView.keySet()) {
        Tube obj = TubeModel.getById(id);
        if (obj != null) {
          long view = mapIdView.get(id);
          obj.setView(view + obj.getView());
          TubeModel.update(obj);
        }
      }
      cache.remove(cachePrefix + "mapIdView");
      com.tubeonfire.model.TubeModel.clearModelCache();
View Full Code Here

      e.printStackTrace();
    }
  }

  public static Tube searchStaticById(String id) {
    Tube tub = new Tube();
    try {
      String prefix = "";
      prefix = cachePrefix + "id_" + id;
      if (cache != null && cache.containsKey(prefix)) {
        tub = (Tube) cache.get(prefix);
View Full Code Here

    return author;
  }

  @SuppressWarnings("unchecked")
  public static Tube videoEntryToTube(VideoEntry entry) {
    Tube tube = new Tube();
    try {
      tube.setId(entry.getMediaGroup().getVideoId());
      if (entry.getMediaGroup().getThumbnails() != null
          && entry.getMediaGroup().getThumbnails().size() > 1) {
        tube.setImageUrl(entry.getMediaGroup().getThumbnails().get(1)
            .getUrl());
      }
      tube.setTitle(entry.getMediaGroup().getTitle()
          .getPlainTextContent());
      if (entry.getMediaGroup().getDescription() != null) {
        tube.setDescription(entry.getMediaGroup().getDescription()
            .getPlainTextContent());
      }
      tube.setAlias(StringHelper.getAliasByLanguage(tube.getTitle()));
      tube.setAuthorUrl(entry.getAuthors().get(0).getUri());
      if (entry.getMediaGroup().getDuration() != null) {
        long duration = entry.getMediaGroup().getDuration();
        int hours = (int) (duration / 3600);
        int remainder = (int) (duration - hours * 3600);
        int minutes = remainder / 60;
        remainder = remainder - minutes * 60;
        int second = remainder;
        tube.setDuration(duration);
        tube.setTotalTime(((hours > 0) ? (hours + ":") : "")
            + String.format("%02d", minutes) + ":"
            + String.format("%02d", second));
      }
      if (entry.getMediaGroup().getCategories() != null
          && entry.getMediaGroup().getCategories().size() > 0) {
        tube.setChannelId(StringHelper.replace(entry.getMediaGroup()
            .getCategories().get(0).getLabel()));
        tube.setChannelName(entry.getMediaGroup().getCategories()
            .get(0).getLabel());
      }

      tube.setPublished(new Date(entry.getPublished().getValue()));
      if (entry.getStatistics() != null) {
        tube.setYoutubeView(entry.getStatistics().getViewCount());
      }
      tube.setStatus(1);
      initCache();
      cache.put(cachePrefix + "id_" + tube.getId(), tube);
      return tube;
    } catch (Exception e) {
      log.warning(e.toString());
      e.printStackTrace();
      return null;
View Full Code Here

TOP

Related Classes of com.tubeonfire.entity.Tube

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.