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

net.anotheria.anosite.gen.asgenericdata.action.MultiOpDialogGenericBoxHandlerDefsAction Maven / Gradle / Ivy

/**
 ********************************************************************************
 *** MultiOpDialogGenericBoxHandlerDefsAction.java                            ***
 *** generated by AnoSiteGenerator (ASG), Version: 4.2.2                      ***
 *** Copyright (C) 2005 - 2025 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.asgenericdata.action;

import net.anotheria.util.NumberUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.anotheria.maf.action.ActionCommand;
import net.anotheria.maf.action.ActionMapping;
import java.util.List;
import java.util.ArrayList;
import net.anotheria.anosite.gen.asgenericdata.data.GenericBoxHandlerDefFactory;
import net.anotheria.anosite.gen.asgenericdata.data.GenericBoxHandlerDef;
import net.anotheria.anosite.gen.asgenericdata.bean.EditGenericBoxHandlerDefFB;
import net.anotheria.asg.util.bean.PopulateUtility;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;

public class MultiOpDialogGenericBoxHandlerDefsAction extends BaseGenericBoxHandlerDefAction{

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


	@Override
	public ActionCommand execute(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		return super.execute(mapping, req, res);
	} //execute

	public ActionCommand anoDocExecute(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String path = stripPath(mapping.getPath());
		if (path.equals("asgenericdataGenericBoxHandlerDefDelete"))
			return asgenericdataGenericBoxHandlerDefDelete(mapping, req, res);
		if (path.equals("asgenericdataGenericBoxHandlerDefDuplicate"))
			return asgenericdataGenericBoxHandlerDefDuplicate(mapping, req, res);
		if (path.equals("asgenericdataGenericBoxHandlerDefUpdate"))
			return asgenericdataGenericBoxHandlerDefUpdate(mapping, req, res);
		if (path.equals("asgenericdataGenericBoxHandlerDefClose"))
			return asgenericdataGenericBoxHandlerDefClose(mapping, req, res);
		if (path.equals("asgenericdataGenericBoxHandlerDefLock"))
			return asgenericdataGenericBoxHandlerDefLock(mapping, req, res);
		if (path.equals("asgenericdataGenericBoxHandlerDefUnLock"))
			return asgenericdataGenericBoxHandlerDefUnLock(mapping, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionCommand asgenericdataGenericBoxHandlerDefDelete(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String[] iDs = req.getParameterValues(PARAM_ID);
		if (iDs == null){
			throw new RuntimeException("Parameter " + PARAM_ID + " is not set.");
		}
		for (String id : iDs){
			GenericBoxHandlerDef genericboxhandlerdefCurr = getASGenericDataService().getGenericBoxHandlerDef(id);
			if (genericboxhandlerdefCurr instanceof LockableObject){ 
				LockableObject lockable = (LockableObject)genericboxhandlerdefCurr;
				DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
			}
			getASGenericDataService().deleteGenericBoxHandlerDef(id);
		}
		res.sendRedirect("asgenericdataGenericBoxHandlerDefShow?ts="+System.currentTimeMillis());
		return null;
	}

	public ActionCommand asgenericdataGenericBoxHandlerDefDuplicate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String id = getStringParameter(req, PARAM_ID);
		GenericBoxHandlerDef genericboxhandlerdefSrc = getASGenericDataService().getGenericBoxHandlerDef(id);
		GenericBoxHandlerDef genericboxhandlerdefDest = GenericBoxHandlerDefFactory.createGenericBoxHandlerDef(genericboxhandlerdefSrc);


		GenericBoxHandlerDef genericboxhandlerdefCreated = getASGenericDataService().createGenericBoxHandlerDef(genericboxhandlerdefDest);
		res.sendRedirect("asgenericdataGenericBoxHandlerDefEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+genericboxhandlerdefCreated.getId());

		return null;
	}

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

	public ActionCommand asgenericdataGenericBoxHandlerDefUpdate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		EditGenericBoxHandlerDefFB form = new EditGenericBoxHandlerDefFB();
		PopulateUtility.populate(form, req);
		boolean create = false;
		GenericBoxHandlerDef genericboxhandlerdef = null;
		if (form.getId()==null) {
		res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
		return null;
	}
	if (form.getId().length()>0){
		genericboxhandlerdef = (GenericBoxHandlerDef)getASGenericDataService().getGenericBoxHandlerDef(form.getId()).clone();
	}else{
		genericboxhandlerdef = GenericBoxHandlerDefFactory.createGenericBoxHandlerDef();
		create = true;
	}

	String nextAction = req.getParameter("nextAction");
	if (nextAction == null || nextAction.length() == 0)
		nextAction = "close";

	//skipped id because it's readonly.
	genericboxhandlerdef.setName(form.getName());
	genericboxhandlerdef.setClazz(form.getClazz());

	GenericBoxHandlerDef updatedCopy = null;
	if (create){
		updatedCopy = getASGenericDataService().createGenericBoxHandlerDef(genericboxhandlerdef);
	}else{
		canUpdateGenericBoxHandlerDefs(genericboxhandlerdef, req);
		checkGenericBoxHandlerDefs(genericboxhandlerdef, req);
		updatedCopy = getASGenericDataService().updateGenericBoxHandlerDef(genericboxhandlerdef);
	}
	if (nextAction.equalsIgnoreCase("stay")){
		res.sendRedirect("asgenericdataGenericBoxHandlerDefEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
	}else{
		unlockAfterUpdate(genericboxhandlerdef, req);
		res.sendRedirect("asgenericdataGenericBoxHandlerDefShow?ts="+System.currentTimeMillis());
	}
	return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(GenericBoxHandlerDef genericboxhandlerdef, HttpServletRequest req) throws Exception{
	if(((LockableObject)genericboxhandlerdef).isLocked())
		unLockGenericBoxHandlerDefs(genericboxhandlerdef, req, false);
}

public ActionCommand asgenericdataGenericBoxHandlerDefLock(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	GenericBoxHandlerDef genericboxhandlerdefCurr = id != null && !id.equals("") ? getASGenericDataService().getGenericBoxHandlerDef(id) : null;
	if(genericboxhandlerdefCurr != null && genericboxhandlerdefCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)genericboxhandlerdefCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockGenericBoxHandlerDefs(genericboxhandlerdefCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, genericboxhandlerdefCurr));
	return null;
}

public ActionCommand asgenericdataGenericBoxHandlerDefUnLock(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	GenericBoxHandlerDef genericboxhandlerdefCurr = id != null && !id.equals("") ? getASGenericDataService().getGenericBoxHandlerDef(id) : null;
	if(genericboxhandlerdefCurr != null && genericboxhandlerdefCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)genericboxhandlerdefCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockGenericBoxHandlerDefs(genericboxhandlerdefCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, genericboxhandlerdefCurr));
	return null;
}

/**
 * Simplest method for redirect url creation. nextAction == showEdit - going to 'editView', to 'listView' otherwise. 
 */
private String getRedirectUrl(HttpServletRequest req, GenericBoxHandlerDef item){
	String nextAction = req.getParameter("nextAction");
	if (item==null || nextAction == null || nextAction.length() == 0)
		return "asgenericdataGenericBoxHandlerDefShow?ts="+System.currentTimeMillis();
	else
		return nextAction.equals("showEdit") ? "asgenericdataGenericBoxHandlerDefEdit?ts="+System.currentTimeMillis()+"&pId="+item.getId()
		       : "asgenericdataGenericBoxHandlerDefShow?ts="+System.currentTimeMillis();
}

public ActionCommand asgenericdataGenericBoxHandlerDefClose(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	GenericBoxHandlerDef genericboxhandlerdefCurr = id != null && !id.equals("") ? getASGenericDataService().getGenericBoxHandlerDef(id) : null;
	if(genericboxhandlerdefCurr != null && genericboxhandlerdefCurr instanceof LockableObject && ((LockableObject)genericboxhandlerdefCurr).isLocked()) 
		unLockGenericBoxHandlerDefs(genericboxhandlerdefCurr, req, false);
	res.sendRedirect("asgenericdataGenericBoxHandlerDefShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy