/*
 * $Id: NewProjectStepInfo.java,v 1.6 2005/02/20 17:00:36 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: NewProjectStepInfo.java,v $
 * Revision 1.6  2005/02/20 17:00:36  marbobo
 * + Beim Speichern der Entities in die Datenbank wird sichergestellt
 *    dass Unicode-Zeichen in Kodierterform (als &#xxxxx;) gespeichert werden
 *
 * Revision 1.5  2004/08/07 18:17:06  marbobo
 * + Bugfix für Zeitangaben und Refactorings
 *
 * Revision 1.4  2004/07/20 08:51:21  jonyp
 * added copyright info + cvs log
 *
 *
 */

package vkc.view.bean;

import java.sql.Timestamp;
import java.util.Calendar;

import vkc.db.entities.VKCCatProjectStep;
import vkc.util.DateUtils;
import vkc.util.StringUtils;
import vkc.util.VKCStringUtils;

public class NewProjectStepInfo {

	private boolean selected  = false;
	private boolean enabled = true;
	private String  activity  = "";
	private String  startDate = "";
	private String  endDate   = "";
	private Integer catProjStepId = new Integer(-1);
	private Integer categoryId = new Integer(-1);
	private Integer step = new Integer(0);
	private Integer processorId;
	private String processedTS = "";
	private String checkedTS = "";
	private Integer checkerId;

	public String getActivity() {
		return activity;
	}

	public void setActivity(String string) {
		activity = StringUtils.normalize( string );
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean b) {
		selected = b;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String string) {
		endDate = StringUtils.normalize( string );
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String string) {
		startDate = StringUtils.normalize( string );
	}


	public Integer getCategoryId() {
		return categoryId;
	}

	public Integer getCatProjStepId() {
		return catProjStepId;
	}

	public String getCheckedTS() {
		return checkedTS;
	}

	public Integer getCheckerId() {
		return checkerId;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public String getProcessedTS() {
		return processedTS;
	}

	public Integer getProcessorId() {
		return processorId;
	}

	public Integer getStep() {
		return step;
	}

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

	public void setCatProjStepId( Integer integer ) {
		catProjStepId = integer;
	}

	public void setCheckedTS( String string ) {
		checkedTS = StringUtils.normalize( string );
	}

	public void setCheckerId( Integer integer ) {
		checkerId = integer;
	}

	public void setEnabled( boolean b ) {
		enabled = b;
	}

	public void setProcessedTS( String string ) {
		processedTS = StringUtils.normalize( string );
	}

	public void setProcessorId( Integer integer ) {
		processorId = integer;
	}

	public void setStep( Integer integer ) {
		step = integer;
	}

	public VKCCatProjectStep toVKCCatProjectStep() {
		VKCCatProjectStep step = new VKCCatProjectStep();
		step.setCatProjStepId( getCatProjStepId() );
		step.setCategoryId( getCategoryId() );
		step.setActivity( VKCStringUtils.filterUnicodeChars( getActivity() ) );
		step.setStep( getStep() );
		
		if ( DateUtils.parseDate( getStartDate() ) != null ) {
			step.setStartDate( new Timestamp( DateUtils.parseDate( getStartDate() ).getTime() ) );
		}
		
		if ( DateUtils.parseDate( getEndDate() ) != null ) {
			Calendar c = Calendar.getInstance();
			c.setTime( DateUtils.parseDate( getEndDate() ) );
			c.set( Calendar.HOUR_OF_DAY, 23 );
			c.set( Calendar.MINUTE, 59 );
			c.set( Calendar.SECOND, 59 );
			step.setEndDate( new Timestamp( c.getTimeInMillis() ) );
		}
		
		step.setEnabled( isEnabled() );
		step.setProcessorId( getProcessorId() );
		
		if ( DateUtils.parseDate( getProcessedTS() ) != null ) {
			step.setProcessedTS( new Timestamp( DateUtils.parseDate( getProcessedTS() ).getTime() ) );
		}
		
		step.setCheckerId( getCheckerId() );
		
		if ( DateUtils.parseDate( getCheckedTS() ) != null ) {
			step.setCheckedTS( new Timestamp( DateUtils.parseDate( getCheckedTS() ).getTime() ) );
		}
		
		return step;
	}
}