/*
 * $Id: EditDefaultCatAclAction.java,v 1.10 2004/11/10 15:02:45 koppy Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: EditDefaultCatAclAction.java,v $
 * Revision 1.10  2004/11/10 15:02:45  koppy
 * Projektweite Überarbeitung von Error-Logs, Stacktraces,..
 *
 * Revision 1.9  2004/08/09 12:49:29  jonyp
 * bug fix: search parentCats for default acl during retrievAcl
 *
 * Revision 1.8  2004/05/25 21:08:52  marbobo
 * + getTargetId() setTargetId() getSubTargetId() setSubTargetId()
 *
 * Revision 1.7  2004/04/27 15:10:25  jonyp
 * added few lines of code to add new permissions (a/q)
 *
 * 
 * Created on 29.10.2003
 */
package vkc.view.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForward;

import vkc.db.entities.VKCCategory;
import vkc.db.serializer.VKCAclSerializer;
import vkc.exception.DBException;
import vkc.misc.VKCLogManager;
import vkc.security.VKCAcl;
import vkc.view.form.EditAclForm;

/**
 * DOCUMENT ME!!!
 * 
 * @author vchris
 */
public class EditDefaultCatAclAction extends EditCatAclAction {

	protected VKCAcl retrieveAcl(HttpServletRequest request, VKCCategory category) throws DBException {
		return VKCAclSerializer.getDefaultCatAcl(null, category, true);
	}
	
	protected VKCAcl retrieveParentAcl(HttpServletRequest request, VKCCategory category) throws DBException {
		return VKCAclSerializer.getDefaultCatAcl(null, category, true);
	}

	protected ActionForward exitActionForward(EditAclForm form) {
		Integer targetId = form.getTargetId();
		Integer subTargetId = form.getSubTargetId();
		
		if ( targetId == null && subTargetId == null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId != null && subTargetId != null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&targetId=" + targetId + 
				"&subTargetId=" + subTargetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId != null && subTargetId == null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&targetId=" + targetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}
		
		if ( targetId == null && subTargetId != null ) {
			return new ActionForward( 
				"/editCategoryAcl.do" + 
				"?categoryId=" + form.getCategoryId() + 
				"&init=true" + 
				"&subTargetId=" + subTargetId + 
				"&sourcePageId=" + form.getSourcePageId() );
		}

		return new ActionForward( 
			"/editCategoryAcl.do" + 
			"?categoryId=" + form.getCategoryId() + 
			"&init=true" + 
			"&sourcePageId=" + form.getSourcePageId() );
	}

	protected void performSaveAcl(HttpServletRequest request, EditAclForm aclForm, VKCAcl acl) {		 
		VKCLogManager.infoLog(this,"Saving Default-ACL...");
		try {
			aclForm.updateAcl(request, acl);
			VKCAclSerializer.saveDefaultAcl(acl);
			VKCLogManager.infoLog(this,"...Default-ACL successfully saved!");
			request.setAttribute("vkc.acl.succeeded","vkc.acl.saved");
		}
		catch (Exception ex) {
			VKCLogManager.errorLog(this,"1","...Error while saving Default-ACL!", ex);
			request.setAttribute("vkc.acl.failed","vkc.acl.notSaved");
		}
	}
}
