/*
 * $Id: UserLicenseForm.java,v 1.2 2007/08/08 12:14:47 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: UserLicenseForm.java,v $
 * Revision 1.2  2007/08/08 12:14:47  marbobo
 * + License-Funktionalität komplett umgeschrieben
 * + Bugfix bzgl. Beschreibungsfelder von Entitäten
 * + Bugfix mailing
 *
 */
package vkc.view.form;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCLicense;
import vkc.db.serializer.VKCLicenseSerializer;
import vkc.exception.DBException;
import vkc.view.form.BasicActionForm;

public class UserLicenseForm extends BasicActionForm {
	List licenses = null;	

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);
		licenses = null;	
	}
    
    public List getLicenses() throws DBException {
        if (licenses == null) {
            if (getUser().isGuestUser()) {
                licenses = new ArrayList();
                VKCLicense license = VKCLicenseSerializer.retrieveActiveLicense();
                
                if (license != null) {
                    license.setAccepted(getUser().getMostRecentLogin());
                    licenses.add(license);
                }
            } else {
                licenses = VKCLicenseSerializer.retrieveUserLicense(getUser().getUserId());
            }
        }
        
        return licenses;
    }
}