}
// 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 {