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

net.anotheria.anosite.gen.asfeature.action.MultiOpDialogFeaturesAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogFeaturesAction.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.asfeature.action;

import net.anotheria.util.NumberUtils;
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 java.util.List;
import java.util.ArrayList;
import net.anotheria.anosite.gen.asfeature.data.FeatureFactory;
import net.anotheria.anosite.gen.asfeature.data.Feature;
import net.anotheria.anosite.gen.asfeature.bean.EditFeatureFB;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;
import net.anotheria.maf.bean.annotations.Form;


public class MultiOpDialogFeaturesAction extends BaseFeatureAction{

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


	@Override
	public ActionForward execute(ActionMapping mapping, @Form(EditFeatureFB.class) FormBean formBean, HttpServletRequest req, HttpServletResponse res) throws Exception{
		return super.execute(mapping, formBean, req, res);
	} //execute

	public ActionForward anoDocExecute(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String path = stripPath(mapping.getPath());
		if (path.equals("asfeatureFeatureDelete"))
			return asfeatureFeatureDelete(mapping, af, req, res);
		if (path.equals("asfeatureFeatureDuplicate"))
			return asfeatureFeatureDuplicate(mapping, af, req, res);
		if (path.equals("asfeatureFeatureUpdate"))
			return asfeatureFeatureUpdate(mapping, af, req, res);
		if (path.equals("asfeatureFeatureClose"))
			return asfeatureFeatureClose(mapping, af, req, res);
		if (path.equals("asfeatureFeatureLock"))
			return asfeatureFeatureLock(mapping, af, req, res);
		if (path.equals("asfeatureFeatureUnLock"))
			return asfeatureFeatureUnLock(mapping, af, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionForward asfeatureFeatureDelete(ActionMapping mapping, FormBean af, 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){
		Feature featureCurr = getASFeatureService().getFeature(id);
		if (featureCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)featureCurr;
		DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
		}
		getASFeatureService().deleteFeature(id);
	}
	res.sendRedirect("asfeatureFeatureShow?ts="+System.currentTimeMillis());
	return null;
}

public ActionForward asfeatureFeatureDuplicate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Feature featureSrc = getASFeatureService().getFeature(id);
	Feature featureDest = FeatureFactory.createFeature(featureSrc);



	Feature featureCreated = getASFeatureService().createFeature(featureDest);
	res.sendRedirect("asfeatureFeatureEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+featureCreated.getId());

	return null;
}

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

public ActionForward asfeatureFeatureUpdate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	EditFeatureFB form = (EditFeatureFB) af;
	boolean create = false;
	Feature feature = null;
	if (form.getId()==null) {
	res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
	return null;
}
if (form.getId().length()>0){
	feature = (Feature)getASFeatureService().getFeature(form.getId()).clone();
}else{
	feature = FeatureFactory.createFeature();
	create = true;
}

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

//skipped id because it's readonly.
feature.setName(form.getName());
feature.setEnabled(form.isEnabled());
feature.setObsolete(form.isObsolete());
// skipped container guards
feature.setAccessOperation(form.getAccessOperation());
feature.setDescription(form.getDescription());

Feature updatedCopy = null;
if (create){
	updatedCopy = getASFeatureService().createFeature(feature);
}else{
	canUpdateFeatures(feature, req);
	checkFeatures(feature, req);
	updatedCopy = getASFeatureService().updateFeature(feature);
}
if (nextAction.equalsIgnoreCase("stay")){
	res.sendRedirect("asfeatureFeatureEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
}else{
	unlockAfterUpdate(feature, req);
	res.sendRedirect("asfeatureFeatureShow?ts="+System.currentTimeMillis());
}
return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(Feature feature, HttpServletRequest req) throws Exception{
	if(((LockableObject)feature).isLocked())
		unLockFeatures(feature, req, false);
}

public ActionForward asfeatureFeatureLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Feature featureCurr = id != null && !id.equals("") ? getASFeatureService().getFeature(id) : null;
	if(featureCurr != null && featureCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)featureCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockFeatures(featureCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, featureCurr));
	return null;
}

public ActionForward asfeatureFeatureUnLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Feature featureCurr = id != null && !id.equals("") ? getASFeatureService().getFeature(id) : null;
	if(featureCurr != null && featureCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)featureCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockFeatures(featureCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, featureCurr));
	return null;
}

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

public ActionForward asfeatureFeatureClose(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Feature featureCurr = id != null && !id.equals("") ? getASFeatureService().getFeature(id) : null;
	if(featureCurr != null && featureCurr instanceof LockableObject && ((LockableObject)featureCurr).isLocked()) 
		unLockFeatures(featureCurr, req, false);
	res.sendRedirect("asfeatureFeatureShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy