/*
 * $Id: ShowVersionsForm.java,v 1.5 2006/08/30 21:08:15 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ShowVersionsForm.java,v $
 * Revision 1.5  2006/08/30 21:08:15  marbobo
 * + Rückkehr zur Projekt- und Funktionssicht korrigiert
 *
 * Revision 1.4  2006/02/02 11:58:42  korowa
 * Möglichkeit zwieschen Veränderungen vorwärts und rückwärts zu springen
 *
 * Revision 1.3  2006/01/27 10:21:52  korowa
 * Link zu Dokumenten beim Vergleich hinzugefügt
 *
 * Revision 1.2  2006/01/26 12:45:00  korowa
 * *** empty log message ***
 *
 * Revision 1.1  2006/01/20 12:44:07  korowa
 * Ermöglicht ein Vergleich von verschiedenen Versionen eines Dokumentes
 *
 *
 */
package vkc.view.form;

import javax.servlet.http.HttpServletRequest;

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

import vkc.db.entities.VKCDocument;
import vkc.db.entities.VKCEntity;

import vkc.db.serializer.VKCDocumentSerializer;
import vkc.exception.DBException;
import vkc.misc.VKCLogManager;
import vkc.view.PageId;

public final class ShowVersionsForm extends BasicActionForm {
	private Integer categoryId = VKCEntity.ID_UNDEFINED;

	private Integer documentId = null;

	private Integer selectedId = null;

	private Integer sourcePageId = PageId.CATEGORY_VIEW;

	private Integer targetId = null;

	private Integer subTargetId = null;

	private String[] selectedDocuments = new String[0];

	private VKCDocument firstVersion = null;

	private VKCDocument secondVersion = null;

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);
		categoryId = VKCEntity.ID_UNDEFINED;
		documentId = null;
		selectedId = null;
		sourcePageId = PageId.CATEGORY_VIEW;
		targetId = null;
		subTargetId = null;
		selectedDocuments = new String[0];
		firstVersion = null;
		secondVersion = null;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		try {
			firstVersion = VKCDocumentSerializer.retrieveDocument(Integer
					.valueOf(getSelectedDocuments()[0]));
			secondVersion = VKCDocumentSerializer.retrieveDocument(Integer
					.valueOf(getSelectedDocuments()[1]));
			if (!firstVersion.getPublished().before(
					secondVersion.getPublished())) {
				VKCDocument temp = firstVersion;
				firstVersion = secondVersion;
				secondVersion = temp;
			}
		} catch (DBException e) {
			VKCLogManager.errorLog(this, "", e.getMessage(), e);
			errors.add("error",
					new ActionError("error.general", e.getMessage()));
		}

		return errors;
	}

	public Integer getCategoryId() {
		return categoryId;
	}

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

	public Integer getDocumentId() {
		return documentId;
	}

	public void setDocumentId(Integer documentId) {
		this.documentId = documentId;
	}

	public Integer getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(Integer selectedId) {
		this.selectedId = selectedId;
	}

	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 VKCDocument getFirstVersion() {
		return firstVersion;
	}

	public void setFirstVersion(VKCDocument firstVersion) {
		this.firstVersion = firstVersion;
	}

	public VKCDocument getSecondVersion() {
		return secondVersion;
	}

	public void setSecondVersion(VKCDocument secondVersion) {
		this.secondVersion = secondVersion;
	}

	public String[] getSelectedDocuments() {
		return selectedDocuments;
	}

	public void setSelectedDocuments(String[] selectedDocuments) {
		this.selectedDocuments = selectedDocuments;
	}
}