HttpSession session = req.getSession();
String type = (String) req.getParameter("type");
String channelId = (String) req.getParameter("channelId");
String playlistId = (String) req.getParameter("playlistId");
Mission mission = new Mission();
Playlist pl = PlaylistModel.byId(playlistId, false);
if (pl != null) {
if (YoutubeService.checkChannel(channelId)) {
if (type.equals("2")) {
YoutubeService tubeService = new YoutubeService();
tubeService.setPage(1);
tubeService.setLimit(49);
List<Tube> listToAdd = new ArrayList<Tube>();
tubeService.searchByChannel(channelId, true);
for (Tube tube : tubeService.getListResult()) {
tube.setPlaylistId(playlistId);
listToAdd.add(tube);
}
TubeModel.insert(listToAdd);
mission.setId(IdUniqueHelper.getId());
mission.setSearchHd(1);
mission.setSearchType(1);
mission.setSearchKeyword(channelId);
mission.setPlaylistId(playlistId);
mission.setSearchLimit(tubeService.getLimit());
if (tubeService.getListResult().size() > 0
&& !tubeService.isTooManyRecentCallError()) {
mission.setSearchPage(tubeService.getPage() + 1);
} else {
mission.setSearchPage(tubeService.getPage());
}
mission.setSearchTotalPage(tubeService.getTotalPage());
mission.setType(2);
mission.setTitle("Get videos from channel " + channelId
+ " to playlist " + pl.getTitle());
MissionModel.insert(mission);
session.setAttribute("success", "Action success !");
resp.sendRedirect("/admin/mission/add");
} else if (type.equals("1")) {
mission.setId(IdUniqueHelper.getId());