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

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

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogGenericGuardDefsAction.java                                 ***
 *** generated by AnoSiteGenerator (ASG), Version: 3.2.2                      ***
 *** Copyright (C) 2005 - 2023 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.GenericGuardDefFactory;
import net.anotheria.anosite.gen.asgenericdata.data.GenericGuardDef;
import net.anotheria.anosite.gen.asgenericdata.bean.EditGenericGuardDefFB;
import net.anotheria.asg.util.bean.PopulateUtility;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;

public class MultiOpDialogGenericGuardDefsAction extends BaseGenericGuardDefAction{

	// 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("asgenericdataGenericGuardDefDelete"))
			return asgenericdataGenericGuardDefDelete(mapping, req, res);
		if (path.equals("asgenericdataGenericGuardDefDuplicate"))
			return asgenericdataGenericGuardDefDuplicate(mapping, req, res);
		if (path.equals("asgenericdataGenericGuardDefUpdate"))
			return asgenericdataGenericGuardDefUpdate(mapping, req, res);
		if (path.equals("asgenericdataGenericGuardDefClose"))
			return asgenericdataGenericGuardDefClose(mapping, req, res);
		if (path.equals("asgenericdataGenericGuardDefLock"))
			return asgenericdataGenericGuardDefLock(mapping, req, res);
		if (path.equals("asgenericdataGenericGuardDefUnLock"))
			return asgenericdataGenericGuardDefUnLock(mapping, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionCommand asgenericdataGenericGuardDefDelete(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){
			GenericGuardDef genericguarddefCurr = getASGenericDataService().getGenericGuardDef(id);
			if (genericguarddefCurr instanceof LockableObject){ 
				LockableObject lockable = (LockableObject)genericguarddefCurr;
				DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
			}
			getASGenericDataService().deleteGenericGuardDef(id);
		}
		res.sendRedirect("asgenericdataGenericGuardDefShow?ts="+System.currentTimeMillis());
		return null;
	}

	public ActionCommand asgenericdataGenericGuardDefDuplicate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String id = getStringParameter(req, PARAM_ID);
		GenericGuardDef genericguarddefSrc = getASGenericDataService().getGenericGuardDef(id);
		GenericGuardDef genericguarddefDest = GenericGuardDefFactory.createGenericGuardDef(genericguarddefSrc);


		GenericGuardDef genericguarddefCreated = getASGenericDataService().createGenericGuardDef(genericguarddefDest);
		res.sendRedirect("asgenericdataGenericGuardDefEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+genericguarddefCreated.getId());

		return null;
	}

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

	public ActionCommand asgenericdataGenericGuardDefUpdate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		EditGenericGuardDefFB form = new EditGenericGuardDefFB();
		PopulateUtility.populate(form, req);
		boolean create = false;
		GenericGuardDef genericguarddef = null;
		if (form.getId()==null) {
		res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
		return null;
	}
	if (form.getId().length()>0){
		genericguarddef = (GenericGuardDef)getASGenericDataService().getGenericGuardDef(form.getId()).clone();
	}else{
		genericguarddef = GenericGuardDefFactory.createGenericGuardDef();
		create = true;
	}

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

	//skipped id because it's readonly.
	genericguarddef.setName(form.getName());
	genericguarddef.setClazz(form.getClazz());
	genericguarddef.setParameter1(form.getParameter1());
	genericguarddef.setParameter2(form.getParameter2());
	genericguarddef.setParameter3(form.getParameter3());
	genericguarddef.setParameter4(form.getParameter4());
	genericguarddef.setParameter5(form.getParameter5());
	genericguarddef.setDescription(form.getDescription());

	GenericGuardDef updatedCopy = null;
	if (create){
		updatedCopy = getASGenericDataService().createGenericGuardDef(genericguarddef);
	}else{
		canUpdateGenericGuardDefs(genericguarddef, req);
		checkGenericGuardDefs(genericguarddef, req);
		updatedCopy = getASGenericDataService().updateGenericGuardDef(genericguarddef);
	}
	if (nextAction.equalsIgnoreCase("stay")){
		res.sendRedirect("asgenericdataGenericGuardDefEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
	}else{
		unlockAfterUpdate(genericguarddef, req);
		res.sendRedirect("asgenericdataGenericGuardDefShow?ts="+System.currentTimeMillis());
	}
	return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(GenericGuardDef genericguarddef, HttpServletRequest req) throws Exception{
	if(((LockableObject)genericguarddef).isLocked())
		unLockGenericGuardDefs(genericguarddef, req, false);
}

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

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

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

public ActionCommand asgenericdataGenericGuardDefClose(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	GenericGuardDef genericguarddefCurr = id != null && !id.equals("") ? getASGenericDataService().getGenericGuardDef(id) : null;
	if(genericguarddefCurr != null && genericguarddefCurr instanceof LockableObject && ((LockableObject)genericguarddefCurr).isLocked()) 
		unLockGenericGuardDefs(genericguarddefCurr, req, false);
	res.sendRedirect("asgenericdataGenericGuardDefShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy