All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.asblogdata.action.MultiOpPostsCommentsAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpPostsCommentsAction.java                                          ***
 *** generated by AnoSiteGenerator (ASG), Version: 2.6.3                      ***
 *** Copyright (C) 2005 - 2010 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.asblogdata.action;

import java.util.List;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.anotheria.maf.action.ActionForward;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.maf.bean.FormBean;
import net.anotheria.anosite.gen.asblogdata.data.PostFactory;
import net.anotheria.anosite.gen.asblogdata.data.Post;
import net.anotheria.anosite.gen.asblogdata.bean.CommentsElementFB;
import net.anotheria.anosite.gen.asblogdata.bean.CommentsQuickAddFB;
import net.anotheria.anosite.gen.asblogdata.data.Comment;
import net.anotheria.anosite.gen.asblogdata.data.CommentSortType;
import net.anotheria.webutils.bean.LabelValueBean;
import net.anotheria.anodoc.data.NoSuchDocumentException;
import net.anotheria.util.StringUtils;
import net.anotheria.asg.exception.ASGRuntimeException;


public class MultiOpPostsCommentsAction extends BasePostAction{

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateContainerMultiOpAction

	public ActionForward anoDocExecute(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String path = stripPath(mapping.getPath());
		if (path.equals("asblogdataPostCommentsShow"))
			return asblogdataPostCommentsShow(mapping, af, req, res);
		if (path.equals("asblogdataPostCommentsAdd"))
			return asblogdataPostCommentsAdd(mapping, af, req, res);
		if (path.equals("asblogdataPostCommentsDelete"))
			return asblogdataPostCommentsDelete(mapping, af, req, res);
		if (path.equals("asblogdataPostCommentsMove"))
			return asblogdataPostCommentsMove(mapping, af, req, res);
		if (path.equals("asblogdataPostCommentsQuickAdd"))
			return asblogdataPostCommentsQuickAdd(mapping, af, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListShowActionMethod

	public ActionForward asblogdataPostCommentsShow(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String id = getStringParameter(req, "ownerId");
		Post post = getASBlogDataService().getPost(id);
		addBeanToRequest(req, "ownerId", id);
		checkPosts(post, req);

		CommentsElementFB form = new CommentsElementFB() ;
		form.setPosition(-1);
		form.setOwnerId(post.getId());
		addBeanToRequest(req, "asblogdataPostCommentsElementForm", form);

		CommentsQuickAddFB quickAddForm = new CommentsQuickAddFB() ;
		quickAddForm.setOwnerId(post.getId());
		addBeanToRequest(req, "asblogdataPostCommentsQuickAddForm", quickAddForm);


		//link postCommentLink to ASBlogData.Comment
		List comments = getASBlogDataService().getComments(new CommentSortType(CommentSortType.SORT_BY_NAME));
		List commentsValues = new ArrayList(comments.size());
		for (int i=0; i beans = new ArrayList(size);
		for (int i=0; i targetList = post.getComments();
		String toSwap = targetList.remove(position);
		targetList.add(0, toSwap);
		post.setComments(targetList);
		getASBlogDataService().updatePost(post);
	}

	private void moveDown(Post post, int position) throws ASGRuntimeException {
		if (position targetList = post.getComments();
		String toSwap = targetList.remove(position);
		targetList.add(toSwap);
		post.setComments(targetList);
		getASBlogDataService().updatePost(post);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListAddRowActionMethod

	public ActionForward asblogdataPostCommentsAdd(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		CommentsElementFB form = new CommentsElementFB();
		populateFormBean(req, form);
		String id = form.getOwnerId();
		Post post;
		post = getASBlogDataService().getPost(id);
		canUpdatePosts(post, req);
		checkPosts(post, req);
		post.addCommentsElement(form.getPostCommentLink());
		getASBlogDataService().updatePost(post);
		return asblogdataPostCommentsShow(mapping, af, req, res);
	}

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateListQuickAddActionMethod

	public ActionForward asblogdataPostCommentsQuickAdd(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		CommentsQuickAddFB form = new CommentsQuickAddFB();
		populateFormBean(req, form);
		String id = form.getOwnerId();
		Post post;
		post = getASBlogDataService().getPost(id);
		canUpdatePosts(post, req);
		checkPosts(post, req);
		String paramIdsToAdd = form.getQuickAddIds();

		String idParameters[] = StringUtils.tokenize(paramIdsToAdd, ',');
		for (String anIdParam : idParameters){
			String ids[] = StringUtils.tokenize(anIdParam, '-');
			for (int i=Integer.parseInt(ids[0]); i<=Integer.parseInt(ids[ids.length-1]); i++){
				post.addCommentsElement(""+i);
			}
		}
		getASBlogDataService().updatePost(post);
		return asblogdataPostCommentsShow(mapping, af, req, res);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy