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

net.anotheria.anosite.gen.assitedata.action.MultiOpDialogSitesAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogSitesAction.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.assitedata.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.assitedata.data.SiteFactory;
import net.anotheria.anosite.gen.assitedata.data.Site;
import net.anotheria.anosite.gen.assitedata.bean.EditSiteFB;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;
import net.anotheria.asg.data.MultilingualObject;
import net.anotheria.maf.bean.annotations.Form;


public class MultiOpDialogSitesAction extends BaseSiteAction{

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


	@Override
	public ActionForward execute(ActionMapping mapping, @Form(EditSiteFB.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("assitedataSiteDelete"))
			return assitedataSiteDelete(mapping, af, req, res);
		if (path.equals("assitedataSiteDuplicate"))
			return assitedataSiteDuplicate(mapping, af, req, res);
		if (path.equals("assitedataSiteUpdate"))
			return assitedataSiteUpdate(mapping, af, req, res);
		if (path.equals("assitedataSiteClose"))
			return assitedataSiteClose(mapping, af, req, res);
		if (path.equals("assitedataSiteCopyLang"))
			return assitedataSiteCopyLang(mapping, af, req, res);
		if (path.equals("assitedataSiteSwitchMultilang"))
			return assitedataSiteSwitchMultilang(mapping, af, req, res);
		if (path.equals("assitedataSiteLock"))
			return assitedataSiteLock(mapping, af, req, res);
		if (path.equals("assitedataSiteUnLock"))
			return assitedataSiteUnLock(mapping, af, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionForward assitedataSiteDelete(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){
		Site siteCurr = getASSiteDataService().getSite(id);
		if (siteCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)siteCurr;
		DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
		}
		getASSiteDataService().deleteSite(id);
	}
	res.sendRedirect("assitedataSiteShow?ts="+System.currentTimeMillis());
	return null;
}

public ActionForward assitedataSiteDuplicate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Site siteSrc = getASSiteDataService().getSite(id);
	Site siteDest = SiteFactory.createSite(siteSrc);




	Site siteCreated = getASSiteDataService().createSite(siteDest);
	res.sendRedirect("assitedataSiteEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+siteCreated.getId());

	return null;
}

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

public ActionForward assitedataSiteUpdate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	EditSiteFB form = (EditSiteFB) af;
	boolean create = false;
	Site site = null;
	if (form.getId()==null) {
	res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
	return null;
}
if (form.getId().length()>0){
	site = (Site)getASSiteDataService().getSite(form.getId()).clone();
}else{
	site = SiteFactory.createSite();
	create = true;
}

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

//skipped id because it's readonly.
site.setName(form.getName());
site.setTitleEN(form.getTitleEN());
site.setTitleDE(form.getTitleDE());
site.setSubtitleEN(form.getSubtitleEN());
site.setSubtitleDE(form.getSubtitleDE());
site.setKeywordsEN(form.getKeywordsEN());
site.setKeywordsDE(form.getKeywordsDE());
site.setDescriptionEN(form.getDescriptionEN());
site.setDescriptionDE(form.getDescriptionDE());
// skipped container topNavi
// skipped container mainNavi
site.setStartpage(form.getStartpage());
site.setSearchpage(form.getSearchpage());
site.setLanguageselector(form.isLanguageselector());
site.setHeaderBackground(form.getHeaderBackground());
site.setSiteLogo(form.getSiteLogo());

Site updatedCopy = null;
if (create){
	updatedCopy = getASSiteDataService().createSite(site);
}else{
	canUpdateSites(site, req);
	checkSites(site, req);
	updatedCopy = getASSiteDataService().updateSite(site);
}
if (nextAction.equalsIgnoreCase("stay")){
	res.sendRedirect("assitedataSiteEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
}else{
	unlockAfterUpdate(site, req);
	res.sendRedirect("assitedataSiteShow?ts="+System.currentTimeMillis());
}
return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(Site site, HttpServletRequest req) throws Exception{
	if(((LockableObject)site).isLocked())
		unLockSites(site, req, false);
}

public ActionForward assitedataSiteCopyLang(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String sourceLanguage = req.getParameter("pSrcLang");
	if (sourceLanguage==null || sourceLanguage.length()==0)
		throw new RuntimeException("No source language");

	String destLanguage = req.getParameter("pDestLang");
	if (destLanguage==null || destLanguage.length()==0)
		throw new RuntimeException("No destination language");

	String id = getStringParameter(req, PARAM_ID);
	Site site = getASSiteDataService().getSite(id);
	canUpdateSites(site, req);
	checkSites(site, req);
	site.copyLANG2LANG(sourceLanguage, destLanguage);
	getASSiteDataService().updateSite(site);
	res.sendRedirect("assitedataSiteEdit?ts="+System.currentTimeMillis()+"&pId="+id);
	return null;
}

public ActionForward assitedataSiteSwitchMultilang(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	String value = getStringParameter(req, "value");
	Site site = getASSiteDataService().getSite(id);
	canUpdateSites(site, req);
	checkSites(site, req);
	((MultilingualObject)site).setMultilingualDisabledInstance(Boolean.valueOf(value));
	getASSiteDataService().updateSite(site);
	res.sendRedirect("assitedataSiteEdit?ts="+System.currentTimeMillis()+"&pId="+id);
	return null;
}

public ActionForward assitedataSiteLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Site siteCurr = id != null && !id.equals("") ? getASSiteDataService().getSite(id) : null;
	if(siteCurr != null && siteCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)siteCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockSites(siteCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, siteCurr));
	return null;
}

public ActionForward assitedataSiteUnLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Site siteCurr = id != null && !id.equals("") ? getASSiteDataService().getSite(id) : null;
	if(siteCurr != null && siteCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)siteCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockSites(siteCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, siteCurr));
	return null;
}

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

public ActionForward assitedataSiteClose(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Site siteCurr = id != null && !id.equals("") ? getASSiteDataService().getSite(id) : null;
	if(siteCurr != null && siteCurr instanceof LockableObject && ((LockableObject)siteCurr).isLocked()) 
		unLockSites(siteCurr, req, false);
	res.sendRedirect("assitedataSiteShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy