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

net.anotheria.anosite.gen.ascustomaction.action.MultiOpDialogActionMappingDefsAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogActionMappingDefsAction.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.ascustomaction.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.ascustomaction.data.ActionMappingDefFactory;
import net.anotheria.anosite.gen.ascustomaction.data.ActionMappingDef;
import net.anotheria.anosite.gen.ascustomaction.bean.EditActionMappingDefFB;
import net.anotheria.asg.util.bean.PopulateUtility;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;

public class MultiOpDialogActionMappingDefsAction extends BaseActionMappingDefAction{

	// 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("ascustomactionActionMappingDefDelete"))
			return ascustomactionActionMappingDefDelete(mapping, req, res);
		if (path.equals("ascustomactionActionMappingDefDuplicate"))
			return ascustomactionActionMappingDefDuplicate(mapping, req, res);
		if (path.equals("ascustomactionActionMappingDefUpdate"))
			return ascustomactionActionMappingDefUpdate(mapping, req, res);
		if (path.equals("ascustomactionActionMappingDefClose"))
			return ascustomactionActionMappingDefClose(mapping, req, res);
		if (path.equals("ascustomactionActionMappingDefLock"))
			return ascustomactionActionMappingDefLock(mapping, req, res);
		if (path.equals("ascustomactionActionMappingDefUnLock"))
			return ascustomactionActionMappingDefUnLock(mapping, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionCommand ascustomactionActionMappingDefDelete(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){
			ActionMappingDef actionmappingdefCurr = getASCustomActionService().getActionMappingDef(id);
			if (actionmappingdefCurr instanceof LockableObject){ 
				LockableObject lockable = (LockableObject)actionmappingdefCurr;
				DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
			}
			getASCustomActionService().deleteActionMappingDef(id);
		}
		res.sendRedirect("ascustomactionActionMappingDefShow?ts="+System.currentTimeMillis());
		return null;
	}

	public ActionCommand ascustomactionActionMappingDefDuplicate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String id = getStringParameter(req, PARAM_ID);
		ActionMappingDef actionmappingdefSrc = getASCustomActionService().getActionMappingDef(id);
		ActionMappingDef actionmappingdefDest = ActionMappingDefFactory.createActionMappingDef(actionmappingdefSrc);



		ActionMappingDef actionmappingdefCreated = getASCustomActionService().createActionMappingDef(actionmappingdefDest);
		res.sendRedirect("ascustomactionActionMappingDefEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+actionmappingdefCreated.getId());

		return null;
	}

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

	public ActionCommand ascustomactionActionMappingDefUpdate(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
		EditActionMappingDefFB form = new EditActionMappingDefFB();
		PopulateUtility.populate(form, req);
		boolean create = false;
		ActionMappingDef actionmappingdef = null;
		if (form.getId()==null) {
		res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
		return null;
	}
	if (form.getId().length()>0){
		actionmappingdef = (ActionMappingDef)getASCustomActionService().getActionMappingDef(form.getId()).clone();
	}else{
		actionmappingdef = ActionMappingDefFactory.createActionMappingDef();
		create = true;
	}

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

	//skipped id because it's readonly.
	actionmappingdef.setName(form.getName());
	actionmappingdef.setAction(form.getAction());
	actionmappingdef.setUrl(form.getUrl());
	actionmappingdef.setPage(form.getPage());
	actionmappingdef.setParameters(form.getParameters());
	actionmappingdef.setCommand(form.getCommand());
	// skipped container localizationBundles

	ActionMappingDef updatedCopy = null;
	if (create){
		updatedCopy = getASCustomActionService().createActionMappingDef(actionmappingdef);
	}else{
		canUpdateActionMappingDefs(actionmappingdef, req);
		checkActionMappingDefs(actionmappingdef, req);
		updatedCopy = getASCustomActionService().updateActionMappingDef(actionmappingdef);
	}
	if (nextAction.equalsIgnoreCase("stay")){
		res.sendRedirect("ascustomactionActionMappingDefEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
	}else{
		unlockAfterUpdate(actionmappingdef, req);
		res.sendRedirect("ascustomactionActionMappingDefShow?ts="+System.currentTimeMillis());
	}
	return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(ActionMappingDef actionmappingdef, HttpServletRequest req) throws Exception{
	if(((LockableObject)actionmappingdef).isLocked())
		unLockActionMappingDefs(actionmappingdef, req, false);
}

public ActionCommand ascustomactionActionMappingDefLock(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	ActionMappingDef actionmappingdefCurr = id != null && !id.equals("") ? getASCustomActionService().getActionMappingDef(id) : null;
	if(actionmappingdefCurr != null && actionmappingdefCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)actionmappingdefCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockActionMappingDefs(actionmappingdefCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, actionmappingdefCurr));
	return null;
}

public ActionCommand ascustomactionActionMappingDefUnLock(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	ActionMappingDef actionmappingdefCurr = id != null && !id.equals("") ? getASCustomActionService().getActionMappingDef(id) : null;
	if(actionmappingdefCurr != null && actionmappingdefCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)actionmappingdefCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockActionMappingDefs(actionmappingdefCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, actionmappingdefCurr));
	return null;
}

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

public ActionCommand ascustomactionActionMappingDefClose(ActionMapping mapping, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	ActionMappingDef actionmappingdefCurr = id != null && !id.equals("") ? getASCustomActionService().getActionMappingDef(id) : null;
	if(actionmappingdefCurr != null && actionmappingdefCurr instanceof LockableObject && ((LockableObject)actionmappingdefCurr).isLocked()) 
		unLockActionMappingDefs(actionmappingdefCurr, req, false);
	res.sendRedirect("ascustomactionActionMappingDefShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy