/*
 * $Id: ShowDocumentVersionsForm.java,v 1.13 2006/08/30 21:08:15 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ShowDocumentVersionsForm.java,v $
 * Revision 1.13  2006/08/30 21:08:15  marbobo
 * + Rückkehr zur Projekt- und Funktionssicht korrigiert
 *
 * Revision 1.12  2006/01/26 12:45:00  korowa
 * *** empty log message ***
 *
 * Revision 1.11  2006/01/20 12:44:07  korowa
 * Ermöglicht ein Vergleich von verschiedenen Versionen eines Dokumentes
 *
 * Revision 1.10  2005/01/06 13:44:02  marbobo
 * + Rechteüberprüfung (für Gast-Benutzer generell verbieten)
 *
 * Revision 1.9  2005/01/06 13:18:09  marbobo
 * + Rechteüberprüfung
 *
 * Revision 1.8  2004/12/22 00:32:46  marbobo
 * + Dokumentversionen löschen implementiert
 *
 * Revision 1.7  2004/07/20 15:21:46  jonyp
 * added copyright info + cvs log
 *
 *
 */

package vkc.view.form;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCCategory;
import vkc.db.entities.VKCDocument;
import vkc.db.serializer.VKCAclSerializer;
import vkc.db.serializer.VKCCategorySerializer;
import vkc.db.serializer.VKCDocumentSerializer;
import vkc.db.serializer.VKCSysParameterSerializer;
import vkc.exception.DBException;
import vkc.security.PermissionManager;
import vkc.view.PageId;

public final class ShowDocumentVersionsForm extends BasicActionForm {
	private boolean comparable = false;

	private Collection documents = null;

	private Integer categoryId = null;

	private Integer deleteId = null;

	private Integer documentId = null;

	private Integer selectedId = null;

	private Integer sourcePageId = PageId.CATEGORY_VIEW;

	private Integer subTargetId = null;

	private Integer targetId = null;

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

	private Integer[] showDocumentDetails = new Integer[0];

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

		comparable = false;

		documents = null;

		categoryId = null;
		deleteId = null;
		documentId = null;
		selectedId = null;
		sourcePageId = PageId.CATEGORY_VIEW;
		subTargetId = null;
		targetId = null;

		selectedDocuments = new String[0];

		showDocumentDetails = new Integer[0];
	}

	public Collection getDocuments() {
		return documents;
	}

	public void setDocuments(Collection collection) {
		documents = collection;
	}

	public boolean isComparable() {
		try {
			VKCDocument document = VKCDocumentSerializer
					.retrieveDocument(getDocumentId());

			if (document.getAdditionalDocumentFormats() != null
					&& document.getAdditionalDocumentFormats().size() != 0) {
				comparable = true;
			}
		} catch (DBException e) {
			e.printStackTrace();
		}

		return comparable;
	}

	public Integer getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Integer i) {
		categoryId = i;
	}

	public Integer getDeleteId() {
		return deleteId;
	}

	public void setDeleteId(Integer i) {
		deleteId = i;
	}

	public Integer getDocumentId() {
		return documentId;
	}

	public void setDocumentId(Integer i) {
		documentId = i;
	}

	public Integer getSourcePageId() {
		return sourcePageId;
	}

	public void setSourcePageId(Integer i) {
		sourcePageId = i;
	}

	public Integer[] getShowDocumentDetails() {
		return showDocumentDetails;
	}

	public void setShowDocumentDetails(Integer[] list) {
		showDocumentDetails = list;
	}

	public boolean getShowDocDetails(int i) {
		List ids = Arrays.asList(getShowDocumentDetails());

		return ids.contains(new Integer(i));
	}

	public Integer getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(Integer i) {
		selectedId = i;
	}

	public Integer getSubTargetId() {
		return subTargetId;
	}

	public Integer getTargetId() {
		return targetId;
	}

	public void setSubTargetId(Integer i) {
		subTargetId = i;
	}

	public void setTargetId(Integer i) {
		targetId = i;
	}

	public boolean isManageDocumentVersions() throws DBException {
		if (VKCSysParameterSerializer.retrieveIntValue("DOCUMENT",
				"EnableDocumentVersionManagement", 0) != 0
				&& !VKCCategory.FLAG_CLOSED.equals(VKCCategorySerializer
						.retrieveFlag(getCategoryId()))
				&& !getUser().isGuestUser()
				&& PermissionManager.hasPermission(VKCAclSerializer
						.getAclByCategoryId(getCategoryId()), getUser(), 'd')) {
			return true;
		}

		return false;
	}

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

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