/*
 * $Id: DisplayUserInfoAction.java,v 1.9 2004/11/12 00:20:30 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: DisplayUserInfoAction.java,v $
 * Revision 1.9  2004/11/12 00:20:30  marbobo
 * - Unnötige Import-Anweisungen entfernt
 *
 * Revision 1.8  2004/11/10 15:02:45  koppy
 * Projektweite Überarbeitung von Error-Logs, Stacktraces,..
 *
 * Revision 1.7  2004/11/02 21:42:29  marbobo
 * + Einige Funktionen für Gast-Benutzer gesperrt
 * + WebShare.LOGIN_PAGE mit WebShare.getLoginPage() ersetzt
 *
 * Revision 1.6  2004/03/11 20:17:15  bigmac
 * Anpassungen an VKCUserSerializer
 *
 * Revision 1.5  2003/12/23 11:03:42  bigmac
 * Kompletter Rework
 *
 * Revision 1.4  2003/10/16 07:52:52  lawern
 * Umstellung von VKCUser auf UserInfo + Code aufräumen.
 *
 * Revision 1.3  2003/08/25 12:29:33  marbobo
 * displayUserInfo ind displayGroupInfo umgeschrieben
 *
 * Revision 1.2  2003/08/25 09:41:14  bigmac
 * *** empty log message ***
 *
 * Revision 1.1  2003/08/20 09:53:32  marbobo
 * verschoben
 *
 * Revision 1.8  2003/08/19 09:21:28  marbobo
 * Bugfix
 *
 * Revision 1.7  2003/08/02 16:53:34  bigmac
 * *** empty log message ***
 *
 * Revision 1.6  2003/07/28 10:21:27  marbobo
 * +Kommentierung von Methoden und des Quellcodes
 * -unnötige Imports entfernt
 *
 */
package vkc.view.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCUser;
import vkc.db.serializer.VKCUserSerializer;
import vkc.misc.VKCLogManager;
import vkc.util.DateUtils;
import vkc.view.form.DisplayUserInfoForm;

public final class DisplayUserInfoAction extends Action {
	private ActionForward DEFAULT_FORWARD = new ActionForward( "/templates/${template.name}/common/displayUserInfo.jsp" );

    public ActionForward execute( ActionMapping mapping, 
    							  ActionForm f,
        						  HttpServletRequest request, 
        						  HttpServletResponse response )
    throws Exception {	
		DisplayUserInfoForm form = (DisplayUserInfoForm)f;

		Integer userId = form.getUserId();

		VKCUser user = null;
		
		try {
			user = VKCUserSerializer.retrieveUser( userId );
		} catch (Exception e) {
			VKCLogManager.errorLog(this, "", e.getMessage(), e);
		}

		form.setUser( user );
		
		if ( user != null ) {
			form.setCreator( VKCUserSerializer.retrieveUserInfo( user.getCreatorId() ) );
			
			if ( user.getCreated()!=null ) {
				Date d = new Date( user.getCreated().getTime() );
				form.setCreationDate( DateUtils.getDD_MM_YYYY( d ) + ", " + DateUtils.getHH_MM_SS( d ) );
			}

			form.setLastEditor( VKCUserSerializer.retrieveUserInfo( user.getLastChangerId() ) );
			
			if ( user.getLastChanged()!=null ) {
				Date d = new Date( user.getLastChanged().getTime() );
				form.setLastEditingDate( DateUtils.getDD_MM_YYYY( d ) + ", " + DateUtils.getHH_MM_SS( d ) );
			}
		}

		return DEFAULT_FORWARD;
    }
}
