/*
 * $Id: VKCNews.java,v 1.4 2007/03/01 15:02:57 korowa Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: VKCNews.java,v $
 * Revision 1.4  2007/03/01 15:02:57  korowa
 * Beschreibungen zur Kategorien und Dokumenten und News werden jetzt in eigener Tabelle NOTES über VKCNoteSerializer gespeichert und sind nicht begrenzt an Zeichenanzahl
 *
 * Revision 1.3  2004/07/23 10:17:38  jonyp
 * + added new fields  (username, lastname, firstname) in VKCNews
 * + added convenience method isValid
 *
 * Revision 1.2  2004/01/14 09:30:53  jonyp
 * + headline
 *
 * Revision 1.1  2003/12/10 11:56:17  jonyp
 * first strike
 *
 */
package vkc.db.entities;

import java.sql.Timestamp;

/**
 * DOCUMENT ME!!!
 * 
 * @author vchris
 */
public class VKCNews {

	private Integer newsId;
	private String headline;
	private String newsText;
	private String infoUrl;
	private Timestamp validFrom;
	private Timestamp validUntil;
	private Timestamp created;
	private Integer creatorId;
	private String creatorName;
	private String creatorFirstname;
	private String creatorLastname;
	private Integer noteId;
	
	public VKCNews() {}
	
	public Timestamp getCreated() {
		return created;
	}

	public Integer getCreatorId() {
		return creatorId;
	}

	public String getNewsText() {
		return newsText;
	}

	public String getInfoUrl() {
		return infoUrl;
	}

	public Integer getNewsId() {
		return newsId;
	}

	public Timestamp getValidFrom() {
		return validFrom;
	}

	public Timestamp getValidUntil() {
		return validUntil;
	}

	public void setCreated(Timestamp timestamp) {
		created = timestamp;
	}

	public void setCreatorId(Integer integer) {
		creatorId = integer;
	}

	public void setNewsText(String string) {
		newsText = string;
	}

	public void setInfoUrl(String string) {
		infoUrl = string;
	}

	public void setNewsId(Integer integer) {
		newsId = integer;
	}

	public void setValidFrom(Timestamp timestamp) {
		validFrom = timestamp;
	}

	public void setValidUntil(Timestamp timestamp) {
		validUntil = timestamp;
	}

	public String getHeadline() {
		return headline;
	}

	public void setHeadline(String string) {
		headline = string;
	}

	public String getCreatorFirstname() {
		return creatorFirstname;
	}

	public String getCreatorLastname() {
		return creatorLastname;
	}

	public String getCreatorName() {
		return creatorName;
	}

	public void setCreatorFirstname(String string) {
		creatorFirstname = string;
	}

	public void setCreatorLastname(String string) {
		creatorLastname = string;
	}

	public void setCreatorName(String string) {
		creatorName = string;
	}

	public boolean isValid() {

		if (validFrom == null && validUntil == null) {
			// valid everytime
			return true;
		}
		
        // now check for other constallations        
		Timestamp now = new Timestamp( System.currentTimeMillis());
		
		// a time frame given...
		if (validFrom != null && validUntil != null) {
		    if ((now.after(validFrom) == true) && (now.before(validUntil) == true)) {
		        return true;
		    }
		    
		    return false;	
		}
		
		// lower bound given...
		if (validFrom != null && validUntil == null) {
			if (now.after(validFrom) == true) {
				return true;
			}
		    
			return false;	
		}

		// upper bound given...
		if (validFrom == null && validUntil != null) {
			if (now.before(validUntil) == true) {
				return true;
			}
		    
			return false;	
		}
		
		// should never happen
		return false;
	}

	public Integer getNoteId() {
		return noteId;
	}

	public void setNoteId(Integer noteId) {
		this.noteId = noteId;
	}
}
