/*
 * $Id: ChangeCategoryCreatorForm.java,v 1.1 2005/08/17 12:58:07 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008
 *           (c) Universität Paderborn 2008
 * All Rights Reserved.
 *
 * $Log: ChangeCategoryCreatorForm.java,v $
 * Revision 1.1  2005/08/17 12:58:07  jonyp
 * *** empty log message ***
 *
 */

package vkc.administration.form;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCCategory;
import vkc.db.serializer.VKCUserSerializer;
import vkc.db.serializer.VKCCategorySerializer;
import vkc.exception.DBException;
import vkc.view.PageId;
import vkc.view.form.BasicActionForm;


public final class ChangeCategoryCreatorForm extends BasicActionForm {

	private Integer selectedNewPublisherId = null;
	private Integer categoryId = null;
	private VKCCategory category = null;

    private Integer selectedIndex 	= new Integer( -1 );
	private Integer sourcePageId 	= PageId.CATEGORY_VIEW;
	private Integer subTargetId 	= null;
	private Integer targetId 		= null;


	public void reset( ActionMapping mapping, HttpServletRequest request ) {
		super.reset( mapping, request );

		selectedNewPublisherId = null;
		categoryId = null;
	}

	public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) {
		ActionErrors errors = new ActionErrors();
		
		return errors;
	}

	public List getNewPublisherList() throws DBException {
	    return VKCUserSerializer.retrieveValidNewPublisherInfos(getCategory().getCreatorId());
	}
    
    public Integer getSelectedNewPublisherId() {
        return selectedNewPublisherId;
    }

    public void setSelectedNewPublisherId(Integer selectedPublisherId) {
        this.selectedNewPublisherId = selectedPublisherId;
    }
    
    public Integer getOldPublisherId() throws DBException {
        return getCategory().getCreatorId();
    }
    
    public String getOldPublisherLastnameLabel() throws DBException {
        return VKCUserSerializer.retrieveUserInfo(getCategory().getCreatorId()).getLastnameLabel();
    }
    
	public Integer getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Integer categoryId) {
		this.categoryId = categoryId;
	}

	public Integer getSelectedIndex() {
		return selectedIndex;
	}

	public void setSelectedIndex(Integer selectedIndex) {
		this.selectedIndex = selectedIndex;
	}

	public Integer getSourcePageId() {
		return sourcePageId;
	}

	public void setSourcePageId(Integer sourcePageId) {
		this.sourcePageId = sourcePageId;
	}

	public Integer getSubTargetId() {
		return subTargetId;
	}

	public void setSubTargetId(Integer subTargetId) {
		this.subTargetId = subTargetId;
	}

	public Integer getTargetId() {
		return targetId;
	}

	public void setTargetId(Integer targetId) {
		this.targetId = targetId;
	}
	
	public VKCCategory getCategory() throws DBException {
        if ( category == null) {
            category = VKCCategorySerializer.retrieveCategory(getCategoryId());
        }
        
        return category;
    }
}
