/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/pci/vo/ScheduleConfigurationLiteVo.java
//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program is distributed in the hope that it will be useful,          #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of           #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
//#  GNU Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5589.25814)
// Copyright (C) 1995-2015 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.pci.vo;

/**
 * Linked to PCI.ScheduleConfiguration business object (ID: 1091100002).
 */
public class ScheduleConfigurationLiteVo extends ims.pci.vo.ScheduleConfigurationRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public ScheduleConfigurationLiteVo()
	{
	}
	public ScheduleConfigurationLiteVo(Integer id, int version)
	{
		super(id, version);
	}
	public ScheduleConfigurationLiteVo(ims.pci.vo.beans.ScheduleConfigurationLiteVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.schedulename = bean.getScheduleName();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.startdob = bean.getStartDob() == null ? null : bean.getStartDob().buildDate();
		this.enddob = bean.getEndDob() == null ? null : bean.getEndDob().buildDate();
		this.isdefaultschedule = bean.getIsDefaultSchedule();
		this.scheduletype = bean.getScheduleType() == null ? null : ims.pci.vo.lookups.ScheduleType.buildLookup(bean.getScheduleType());
		this.campaignstartdate = bean.getCampaignStartDate() == null ? null : bean.getCampaignStartDate().buildDate();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.pci.vo.beans.ScheduleConfigurationLiteVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.schedulename = bean.getScheduleName();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.startdob = bean.getStartDob() == null ? null : bean.getStartDob().buildDate();
		this.enddob = bean.getEndDob() == null ? null : bean.getEndDob().buildDate();
		this.isdefaultschedule = bean.getIsDefaultSchedule();
		this.scheduletype = bean.getScheduleType() == null ? null : ims.pci.vo.lookups.ScheduleType.buildLookup(bean.getScheduleType());
		this.campaignstartdate = bean.getCampaignStartDate() == null ? null : bean.getCampaignStartDate().buildDate();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.pci.vo.beans.ScheduleConfigurationLiteVoBean bean = null;
		if(map != null)
			bean = (ims.pci.vo.beans.ScheduleConfigurationLiteVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.pci.vo.beans.ScheduleConfigurationLiteVoBean();
			map.addValueObjectBean(this, bean);
			bean.populate(map, this);
		}
		return bean;
	}
	public Object getFieldValueByFieldName(String fieldName)
	{
		if(fieldName == null)
			throw new ims.framework.exceptions.CodingRuntimeException("Invalid field name");
		fieldName = fieldName.toUpperCase();
		if(fieldName.equals("SCHEDULENAME"))
			return getScheduleName();
		if(fieldName.equals("STATUS"))
			return getStatus();
		if(fieldName.equals("STARTDOB"))
			return getStartDob();
		if(fieldName.equals("ENDDOB"))
			return getEndDob();
		if(fieldName.equals("ISDEFAULTSCHEDULE"))
			return getIsDefaultSchedule();
		if(fieldName.equals("SCHEDULETYPE"))
			return getScheduleType();
		if(fieldName.equals("CAMPAIGNSTARTDATE"))
			return getCampaignStartDate();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getScheduleNameIsNotNull()
	{
		return this.schedulename != null;
	}
	public String getScheduleName()
	{
		return this.schedulename;
	}
	public static int getScheduleNameMaxLength()
	{
		return 75;
	}
	public void setScheduleName(String value)
	{
		this.isValidated = false;
		this.schedulename = value;
	}
	public boolean getStatusIsNotNull()
	{
		return this.status != null;
	}
	public ims.core.vo.lookups.PreActiveActiveInactiveStatus getStatus()
	{
		return this.status;
	}
	public void setStatus(ims.core.vo.lookups.PreActiveActiveInactiveStatus value)
	{
		this.isValidated = false;
		this.status = value;
	}
	public boolean getStartDobIsNotNull()
	{
		return this.startdob != null;
	}
	public ims.framework.utils.Date getStartDob()
	{
		return this.startdob;
	}
	public void setStartDob(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.startdob = value;
	}
	public boolean getEndDobIsNotNull()
	{
		return this.enddob != null;
	}
	public ims.framework.utils.Date getEndDob()
	{
		return this.enddob;
	}
	public void setEndDob(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.enddob = value;
	}
	public boolean getIsDefaultScheduleIsNotNull()
	{
		return this.isdefaultschedule != null;
	}
	public Boolean getIsDefaultSchedule()
	{
		return this.isdefaultschedule;
	}
	public void setIsDefaultSchedule(Boolean value)
	{
		this.isValidated = false;
		this.isdefaultschedule = value;
	}
	public boolean getScheduleTypeIsNotNull()
	{
		return this.scheduletype != null;
	}
	public ims.pci.vo.lookups.ScheduleType getScheduleType()
	{
		return this.scheduletype;
	}
	public void setScheduleType(ims.pci.vo.lookups.ScheduleType value)
	{
		this.isValidated = false;
		this.scheduletype = value;
	}
	public boolean getCampaignStartDateIsNotNull()
	{
		return this.campaignstartdate != null;
	}
	public ims.framework.utils.Date getCampaignStartDate()
	{
		return this.campaignstartdate;
	}
	public void setCampaignStartDate(ims.framework.utils.Date value)
	{
		this.isValidated = false;
		this.campaignstartdate = value;
	}
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		if(this.schedulename != null)
			sb.append(this.schedulename);
		return sb.toString();
	}
	/**
	* Custom validate method - checks for startDOB < endDOB and if default is set only when the schedule is active
	*/
	public String[] validateCustomRules(String[] existingErrors)
	{
		existingErrors = this.validate(existingErrors);
	
		if(this.isBusy)
			return null;
	
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
	
		if (ims.pci.vo.lookups.ScheduleType.OUTBREAKSCHEDULE.equals(this.scheduletype))
		{
			if (this.campaignstartdate == null)
				listOfErrors.add("Campaign start date is mandatory");
		}
		else if (ims.pci.vo.lookups.ScheduleType.INVALIDVACCINESCHEDULE.equals(this.scheduletype) || ims.pci.vo.lookups.ScheduleType.PCISCHEDULE.equals(this.scheduletype))
		{
			if (this.startdob == null)
				listOfErrors.add("Start DOB is mandatory");
		}
	
		if ((this.startdob != null) && (this.enddob != null && this.startdob.isGreaterThan(this.enddob)))
			listOfErrors.add("StartDob can not be set after EndDob");
	
		if (ims.core.vo.lookups.PreActiveActiveInactiveStatus.PREACTIVE.equals(this.status) && this.isdefaultschedule)
			listOfErrors.add("Schedule can be set as default only if it is active");
	
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
	
		String[] result = new String[errorCount];
	
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
	
		this.isBusy = false;
		this.isValidated = false;
	
		return result;
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		this.isBusy = false;
		return true;
	}
	public String[] validate()
	{
		return validate(null);
	}
	public String[] validate(String[] existingErrors)
	{
		if(this.isBusy)
			return null;
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
		if(this.schedulename == null || this.schedulename.length() == 0)
			listOfErrors.add("ScheduleName is mandatory");
		else if(this.schedulename.length() > 75)
			listOfErrors.add("The length of the field [schedulename] in the value object [ims.pci.vo.ScheduleConfigurationLiteVo] is too big. It should be less or equal to 75");
		if(this.status == null)
			listOfErrors.add("Status is mandatory");
		if(this.isdefaultschedule == null)
			listOfErrors.add("isDefaultSchedule is mandatory");
		if(this.scheduletype == null)
			listOfErrors.add("ScheduleType is mandatory");
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
		String[] result = new String[errorCount];
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
		this.isBusy = false;
		this.isValidated = false;
		return result;
	}
	public void clearIDAndVersion()
	{
		this.id = null;
		this.version = 0;
	}
	public Object clone()
	{
		if(this.isBusy)
			return this;
		this.isBusy = true;
	
		ScheduleConfigurationLiteVo clone = new ScheduleConfigurationLiteVo(this.id, this.version);
		
		clone.schedulename = this.schedulename;
		if(this.status == null)
			clone.status = null;
		else
			clone.status = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)this.status.clone();
		if(this.startdob == null)
			clone.startdob = null;
		else
			clone.startdob = (ims.framework.utils.Date)this.startdob.clone();
		if(this.enddob == null)
			clone.enddob = null;
		else
			clone.enddob = (ims.framework.utils.Date)this.enddob.clone();
		clone.isdefaultschedule = this.isdefaultschedule;
		if(this.scheduletype == null)
			clone.scheduletype = null;
		else
			clone.scheduletype = (ims.pci.vo.lookups.ScheduleType)this.scheduletype.clone();
		if(this.campaignstartdate == null)
			clone.campaignstartdate = null;
		else
			clone.campaignstartdate = (ims.framework.utils.Date)this.campaignstartdate.clone();
		clone.isValidated = this.isValidated;
		
		this.isBusy = false;
		return clone;
	}
	public int compareTo(Object obj)
	{
		return compareTo(obj, true);
	}
	public int compareTo(Object obj, boolean caseInsensitive)
	{
		if (obj == null)
		{
			return -1;
		}
		if(caseInsensitive); // this is to avoid eclipse warning only.
		if (!(ScheduleConfigurationLiteVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A ScheduleConfigurationLiteVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((ScheduleConfigurationLiteVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((ScheduleConfigurationLiteVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.schedulename != null)
			count++;
		if(this.status != null)
			count++;
		if(this.startdob != null)
			count++;
		if(this.enddob != null)
			count++;
		if(this.isdefaultschedule != null)
			count++;
		if(this.scheduletype != null)
			count++;
		if(this.campaignstartdate != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 7;
	}
	protected String schedulename;
	protected ims.core.vo.lookups.PreActiveActiveInactiveStatus status;
	protected ims.framework.utils.Date startdob;
	protected ims.framework.utils.Date enddob;
	protected Boolean isdefaultschedule;
	protected ims.pci.vo.lookups.ScheduleType scheduletype;
	protected ims.framework.utils.Date campaignstartdate;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
