// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5007.25751)
// Copyright (C) 1995-2014 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.RefMan.vo;

/**
 * Linked to RefMan.WorkAllocation business object (ID: 1096100033).
 */
public class WorkAllocationVo extends ims.core.vo.WorkAllocationListVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public WorkAllocationVo()
	{
	}
	public WorkAllocationVo(Integer id, int version)
	{
		super(id, version);
	}
	public WorkAllocationVo(ims.RefMan.vo.beans.WorkAllocationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.catsreferral = bean.getCatsReferral() == null ? null : new ims.RefMan.vo.CatsReferralRefVo(new Integer(bean.getCatsReferral().getId()), bean.getCatsReferral().getVersion());
		this.allocatedby = bean.getAllocatedBy() == null ? null : bean.getAllocatedBy().buildVo();
		this.dateallocated = bean.getDateAllocated() == null ? null : bean.getDateAllocated().buildDateTime();
		this.allocatedto = bean.getAllocatedTo() == null ? null : bean.getAllocatedTo().buildVo();
		this.completeddatetime = bean.getCompletedDateTime() == null ? null : bean.getCompletedDateTime().buildDateTime();
		this.completedby = bean.getCompletedBy() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getCompletedBy().getId()), bean.getCompletedBy().getVersion());
		this.unallocatedby = bean.getUnallocatedBy() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getUnallocatedBy().getId()), bean.getUnallocatedBy().getVersion());
		this.unallocateddate = bean.getUnallocatedDate() == null ? null : bean.getUnallocatedDate().buildDateTime();
		this.referralstatus = bean.getReferralStatus() == null ? null : ims.RefMan.vo.lookups.ReferralApptStatus.buildLookup(bean.getReferralStatus());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.RefMan.vo.beans.WorkAllocationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.catsreferral = bean.getCatsReferral() == null ? null : new ims.RefMan.vo.CatsReferralRefVo(new Integer(bean.getCatsReferral().getId()), bean.getCatsReferral().getVersion());
		this.allocatedby = bean.getAllocatedBy() == null ? null : bean.getAllocatedBy().buildVo(map);
		this.dateallocated = bean.getDateAllocated() == null ? null : bean.getDateAllocated().buildDateTime();
		this.allocatedto = bean.getAllocatedTo() == null ? null : bean.getAllocatedTo().buildVo(map);
		this.completeddatetime = bean.getCompletedDateTime() == null ? null : bean.getCompletedDateTime().buildDateTime();
		this.completedby = bean.getCompletedBy() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getCompletedBy().getId()), bean.getCompletedBy().getVersion());
		this.unallocatedby = bean.getUnallocatedBy() == null ? null : new ims.core.resource.people.vo.MemberOfStaffRefVo(new Integer(bean.getUnallocatedBy().getId()), bean.getUnallocatedBy().getVersion());
		this.unallocateddate = bean.getUnallocatedDate() == null ? null : bean.getUnallocatedDate().buildDateTime();
		this.referralstatus = bean.getReferralStatus() == null ? null : ims.RefMan.vo.lookups.ReferralApptStatus.buildLookup(bean.getReferralStatus());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.RefMan.vo.beans.WorkAllocationVoBean bean = null;
		if(map != null)
			bean = (ims.RefMan.vo.beans.WorkAllocationVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.RefMan.vo.beans.WorkAllocationVoBean();
			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("ALLOCATEDBY"))
			return getAllocatedBy();
		if(fieldName.equals("DATEALLOCATED"))
			return getDateAllocated();
		if(fieldName.equals("ALLOCATEDTO"))
			return getAllocatedTo();
		if(fieldName.equals("COMPLETEDDATETIME"))
			return getCompletedDateTime();
		if(fieldName.equals("COMPLETEDBY"))
			return getCompletedBy();
		if(fieldName.equals("UNALLOCATEDBY"))
			return getUnallocatedBy();
		if(fieldName.equals("UNALLOCATEDDATE"))
			return getUnallocatedDate();
		if(fieldName.equals("REFERRALSTATUS"))
			return getReferralStatus();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getAllocatedByIsNotNull()
	{
		return this.allocatedby != null;
	}
	public ims.core.vo.MemberOfStaffLiteVo getAllocatedBy()
	{
		return this.allocatedby;
	}
	public void setAllocatedBy(ims.core.vo.MemberOfStaffLiteVo value)
	{
		this.isValidated = false;
		this.allocatedby = value;
	}
	public boolean getDateAllocatedIsNotNull()
	{
		return this.dateallocated != null;
	}
	public ims.framework.utils.DateTime getDateAllocated()
	{
		return this.dateallocated;
	}
	public void setDateAllocated(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.dateallocated = value;
	}
	public boolean getAllocatedToIsNotNull()
	{
		return this.allocatedto != null;
	}
	public ims.core.vo.MemberOfStaffLiteVo getAllocatedTo()
	{
		return this.allocatedto;
	}
	public void setAllocatedTo(ims.core.vo.MemberOfStaffLiteVo value)
	{
		this.isValidated = false;
		this.allocatedto = value;
	}
	public boolean getCompletedDateTimeIsNotNull()
	{
		return this.completeddatetime != null;
	}
	public ims.framework.utils.DateTime getCompletedDateTime()
	{
		return this.completeddatetime;
	}
	public void setCompletedDateTime(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.completeddatetime = value;
	}
	public boolean getCompletedByIsNotNull()
	{
		return this.completedby != null;
	}
	public ims.core.resource.people.vo.MemberOfStaffRefVo getCompletedBy()
	{
		return this.completedby;
	}
	public void setCompletedBy(ims.core.resource.people.vo.MemberOfStaffRefVo value)
	{
		this.isValidated = false;
		this.completedby = value;
	}
	public boolean getUnallocatedByIsNotNull()
	{
		return this.unallocatedby != null;
	}
	public ims.core.resource.people.vo.MemberOfStaffRefVo getUnallocatedBy()
	{
		return this.unallocatedby;
	}
	public void setUnallocatedBy(ims.core.resource.people.vo.MemberOfStaffRefVo value)
	{
		this.isValidated = false;
		this.unallocatedby = value;
	}
	public boolean getUnallocatedDateIsNotNull()
	{
		return this.unallocateddate != null;
	}
	public ims.framework.utils.DateTime getUnallocatedDate()
	{
		return this.unallocateddate;
	}
	public void setUnallocatedDate(ims.framework.utils.DateTime value)
	{
		this.isValidated = false;
		this.unallocateddate = value;
	}
	public boolean getReferralStatusIsNotNull()
	{
		return this.referralstatus != null;
	}
	public ims.RefMan.vo.lookups.ReferralApptStatus getReferralStatus()
	{
		return this.referralstatus;
	}
	public void setReferralStatus(ims.RefMan.vo.lookups.ReferralApptStatus value)
	{
		this.isValidated = false;
		this.referralstatus = value;
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.allocatedby != null)
		{
			if(!this.allocatedby.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.catsreferral == null)
			listOfErrors.add("CatsReferral is mandatory");
		if(this.allocatedby == null)
			listOfErrors.add("AllocatedBy is mandatory");
		if(this.allocatedby != null)
		{
			String[] listOfOtherErrors = this.allocatedby.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.dateallocated == null)
			listOfErrors.add("DateAllocated is mandatory");
		if(this.allocatedto == null)
			listOfErrors.add("AllocatedTo is mandatory");
		if(this.referralstatus == null)
			listOfErrors.add("ReferralStatus 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;
	
		WorkAllocationVo clone = new WorkAllocationVo(this.id, this.version);
		
		clone.catsreferral = this.catsreferral;
		if(this.allocatedby == null)
			clone.allocatedby = null;
		else
			clone.allocatedby = (ims.core.vo.MemberOfStaffLiteVo)this.allocatedby.clone();
		if(this.dateallocated == null)
			clone.dateallocated = null;
		else
			clone.dateallocated = (ims.framework.utils.DateTime)this.dateallocated.clone();
		if(this.allocatedto == null)
			clone.allocatedto = null;
		else
			clone.allocatedto = (ims.core.vo.MemberOfStaffLiteVo)this.allocatedto.clone();
		if(this.completeddatetime == null)
			clone.completeddatetime = null;
		else
			clone.completeddatetime = (ims.framework.utils.DateTime)this.completeddatetime.clone();
		clone.completedby = this.completedby;
		clone.unallocatedby = this.unallocatedby;
		if(this.unallocateddate == null)
			clone.unallocateddate = null;
		else
			clone.unallocateddate = (ims.framework.utils.DateTime)this.unallocateddate.clone();
		if(this.referralstatus == null)
			clone.referralstatus = null;
		else
			clone.referralstatus = (ims.RefMan.vo.lookups.ReferralApptStatus)this.referralstatus.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 (!(WorkAllocationVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A WorkAllocationVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((WorkAllocationVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((WorkAllocationVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.allocatedby != null)
			count++;
		if(this.dateallocated != null)
			count++;
		if(this.allocatedto != null)
			count++;
		if(this.completeddatetime != null)
			count++;
		if(this.completedby != null)
			count++;
		if(this.unallocatedby != null)
			count++;
		if(this.unallocateddate != null)
			count++;
		if(this.referralstatus != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 8;
	}
	protected ims.core.vo.MemberOfStaffLiteVo allocatedby;
	protected ims.framework.utils.DateTime dateallocated;
	protected ims.core.vo.MemberOfStaffLiteVo allocatedto;
	protected ims.framework.utils.DateTime completeddatetime;
	protected ims.core.resource.people.vo.MemberOfStaffRefVo completedby;
	protected ims.core.resource.people.vo.MemberOfStaffRefVo unallocatedby;
	protected ims.framework.utils.DateTime unallocateddate;
	protected ims.RefMan.vo.lookups.ReferralApptStatus referralstatus;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
