YtStatistics stats = videoEntry.getStatistics();
if (stats != null) {
viewCount = stats.getViewCount();
}
VideoSubmission submission = new VideoSubmission(Long.parseLong(assignmentId));
submission.setArticleUrl(articleUrl);
submission.setVideoId(videoId);
submission.setVideoTitle(title);
submission.setVideoDescription(description);
submission.setVideoTags(sortedTags);
submission.setVideoLocation(location);
submission.setPhoneNumber(phoneNumber);
submission.setVideoDate(date);
submission.setYouTubeName(youTubeName);
userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);
submission.setViewCount(viewCount);
submission.setVideoSource(VideoSubmission.VideoSource.EXISTING_VIDEO);
submission.setNotifyEmail(email);
AdminConfig adminConfig = adminConfigDao.getAdminConfig();
if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
// NO_MOD is set, auto approve all submission
// TODO: This isn't enough, as the normal approval flow (adding the
// branding, tags, emails,
// etc.) isn't taking place.
submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);
// Add video to YouTube playlist if it isn't in it already.
// This code is kind of ugly and is mostly copy/pasted from UpdateVideoSubmissionStatus
// TODO: It should be refactored into a common helper method somewhere...
if (!submission.isInPlaylist()) {
Assignment assignment = assignmentDao.getAssignmentById(assignmentId);
if (assignment == null) {
log.warning(String.format("Couldn't find assignment id '%d' for video id '%s'.",
assignmentId, videoId));
} else {
String playlistId = assignment.getPlaylistId();
if (util.isNullOrEmpty(playlistId)) {
log.warning(String.format("Assignment id '%d' doesn't have an associated playlist.",
assignmentId));
} else {
apiManager.setAuthSubToken(adminConfig.getYouTubeAuthSubToken());
if (apiManager.insertVideoIntoPlaylist(playlistId, videoId)) {
submission.setIsInPlaylist(true);
}
}
}
}
}