Package com.tubeonfire.entity

Examples of com.tubeonfire.entity.Playlist


  private String changeAllVideosToCategory(HttpSession session,
      HttpServletRequest request) {
    try {
      String strIds = (String) request.getParameter("ids");
      String plId = (String) request.getParameter("plId");
      Playlist pl = PlaylistModel.byId(plId, false);
      if (pl != null) {
        List<Tube> list = new ArrayList<Tube>();
        String[] ids = strIds.split(",");
        for (int i = 0; i < ids.length; i++) {
          if (!ids[i].isEmpty()) {
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  public static Playlist byId(String id, boolean fromCache) {
    init();
    Playlist obj = new Playlist();
    String prefix = cachePrefix + "id_" + id;
    if (cache != null && cache.containsKey(prefix) && fromCache) {
      obj = (Playlist) cache.get(prefix);
    } else {
      try {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public static Playlist byAlias(String alias, boolean fromCache) {
    init();
    Playlist obj = new Playlist();
    String prefix = cachePrefix + "alias_" + alias;
    mapCacheKey.put(prefix, prefix);
    if (cache != null && cache.containsKey(prefix) && fromCache) {
      obj = (Playlist) cache.get(prefix);
    } else {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public static Playlist byId(String id, boolean fromCache) {
    init();
    Playlist obj = new Playlist();
    String prefix = cachePrefix + "id_" + id;
    if (cache != null && cache.containsKey(prefix) && fromCache) {
      obj = (Playlist) cache.get(prefix);
    } else {
      try {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public static Playlist getById(String id) {
    initPm();
    Playlist playList = null;
    Query query = pm.newQuery(Playlist.class);
    query.setFilter("id=='" + id + "' && status==1");
    query.setRange(0, 1);
    List<Playlist> listResult = (List<Playlist>) query.execute();
    if (listResult.size() > 0) {
View Full Code Here

    if (cache != null && cache.containsKey("cachedPl")) {
      result = new ArrayList<Playlist>();
      List<String> cachedPl = (List<String>) cache.get("cachedPl");
      if (cachedPl.size() > 0) {
        for (String stringCate : cachedPl) {
          Playlist pl = new Playlist();
          pl.transformString(stringCate);
          result.add(pl);
        }
      }
    }
    return result;
View Full Code Here

      }
      // delete playlist, return manager page.
      else if (action.equalsIgnoreCase("delete")) {
        if (user != null) {
          String pid = request.getParameter("id");
          Playlist pl = PlaylistModel.getById(pid);
          if (pl.getUserFederatedId().equals(user.getUserId())) {
            pl.setStatus(4);
            PlaylistModel.update(pl);
            PlaylistModel.closePM();
            response.sendRedirect("/playlist/manager");
          } else {
            response.getWriter().println(
                "You don't have permission to do this action.");
          }
        } else {
          response.getWriter().println("User's not login.");
        }

      }
      // add video to playlist.
      else if (action.equalsIgnoreCase("add")) {
        if (request.getParameter("playlist_id") != null
            && request.getParameter("video_id") != null) {
          Playlist plToAdd = PlaylistModel.getById(request
              .getParameter("playlist_id"));
          Tube tub = TubeModel.getByTubeId(request
              .getParameter("video_id"));
          if (tub != null && plToAdd != null) {
            List<Text> listTube = new ArrayList<Text>();
            if (plToAdd.getListTubes().size() > 0) {
              listTube = plToAdd.getListTubes();
            }
            Text tmpText = new Text(tub.toString());
            for (int i = 0; i < listTube.size(); i++) {
              if (listTube.get(i).equals(tmpText)) {
                listTube.remove(i);
                break;
              }
            }
            listTube.add(new Text(tub.toString()));
            plToAdd.setListTubes(listTube);
            PlaylistModel.update(plToAdd);
            PlaylistModel.closePM();
            System.out.println("Ok, video added to playlist");
          } else {
            response.getWriter().println(
                "Cannot add video to playlist.");
          }
        } else {
          response.getWriter().println(
              "Cannot add video to playlist.");
        }
      }
      // edit playlist.
      else if (action.equalsIgnoreCase("edit")) {
        if (user != null) {
          String pid = request.getParameter("id");
          Playlist pl = PlaylistModel.getById(pid);
          if (pl.getUserFederatedId().equals(user.getUserId())) {
            request.setAttribute("result", pl);
            request.getRequestDispatcher("/playlist_edit.jsp")
                .forward(request, response);
          } else {
            response.getWriter()
                .println(
                    "You don't have permission to delete this playlist.");
          }
        } else {
          response.getWriter().println("User's not login.");
        }
      }
      // edit videos in playlist.
      else if (action.equalsIgnoreCase("edit_videos")) {
        if (user != null) {
          String pid = request.getParameter("id");
          Playlist pl = PlaylistModel.getById(pid);
          if (pl.getUserFederatedId().equals(user.getUserId())) {
            request.setAttribute("result", pl);
            request.getRequestDispatcher(
                "/playlist_edit_videos.jsp").forward(request,
                response);
          } else {
            response.getWriter()
                .println(
                    "You don't have permission to delete this playlist.");
          }
        } else {
          response.getWriter().println("User's not login.");
        }
      }
      // remove clip from a playlist.
      else if (action.equalsIgnoreCase("remove_clip")) {
        if (user != null) {
          String id = request.getParameter("id");
          String pId = request.getParameter("pId");
          System.out.println(id);
          System.out.println(pId);
          Tube tub = TubeModel.getByTubeId(id);
          Playlist pl = PlaylistModel.getById(pId);
          if (pl != null && tub != null
              && pl.getUserFederatedId().equals(user.getUserId())) {
            List<Text> newVideos = pl.getListTubes();
            for (int i = 0; i < newVideos.size(); i++) {
              Tube exitTub = new Tube();
              exitTub.transformString(newVideos.get(i).getValue());
              if (tub.getTubeId().equalsIgnoreCase(
                  exitTub.getTubeId())) {
                newVideos.remove(i);
                break;
              }
            }
            pl.setListTubes(newVideos);
            PlaylistModel.update(pl);
            PlaylistModel.closePM();
            response.sendRedirect("/playlist/edit_videos?id="
                + pl.getId());
          } else {
            response.getWriter()
                .println(
                    "You don't have permission to delete this playlist.");
          }
        } else {
          response.getWriter().println("User's not login.");
        }
      }
    }
    // if length = 4, this is view detail playlist request.
    else if (splittedURI.length == 4) {
      if (user != null) {
        List<Playlist> pls = PlaylistModel
            .getByUserId(user.getUserId());
        Playlist pl = null;
        if (pls.size() > 0) {
          for (Playlist playlist : pls) {
            if (playlist.getId().equalsIgnoreCase(splittedURI[2])) {
              pl = playlist;
              break;
            }
          }
        }
        if (pl != null && pl.getListTubes().size() > 0) {
          request.setAttribute("result", pl);
          request.setAttribute("listPl", pls);
          request.getRequestDispatcher("/playlist_show.jsp").forward(
              request, response);
        } else {

        }
      } else {
        Playlist pl = PlaylistModel.getById(splittedURI[2]);
        if (pl != null && pl.getListTubes().size() > 0) {
          request.setAttribute("result", pl);
          request.getRequestDispatcher("/playlist_show.jsp").forward(
              request, response);
        } else {
View Full Code Here

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
      String action = req.getParameter("action");
      if (action.equalsIgnoreCase("create")) {
        Playlist pl = new Playlist();
        if (req.getParameter("title") != null) {
          pl.setTitle(new Text(req.getParameter("title")));
        }
        if (req.getParameter("description") != null) {
          pl.setDescription(new Text(req.getParameter("description")));
        }
        Map<String, List<BlobKey>> blobs = blobstoreService
            .getUploads(req);
        List<BlobKey> blobKeys = blobs.get("myFile");
        if (blobKeys != null && blobKeys.size() > 0) {
          pl.setPictureBlobKey(new Text(blobKeys.get(0)
              .getKeyString()));
        }
        SecureRandom random = null;
        for (int i = 0; i < 10; i++) {
          random = new SecureRandom();
          String id = new BigInteger(130, random).toString(32)
              .substring(0, 11);
          if (!PlaylistModel.isExits(id)) {
            pl.setId(id);
            break;
          }
          pl.setId(null);
        }
        pl.setUserFederatedId(user.getUserId());
        pl.setDoc(Calendar.getInstance().getTime());
        pl.setUpdate(Calendar.getInstance().getTime());
        pl.setAlias(new Text(StringHelper.getAliasByLanguage(pl
            .getTitle().getValue())));
        pl.setStatus(1);
        if (pl.isOk()) {
          PlaylistModel.add(pl);
          System.out.println("Add playlist ok.");
          resp.sendRedirect("/playlist/manager");
        } else {
          System.out.println("Playlist is invalid.");
          resp.sendRedirect("/playlist/create");
        }
      } else if (action.equalsIgnoreCase("edit")) {
        String id = req.getParameter("playlist_id");
        Playlist pl = PlaylistModel.getById(id);
        if (pl != null) {
          if (req.getParameter("title") != null) {
            pl.setTitle(new Text(req.getParameter("title")));
          }
          if (req.getParameter("description") != null) {
            pl.setDescription(new Text(req
                .getParameter("description")));
          }
          Map<String, List<BlobKey>> blobs = blobstoreService
              .getUploads(req);
          List<BlobKey> blobKeys = blobs.get("myFile");
          if (blobKeys != null && blobKeys.size() > 0) {
            pl.setPictureBlobKey(new Text(blobKeys.get(0)
                .getKeyString()));
          }
          pl.setUpdate(Calendar.getInstance().getTime());
          if (pl.isOk()) {
            PlaylistModel.update(pl);
            PlaylistModel.closePM();
            System.out.println("Save playlist ok.");
            resp.sendRedirect("/playlist/manager");
          } else {
View Full Code Here

TOP

Related Classes of com.tubeonfire.entity.Playlist

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.