else if (action.equalsIgnoreCase("add_video")) {
if (request.getParameter("nextId") == null
&& request.getParameter("prevId") == null) {
Category cate = CategoryModel.getByCateAlias(request
.getParameter("categoryAlias"));
Tube tub = TubeModel.getByTubeId(request
.getParameter("tubeId"));
if (tub == null) {
tub = TubeService.searchById(
request.getParameter("tubeId"), true);
}
if (tub.getCategoryAlias() != null
&& tub.getCategoryAlias().equalsIgnoreCase(
cate.getAlias())) {
} else {
cate.setCount(cate.getCount() + 1);
}
tub.setCategoryAlias(cate.getAlias());
tub.setCatePosition(1000000);
TubeModel.update(tub);
CategoryModel.update(cate);
TubeModel.closePM();
CategoryModel.closePM();
} else if (request.getParameter("prevId") == null) {
Category cate = CategoryModel.getByCateAlias(request
.getParameter("categoryAlias"));
Tube tub = TubeModel.getByTubeId(request
.getParameter("tubeId"));
if (tub == null) {
tub = TubeService.searchById(
request.getParameter("tubeId"), true);
}
if (tub.getCategoryAlias() != null
&& tub.getCategoryAlias().equalsIgnoreCase(
cate.getAlias())) {
} else {
cate.setCount(cate.getCount() + 1);
}
Tube nextTub = TubeModel.getByTubeId(request
.getParameter("nextId"));
tub.setCategoryAlias(cate.getAlias());
tub.setCatePosition(nextTub.getCatePosition() / 2);
TubeModel.update(tub);
CategoryModel.update(cate);
TubeModel.closePM();
CategoryModel.closePM();
} else if (request.getParameter("nextId") == null) {
Category cate = CategoryModel.getByCateAlias(request
.getParameter("categoryAlias"));
Tube tub = TubeModel.getByTubeId(request
.getParameter("tubeId"));
if (tub == null) {
tub = TubeService.searchById(
request.getParameter("tubeId"), true);
}
if (tub.getCategoryAlias() != null
&& tub.getCategoryAlias().equalsIgnoreCase(
cate.getAlias())) {
} else {
cate.setCount(cate.getCount() + 1);
}
Tube prevTub = TubeModel.getByTubeId(request
.getParameter("prevId"));
tub.setCategoryAlias(cate.getAlias());
tub.setCatePosition(prevTub.getCatePosition() + 1000000);
TubeModel.update(tub);
CategoryModel.update(cate);
TubeModel.closePM();
CategoryModel.closePM();
} else {
Category cate = CategoryModel.getByCateAlias(request
.getParameter("categoryAlias"));
Tube tub = TubeModel.getByTubeId(request
.getParameter("tubeId"));
if (tub == null) {
tub = TubeService.searchById(
request.getParameter("tubeId"), true);
}
if (tub.getCategoryAlias() != null
&& tub.getCategoryAlias().equalsIgnoreCase(
cate.getAlias())) {
} else {
cate.setCount(cate.getCount() + 1);
}
Tube nextTub = TubeModel.getByTubeId(request
.getParameter("nextId"));
Tube prevTub = TubeModel.getByTubeId(request
.getParameter("prevId"));
tub.setCategoryAlias(cate.getAlias());
// calculate tub position.
tub.setCatePosition((nextTub.getCatePosition() + prevTub
.getCatePosition()) / 2);
System.out.println(tub.getTitle().getValue()
+ " was added to category : "
+ cate.getTitle().getValue() + " between "
+ prevTub.getTitle().getValue() + " and "
+ nextTub.getTitle().getValue());
CategoryModel.update(cate);
TubeModel.update(tub);
CategoryModel.closePM();
TubeModel.closePM();
}
response.getWriter().println(
"<div><p style='color:green'>Update success</p></div>");
}
// reorder category index
else if (action.equalsIgnoreCase("re_order_index")) {
if (request.getParameter("prevAlias") == null
&& request.getParameter("nextAlias") == null) {
Category current = CategoryModel.getByCateAlias(request
.getParameter("currentAlias"));
current.setIndex(1000000);
CategoryModel.update(current);
CategoryModel.closePM();
} else if (request.getParameter("prevAlias") == null) {
Category current = CategoryModel.getByCateAlias(request
.getParameter("currentAlias"));
Category next = CategoryModel.getByCateAlias(request
.getParameter("nextAlias"));
current.setIndex(next.getIndex() / 2);
CategoryModel.update(current);
CategoryModel.closePM();
} else if (request.getParameter("nextAlias") == null) {
Category current = CategoryModel.getByCateAlias(request
.getParameter("currentAlias"));
Category pre = CategoryModel.getByCateAlias(request
.getParameter("prevAlias"));
current.setIndex(pre.getIndex() + 1000000);
CategoryModel.update(current);
CategoryModel.closePM();
} else {
Category current = CategoryModel.getByCateAlias(request
.getParameter("currentAlias"));
Category pre = CategoryModel.getByCateAlias(request
.getParameter("prevAlias"));
Category next = CategoryModel.getByCateAlias(request
.getParameter("nextAlias"));
current.setIndex((pre.getIndex() + next.getIndex()) / 2);
CategoryModel.update(current);
CategoryModel.closePM();
}
response.getWriter().println(
"<div><p style='color:green'>Update success</p></div>");
}
// remove clips from category.
else if (action.equalsIgnoreCase("remove_video")) {
Tube tub = TubeModel
.getByTubeId(request.getParameter("tubeId"));
Category cate = CategoryModel.getByCateAlias(request
.getParameter("categoryAlias"));
if (cate.getCount() > 0) {
cate.setCount(cate.getCount() - 1);
}
CategoryModel.update(cate);
CategoryModel.closePM();
tub.setCategoryAlias("");
TubeModel.update(tub);
TubeModel.closePM();
response.getWriter()
.println(
"<div><p style='color:green'>Video removed success !</p></div>");